-
Notifications
You must be signed in to change notification settings - Fork 11k
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' of github.com:RocketChat/Rocket.Chat into fix/…
…message-body * 'develop' of github.com:RocketChat/Rocket.Chat: [IMPROVE] Refactor + unit tests for federation-v2 (#25680) [FIX] user status Offline misnamed as Invisible in Custom Status edit dropdown menu (#24796) Chore: Messages raw model rewrite to ts (#25761) Chore: migrate katex to ts (#25501) Chore: AutoTranslate contextualBar rewrite (#25751) Chore: Replace AnnouncementModal in favor of GenericModal (#25752) Chore: Keyboard shortcuts contextualBar rewrite (#25753) Chore: Prune Messages contextualBar rewrite (#25757) Chore: add Ajv JSON Schema to api/v1 (#25601) Update package.json (#25755) Update CODEOWNERS Chore: remove duplicated NotFoundPage.js (#25749)
- Loading branch information
Showing
141 changed files
with
7,281 additions
and
1,874 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,4 +41,5 @@ yarn-error.log* | |
!.yarn/sdks | ||
!.yarn/versions | ||
|
||
.nvmrc | ||
.nvmrc | ||
.idea/ |
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
217 changes: 217 additions & 0 deletions
217
apps/meteor/app/federation-v2/server/application/RoomServiceReceiver.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,217 @@ | ||
import { RoomType } from '@rocket.chat/apps-engine/definition/rooms'; | ||
|
||
import { FederatedRoom } from '../domain/FederatedRoom'; | ||
import { FederatedUser } from '../domain/FederatedUser'; | ||
import { EVENT_ORIGIN, IFederationBridge } from '../domain/IFederationBridge'; | ||
import { RocketChatMessageAdapter } from '../infrastructure/rocket-chat/adapters/Message'; | ||
import { RocketChatRoomAdapter } from '../infrastructure/rocket-chat/adapters/Room'; | ||
import { RocketChatSettingsAdapter } from '../infrastructure/rocket-chat/adapters/Settings'; | ||
import { RocketChatUserAdapter } from '../infrastructure/rocket-chat/adapters/User'; | ||
import { | ||
FederationRoomCreateInputDto, | ||
FederationRoomChangeMembershipDto, | ||
FederationRoomSendInternalMessageDto, | ||
FederationRoomChangeJoinRulesDto, | ||
FederationRoomChangeNameDto, | ||
FederationRoomChangeTopicDto, | ||
} from './input/RoomReceiverDto'; | ||
|
||
export class FederationRoomServiceReceiver { | ||
constructor( | ||
private rocketRoomAdapter: RocketChatRoomAdapter, | ||
private rocketUserAdapter: RocketChatUserAdapter, | ||
private rocketMessageAdapter: RocketChatMessageAdapter, | ||
private rocketSettingsAdapter: RocketChatSettingsAdapter, | ||
private bridge: IFederationBridge, | ||
) {} // eslint-disable-line no-empty-function | ||
|
||
public async createRoom(roomCreateInput: FederationRoomCreateInputDto): Promise<void> { | ||
const { | ||
externalRoomId, | ||
externalInviterId, | ||
normalizedInviterId, | ||
externalRoomName, | ||
normalizedRoomId, | ||
roomType, | ||
wasInternallyProgramaticallyCreated = false, | ||
} = roomCreateInput; | ||
|
||
if ((await this.rocketRoomAdapter.getFederatedRoomByExternalId(externalRoomId)) || wasInternallyProgramaticallyCreated) { | ||
return; | ||
} | ||
|
||
if (!(await this.rocketUserAdapter.getFederatedUserByExternalId(externalInviterId))) { | ||
const externalUserProfileInformation = await this.bridge.getUserProfileInformation(externalInviterId); | ||
const name = externalUserProfileInformation?.displayname || normalizedInviterId; | ||
const federatedCreatorUser = FederatedUser.createInstance(externalInviterId, { | ||
name, | ||
username: normalizedInviterId, | ||
existsOnlyOnProxyServer: false, | ||
}); | ||
|
||
await this.rocketUserAdapter.createFederatedUser(federatedCreatorUser); | ||
} | ||
const creator = await this.rocketUserAdapter.getFederatedUserByExternalId(externalInviterId); | ||
const newFederatedRoom = FederatedRoom.createInstance( | ||
externalRoomId, | ||
normalizedRoomId, | ||
creator as FederatedUser, | ||
roomType || RoomType.CHANNEL, | ||
externalRoomName, | ||
); | ||
await this.rocketRoomAdapter.createFederatedRoom(newFederatedRoom); | ||
} | ||
|
||
public async changeRoomMembership(roomChangeMembershipInput: FederationRoomChangeMembershipDto): Promise<void> { | ||
const { | ||
externalRoomId, | ||
normalizedInviteeId, | ||
normalizedRoomId, | ||
normalizedInviterId, | ||
externalRoomName, | ||
externalInviteeId, | ||
externalInviterId, | ||
inviteeUsernameOnly, | ||
inviterUsernameOnly, | ||
eventOrigin, | ||
roomType, | ||
leave, | ||
} = roomChangeMembershipInput; | ||
const affectedFederatedRoom = await this.rocketRoomAdapter.getFederatedRoomByExternalId(externalRoomId); | ||
if (!affectedFederatedRoom && eventOrigin === EVENT_ORIGIN.LOCAL) { | ||
throw new Error(`Could not find room with external room id: ${externalRoomId}`); | ||
} | ||
const isInviterFromTheSameHomeServer = await this.bridge.isUserIdFromTheSameHomeserver( | ||
externalInviterId, | ||
this.rocketSettingsAdapter.getHomeServerDomain(), | ||
); | ||
const isInviteeFromTheSameHomeServer = await this.bridge.isUserIdFromTheSameHomeserver( | ||
externalInviteeId, | ||
this.rocketSettingsAdapter.getHomeServerDomain(), | ||
); | ||
|
||
if (!(await this.rocketUserAdapter.getFederatedUserByExternalId(externalInviterId))) { | ||
const externalUserProfileInformation = await this.bridge.getUserProfileInformation(externalInviterId); | ||
const name = externalUserProfileInformation.displayname || normalizedInviterId; | ||
const username = isInviterFromTheSameHomeServer ? inviterUsernameOnly : normalizedInviterId; | ||
const federatedInviterUser = FederatedUser.createInstance(externalInviterId, { | ||
name, | ||
username, | ||
existsOnlyOnProxyServer: isInviterFromTheSameHomeServer, | ||
}); | ||
|
||
await this.rocketUserAdapter.createFederatedUser(federatedInviterUser); | ||
} | ||
|
||
if (!(await this.rocketUserAdapter.getFederatedUserByExternalId(externalInviteeId))) { | ||
const externalUserProfileInformation = await this.bridge.getUserProfileInformation(externalInviteeId); | ||
const name = externalUserProfileInformation.displayname || normalizedInviteeId; | ||
const username = isInviteeFromTheSameHomeServer ? inviteeUsernameOnly : normalizedInviteeId; | ||
const federatedInviteeUser = FederatedUser.createInstance(externalInviteeId, { | ||
name, | ||
username, | ||
existsOnlyOnProxyServer: isInviteeFromTheSameHomeServer, | ||
}); | ||
|
||
await this.rocketUserAdapter.createFederatedUser(federatedInviteeUser); | ||
} | ||
|
||
const federatedInviteeUser = await this.rocketUserAdapter.getFederatedUserByExternalId(externalInviteeId); | ||
const federatedInviterUser = await this.rocketUserAdapter.getFederatedUserByExternalId(externalInviterId); | ||
|
||
if (!affectedFederatedRoom && eventOrigin === EVENT_ORIGIN.REMOTE) { | ||
const members = [federatedInviterUser, federatedInviteeUser] as any[]; | ||
const newFederatedRoom = FederatedRoom.createInstance( | ||
externalRoomId, | ||
normalizedRoomId, | ||
federatedInviterUser as FederatedUser, | ||
roomType, | ||
externalRoomName, | ||
members, | ||
); | ||
|
||
await this.rocketRoomAdapter.createFederatedRoom(newFederatedRoom); | ||
await this.bridge.joinRoom(externalRoomId, externalInviteeId); | ||
} | ||
const federatedRoom = affectedFederatedRoom || (await this.rocketRoomAdapter.getFederatedRoomByExternalId(externalRoomId)); | ||
|
||
if (leave) { | ||
return this.rocketRoomAdapter.removeUserFromRoom( | ||
federatedRoom as FederatedRoom, | ||
federatedInviteeUser as FederatedUser, | ||
federatedInviterUser as FederatedUser, | ||
); | ||
} | ||
await this.rocketRoomAdapter.addUserToRoom( | ||
federatedRoom as FederatedRoom, | ||
federatedInviteeUser as FederatedUser, | ||
federatedInviterUser as FederatedUser, | ||
); | ||
} | ||
|
||
public async receiveExternalMessage(roomSendInternalMessageInput: FederationRoomSendInternalMessageDto): Promise<void> { | ||
const { externalRoomId, externalSenderId, text } = roomSendInternalMessageInput; | ||
|
||
const federatedRoom = await this.rocketRoomAdapter.getFederatedRoomByExternalId(externalRoomId); | ||
if (!federatedRoom) { | ||
return; | ||
} | ||
|
||
const senderUser = await this.rocketUserAdapter.getFederatedUserByExternalId(externalSenderId); | ||
if (!senderUser) { | ||
return; | ||
} | ||
|
||
await this.rocketMessageAdapter.sendMessage(senderUser, text, federatedRoom); | ||
} | ||
|
||
public async changeJoinRules(roomJoinRulesChangeInput: FederationRoomChangeJoinRulesDto): Promise<void> { | ||
const { externalRoomId, roomType } = roomJoinRulesChangeInput; | ||
|
||
const federatedRoom = await this.rocketRoomAdapter.getFederatedRoomByExternalId(externalRoomId); | ||
if (!federatedRoom) { | ||
return; | ||
} | ||
|
||
if (federatedRoom.isDirectMessage()) { | ||
return; | ||
} | ||
|
||
federatedRoom.setRoomType(roomType); | ||
await this.rocketRoomAdapter.updateRoomType(federatedRoom); | ||
} | ||
|
||
public async changeRoomName(roomChangeNameInput: FederationRoomChangeNameDto): Promise<void> { | ||
const { externalRoomId, normalizedRoomName } = roomChangeNameInput; | ||
|
||
const federatedRoom = await this.rocketRoomAdapter.getFederatedRoomByExternalId(externalRoomId); | ||
if (!federatedRoom) { | ||
return; | ||
} | ||
|
||
if (federatedRoom.isDirectMessage()) { | ||
return; | ||
} | ||
|
||
federatedRoom.changeRoomName(normalizedRoomName); | ||
|
||
await this.rocketRoomAdapter.updateRoomName(federatedRoom); | ||
} | ||
|
||
public async changeRoomTopic(roomChangeTopicInput: FederationRoomChangeTopicDto): Promise<void> { | ||
const { externalRoomId, roomTopic } = roomChangeTopicInput; | ||
|
||
const federatedRoom = await this.rocketRoomAdapter.getFederatedRoomByExternalId(externalRoomId); | ||
if (!federatedRoom) { | ||
return; | ||
} | ||
|
||
if (federatedRoom.isDirectMessage()) { | ||
return; | ||
} | ||
|
||
federatedRoom.changeRoomTopic(roomTopic); | ||
|
||
await this.rocketRoomAdapter.updateRoomTopic(federatedRoom); | ||
} | ||
} |
Oops, something went wrong.