-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NEW] Federation events coverage expansion (#27119)
- Loading branch information
1 parent
2c829b1
commit fb32bdf
Showing
47 changed files
with
1,401 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,4 +85,5 @@ coverage | |
tests/e2e/test-failures/ | ||
out.txt | ||
dist | ||
*-session.json | ||
*-session.json | ||
matrix-federation-config/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
apps/meteor/app/federation-v2/server/application/UserServiceListener.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import type { IFederationBridge } from '../domain/IFederationBridge'; | ||
import type { RocketChatFileAdapter } from '../infrastructure/rocket-chat/adapters/File'; | ||
import type { RocketChatNotificationAdapter } from '../infrastructure/rocket-chat/adapters/Notification'; | ||
import type { RocketChatRoomAdapter } from '../infrastructure/rocket-chat/adapters/Room'; | ||
import type { RocketChatSettingsAdapter } from '../infrastructure/rocket-chat/adapters/Settings'; | ||
import type { RocketChatUserAdapter } from '../infrastructure/rocket-chat/adapters/User'; | ||
import { FederationService } from './AbstractFederationService'; | ||
import type { FederationUserTypingStatusEventDto } from './input/UserReceiverDto'; | ||
|
||
export class FederationUserServiceListener extends FederationService { | ||
private usersTypingByRoomIdCache: Map<string, Record<string, string>[]> = new Map(); | ||
|
||
constructor( | ||
protected internalRoomAdapter: RocketChatRoomAdapter, | ||
protected internalUserAdapter: RocketChatUserAdapter, | ||
protected internalFileAdapter: RocketChatFileAdapter, | ||
protected internalNotificationAdapter: RocketChatNotificationAdapter, | ||
protected internalSettingsAdapter: RocketChatSettingsAdapter, | ||
protected bridge: IFederationBridge, | ||
) { | ||
super(bridge, internalUserAdapter, internalFileAdapter, internalSettingsAdapter); | ||
} | ||
|
||
private handleUsersWhoStoppedTyping(externalRoomId: string, internalRoomId: string, externalUserIdsTyping: string[]): void { | ||
const isTyping = false; | ||
const notTypingAnymore = this.usersTypingByRoomIdCache | ||
.get(externalRoomId) | ||
?.filter((user) => !externalUserIdsTyping.includes(user.externalUserId)); | ||
|
||
const stillTyping = this.usersTypingByRoomIdCache | ||
.get(externalRoomId) | ||
?.filter((user) => externalUserIdsTyping.includes(user.externalUserId)); | ||
|
||
notTypingAnymore?.forEach((user) => this.internalNotificationAdapter.notifyUserTypingOnRoom(internalRoomId, user.username, isTyping)); | ||
this.usersTypingByRoomIdCache.set(externalRoomId, stillTyping || []); | ||
} | ||
|
||
public async onUserTyping(userTypingInput: FederationUserTypingStatusEventDto): Promise<void> { | ||
const { externalUserIdsTyping, externalRoomId } = userTypingInput; | ||
const federatedRoom = await this.internalRoomAdapter.getFederatedRoomByExternalId(externalRoomId); | ||
if (!federatedRoom) { | ||
return; | ||
} | ||
if (this.usersTypingByRoomIdCache.has(externalRoomId)) { | ||
this.handleUsersWhoStoppedTyping(externalRoomId, federatedRoom.getInternalId(), externalUserIdsTyping); | ||
} | ||
|
||
if (externalUserIdsTyping.length === 0) { | ||
return; | ||
} | ||
|
||
const federatedUsers = await this.internalUserAdapter.getFederatedUsersByExternalIds(externalUserIdsTyping); | ||
if (federatedUsers.length === 0) { | ||
return; | ||
} | ||
|
||
const isTyping = true; | ||
|
||
this.usersTypingByRoomIdCache.set( | ||
externalRoomId, | ||
federatedUsers.map((federatedUser) => { | ||
this.internalNotificationAdapter.notifyUserTypingOnRoom( | ||
federatedRoom.getInternalId(), | ||
federatedUser.getUsername() as string, | ||
isTyping, | ||
); | ||
|
||
return { | ||
externalUserId: federatedUser.getInternalId(), | ||
username: federatedUser.getUsername() as string, | ||
}; | ||
}), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
apps/meteor/app/federation-v2/server/application/input/UserReceiverDto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { IFederationReceiverBaseRoomInputDto } from './RoomReceiverDto'; | ||
import { FederationBaseRoomInputDto } from './RoomReceiverDto'; | ||
|
||
interface IFederationUserTypingStatusInputDto extends IFederationReceiverBaseRoomInputDto { | ||
externalUserIdsTyping: string[]; | ||
} | ||
|
||
export class FederationUserTypingStatusEventDto extends FederationBaseRoomInputDto { | ||
constructor({ externalRoomId, normalizedRoomId, externalUserIdsTyping }: IFederationUserTypingStatusInputDto) { | ||
super({ externalRoomId, normalizedRoomId, externalEventId: '' }); | ||
this.externalRoomId = externalRoomId; | ||
this.normalizedRoomId = normalizedRoomId; | ||
this.externalUserIdsTyping = externalUserIdsTyping; | ||
} | ||
|
||
externalUserIdsTyping: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.