-
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.
Merge branch 'develop' into add-setting-translation
- Loading branch information
Showing
312 changed files
with
6,702 additions
and
3,657 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
57 changes: 57 additions & 0 deletions
57
apps/meteor/app/federation-v2/server/application/MessageServiceListener.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,57 @@ | ||
import { isMessageFromMatrixFederation } from '@rocket.chat/core-typings'; | ||
|
||
import type { IFederationBridge } from '../domain/IFederationBridge'; | ||
import type { RocketChatMessageAdapter } from '../infrastructure/rocket-chat/adapters/Message'; | ||
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 { FederationMessageReactionEventDto } from './input/MessageReceiverDto'; | ||
|
||
export class FederationMessageServiceListener extends FederationService { | ||
constructor( | ||
protected internalRoomAdapter: RocketChatRoomAdapter, | ||
protected internalUserAdapter: RocketChatUserAdapter, | ||
protected internalMessageAdapter: RocketChatMessageAdapter, | ||
protected internalSettingsAdapter: RocketChatSettingsAdapter, | ||
protected bridge: IFederationBridge, | ||
) { | ||
super(bridge, internalUserAdapter, internalSettingsAdapter); | ||
} | ||
|
||
public async onMessageReaction(messageReactionEventInput: FederationMessageReactionEventDto): Promise<void> { | ||
const { | ||
externalRoomId, | ||
emoji, | ||
externalSenderId, | ||
externalEventId: externalReactionEventId, | ||
externalReactedEventId: externalMessageId, | ||
} = messageReactionEventInput; | ||
|
||
const federatedRoom = await this.internalRoomAdapter.getFederatedRoomByExternalId(externalRoomId); | ||
if (!federatedRoom) { | ||
return; | ||
} | ||
|
||
const federatedUser = await this.internalUserAdapter.getFederatedUserByExternalId(externalSenderId); | ||
if (!federatedUser) { | ||
return; | ||
} | ||
const message = await this.internalMessageAdapter.getMessageByFederationId(externalMessageId); | ||
if (!message) { | ||
return; | ||
} | ||
if (!isMessageFromMatrixFederation(message)) { | ||
return; | ||
} | ||
// TODO: move this to a Message entity in the domain layer | ||
const userAlreadyReacted = Boolean( | ||
federatedUser.getUsername() && message.reactions?.[emoji]?.usernames?.includes(federatedUser.getUsername() as string), | ||
); | ||
if (userAlreadyReacted) { | ||
return; | ||
} | ||
|
||
await this.internalMessageAdapter.reactToMessage(federatedUser, message, emoji, externalReactionEventId); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
apps/meteor/app/federation-v2/server/application/RoomRedactionHandlers.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,61 @@ | ||
import type { IMessage } from '@rocket.chat/core-typings'; | ||
|
||
import type { FederatedUser } from '../domain/FederatedUser'; | ||
import { Federation } from '../Federation'; | ||
import type { RocketChatMessageAdapter } from '../infrastructure/rocket-chat/adapters/Message'; | ||
|
||
export interface IRoomRedactionHandlers { | ||
handle(): Promise<void>; | ||
} | ||
|
||
class DeleteMessageHandler implements IRoomRedactionHandlers { | ||
constructor( | ||
private readonly internalMessageAdapter: RocketChatMessageAdapter, | ||
private readonly message: IMessage, | ||
private readonly federatedUser: FederatedUser, | ||
) {} | ||
|
||
public async handle(): Promise<void> { | ||
await this.internalMessageAdapter.deleteMessage(this.message, this.federatedUser); | ||
} | ||
} | ||
|
||
class UnreactToMessageHandler implements IRoomRedactionHandlers { | ||
constructor( | ||
private readonly internalMessageAdapter: RocketChatMessageAdapter, | ||
private readonly message: IMessage, | ||
private readonly federatedUser: FederatedUser, | ||
private readonly redactsEvents: string, | ||
) {} | ||
|
||
public async handle(): Promise<void> { | ||
const normalizedEventId = Federation.escapeExternalFederationEventId(this.redactsEvents); | ||
const reaction = Object.keys(this.message.reactions || {}).find( | ||
(key) => | ||
this.message.reactions?.[key]?.federationReactionEventIds?.[normalizedEventId] === this.federatedUser.getUsername() && | ||
this.message.reactions?.[key]?.usernames?.includes(this.federatedUser.getUsername() || ''), | ||
); | ||
if (!reaction) { | ||
return; | ||
} | ||
await this.internalMessageAdapter.unreactToMessage(this.federatedUser, this.message, reaction, this.redactsEvents); | ||
} | ||
} | ||
|
||
export const getRedactMessageHandler = async ( | ||
internalMessageAdapter: RocketChatMessageAdapter, | ||
redactsEvent: string, | ||
federatedUser: FederatedUser, | ||
): Promise<IRoomRedactionHandlers | undefined> => { | ||
const message = await internalMessageAdapter.getMessageByFederationId(redactsEvent); | ||
const messageWithReaction = await internalMessageAdapter.findOneByFederationIdOnReactions(redactsEvent, federatedUser); | ||
if (!message && !messageWithReaction) { | ||
return; | ||
} | ||
if (messageWithReaction) { | ||
return new UnreactToMessageHandler(internalMessageAdapter, messageWithReaction, federatedUser, redactsEvent); | ||
} | ||
if (message) { | ||
return new DeleteMessageHandler(internalMessageAdapter, message, federatedUser); | ||
} | ||
}; |
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
31 changes: 31 additions & 0 deletions
31
apps/meteor/app/federation-v2/server/application/input/MessageReceiverDto.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,31 @@ | ||
import type { IFederationReceiverBaseRoomInputDto } from './RoomReceiverDto'; | ||
import { FederationBaseRoomInputDto } from './RoomReceiverDto'; | ||
|
||
interface IFederationRoomMessageReactionInputDto extends IFederationReceiverBaseRoomInputDto { | ||
externalSenderId: string; | ||
externalEventId: string; | ||
externalReactedEventId: string; | ||
emoji: string; | ||
} | ||
|
||
export class FederationMessageReactionEventDto extends FederationBaseRoomInputDto { | ||
constructor({ | ||
externalRoomId, | ||
normalizedRoomId, | ||
externalEventId, | ||
externalReactedEventId, | ||
emoji, | ||
externalSenderId, | ||
}: IFederationRoomMessageReactionInputDto) { | ||
super({ externalRoomId, normalizedRoomId, externalEventId }); | ||
this.emoji = emoji; | ||
this.externalSenderId = externalSenderId; | ||
this.externalReactedEventId = externalReactedEventId; | ||
} | ||
|
||
emoji: string; | ||
|
||
externalSenderId: string; | ||
|
||
externalReactedEventId: string; | ||
} |
Oops, something went wrong.