diff --git a/apps/meteor/app/channel-settings/server/functions/saveRoomType.js b/apps/meteor/app/channel-settings/server/functions/saveRoomType.js index d853abb8c93e..6c1fd4b22d62 100644 --- a/apps/meteor/app/channel-settings/server/functions/saveRoomType.js +++ b/apps/meteor/app/channel-settings/server/functions/saveRoomType.js @@ -7,7 +7,7 @@ import { settings } from '../../../settings/server'; import { roomCoordinator } from '../../../../server/lib/rooms/roomCoordinator'; import { RoomSettingsEnum } from '../../../../definition/IRoomTypeConfig'; -export const saveRoomType = function (rid, roomType, user, sendMessage = true) { +export const saveRoomType = async function (rid, roomType, user, sendMessage = true) { if (!Match.test(rid, String)) { throw new Meteor.Error('invalid-room', 'Invalid room', { function: 'RocketChat.saveRoomType', @@ -27,7 +27,7 @@ export const saveRoomType = function (rid, roomType, user, sendMessage = true) { }); } - if (!roomCoordinator.getRoomDirectives(room.t).allowRoomSettingChange(room, RoomSettingsEnum.TYPE)) { + if (!(await roomCoordinator.getRoomDirectives(room.t)?.allowRoomSettingChange(room, RoomSettingsEnum.TYPE))) { throw new Meteor.Error('error-direct-room', "Can't change type of direct rooms", { function: 'RocketChat.saveRoomType', }); diff --git a/apps/meteor/app/channel-settings/server/methods/saveRoomSettings.ts b/apps/meteor/app/channel-settings/server/methods/saveRoomSettings.ts index 467ead137069..99af371b6838 100644 --- a/apps/meteor/app/channel-settings/server/methods/saveRoomSettings.ts +++ b/apps/meteor/app/channel-settings/server/methods/saveRoomSettings.ts @@ -100,7 +100,7 @@ const validators: RoomSettingsValidators = { }, async encrypted({ userId, value, room, rid }) { if (value !== room.encrypted) { - if (!roomCoordinator.getRoomDirectives(room.t).allowRoomSettingChange(room, RoomSettingsEnum.E2E)) { + if (!(await roomCoordinator.getRoomDirectives(room.t)?.allowRoomSettingChange(room, RoomSettingsEnum.E2E))) { throw new Meteor.Error('error-action-not-allowed', 'Only groups or direct channels can enable encryption', { method: 'saveRoomSettings', action: 'Change_Room_Encrypted', @@ -253,12 +253,12 @@ const settingSavers: RoomSettingsSavers = { saveRoomDescription(rid, value, user); } }, - roomType({ value, room, rid, user }) { + async roomType({ value, room, rid, user }) { if (value === room.t) { return; } - if (!saveRoomType(rid, value, user)) { + if (!(await saveRoomType(rid, value, user))) { return; } diff --git a/apps/meteor/ee/server/local-services/federation/application/AbstractFederationService.ts b/apps/meteor/ee/server/local-services/federation/application/AbstractFederationApplicationServiceEE.ts similarity index 96% rename from apps/meteor/ee/server/local-services/federation/application/AbstractFederationService.ts rename to apps/meteor/ee/server/local-services/federation/application/AbstractFederationApplicationServiceEE.ts index bedca44da285..e0e40a316166 100644 --- a/apps/meteor/ee/server/local-services/federation/application/AbstractFederationService.ts +++ b/apps/meteor/ee/server/local-services/federation/application/AbstractFederationApplicationServiceEE.ts @@ -1,4 +1,4 @@ -import { AbstractFederationApplicationService } from '../../../../../server/services/federation/application/AbstractFederationService'; +import { AbstractFederationApplicationService } from '../../../../../server/services/federation/application/AbstractFederationApplicationService'; import type { RocketChatFileAdapter } from '../../../../../server/services/federation/infrastructure/rocket-chat/adapters/File'; import type { RocketChatSettingsAdapter } from '../../../../../server/services/federation/infrastructure/rocket-chat/adapters/Settings'; import { FederatedUserEE } from '../domain/FederatedUser'; diff --git a/apps/meteor/ee/server/local-services/federation/application/UserService.ts b/apps/meteor/ee/server/local-services/federation/application/UserService.ts index 9c337ec0ef8a..6df02f838266 100644 --- a/apps/meteor/ee/server/local-services/federation/application/UserService.ts +++ b/apps/meteor/ee/server/local-services/federation/application/UserService.ts @@ -1,6 +1,6 @@ import type { IFederationBridgeEE } from '../domain/IFederationBridge'; import type { RocketChatUserAdapterEE } from '../infrastructure/rocket-chat/adapters/User'; -import { AbstractFederationApplicationServiceEE } from './AbstractFederationService'; +import { AbstractFederationApplicationServiceEE } from './AbstractFederationApplicationServiceEE'; import type { RocketChatSettingsAdapter } from '../../../../../server/services/federation/infrastructure/rocket-chat/adapters/Settings'; import type { RocketChatFileAdapter } from '../../../../../server/services/federation/infrastructure/rocket-chat/adapters/File'; diff --git a/apps/meteor/ee/server/local-services/federation/application/room/sender/DirectMessageRoomServiceSender.ts b/apps/meteor/ee/server/local-services/federation/application/room/sender/DirectMessageRoomServiceSender.ts index 45be09f35dc0..532e314897ea 100644 --- a/apps/meteor/ee/server/local-services/federation/application/room/sender/DirectMessageRoomServiceSender.ts +++ b/apps/meteor/ee/server/local-services/federation/application/room/sender/DirectMessageRoomServiceSender.ts @@ -8,7 +8,7 @@ import type { FederationOnDirectMessageRoomCreationDto, FederationRoomInviteUserDto, } from './input/RoomSenderDto'; -import { AbstractFederationApplicationServiceEE } from '../../AbstractFederationService'; +import { AbstractFederationApplicationServiceEE } from '../../AbstractFederationApplicationServiceEE'; import type { RocketChatFileAdapter } from '../../../../../../../server/services/federation/infrastructure/rocket-chat/adapters/File'; import type { RocketChatSettingsAdapter } from '../../../../../../../server/services/federation/infrastructure/rocket-chat/adapters/Settings'; diff --git a/apps/meteor/ee/server/local-services/federation/application/room/sender/RoomServiceSender.ts b/apps/meteor/ee/server/local-services/federation/application/room/sender/RoomServiceSender.ts index 12559e6e744a..c6ad28b6d1a5 100644 --- a/apps/meteor/ee/server/local-services/federation/application/room/sender/RoomServiceSender.ts +++ b/apps/meteor/ee/server/local-services/federation/application/room/sender/RoomServiceSender.ts @@ -13,7 +13,7 @@ import type { FederationSetupRoomDto, IFederationInviteeDto, } from './input/RoomSenderDto'; -import { AbstractFederationApplicationServiceEE } from '../../AbstractFederationService'; +import { AbstractFederationApplicationServiceEE } from '../../AbstractFederationApplicationServiceEE'; import type { RocketChatFileAdapter } from '../../../../../../../server/services/federation/infrastructure/rocket-chat/adapters/File'; import type { RocketChatSettingsAdapter } from '../../../../../../../server/services/federation/infrastructure/rocket-chat/adapters/Settings'; import type { RocketChatMessageAdapter } from '../../../../../../../server/services/federation/infrastructure/rocket-chat/adapters/Message'; diff --git a/apps/meteor/ee/server/local-services/federation/service.ts b/apps/meteor/ee/server/local-services/federation/service.ts index 6c55702fcbad..b9012dd9a483 100644 --- a/apps/meteor/ee/server/local-services/federation/service.ts +++ b/apps/meteor/ee/server/local-services/federation/service.ts @@ -186,4 +186,10 @@ export class FederationServiceEE extends AbstractBaseFederationServiceEE impleme FederationRoomSenderConverterEE.toJoinExternalPublicRoomDto(internalUserId, externalRoomId), ); } + + static async createFederationService(): Promise { + const federationService = new FederationServiceEE(); + await federationService.initialize(); + return federationService; + } } diff --git a/apps/meteor/ee/server/startup/services.ts b/apps/meteor/ee/server/startup/services.ts index 89cc978e51d1..aa852a01d7f2 100644 --- a/apps/meteor/ee/server/startup/services.ts +++ b/apps/meteor/ee/server/startup/services.ts @@ -22,12 +22,15 @@ if (!isRunningMs()) { } let federationService: FederationService; -if (!isEnterprise()) { - federationService = new FederationService(); - api.registerService(federationService); -} -onLicense('federation', () => { +void (async () => { + if (!isEnterprise()) { + federationService = await FederationService.createFederationService(); + api.registerService(federationService); + } +})(); + +onLicense('federation', async () => { const federationServiceEE = new FederationServiceEE(); if (federationService) { api.destroyService(federationService); diff --git a/apps/meteor/server/lib/rooms/roomCoordinator.ts b/apps/meteor/server/lib/rooms/roomCoordinator.ts index a4f6fcadf604..8dba2fca2065 100644 --- a/apps/meteor/server/lib/rooms/roomCoordinator.ts +++ b/apps/meteor/server/lib/rooms/roomCoordinator.ts @@ -8,7 +8,7 @@ import { settings } from '../../../app/settings/server'; class RoomCoordinatorServer extends RoomCoordinator { add(roomConfig: IRoomTypeConfig, directives: Partial): void { this.addRoomType(roomConfig, { - allowRoomSettingChange(_room: IRoom, _setting: ValueOf): boolean { + allowRoomSettingChange(_room: IRoom, _setting: ValueOf) { return true; }, allowMemberAction(_room: IRoom, _action: ValueOf, _userId?: IUser['_id']): boolean { diff --git a/apps/meteor/server/lib/rooms/roomTypes/direct.ts b/apps/meteor/server/lib/rooms/roomTypes/direct.ts index 698f44580949..ce88c5012e91 100644 --- a/apps/meteor/server/lib/rooms/roomTypes/direct.ts +++ b/apps/meteor/server/lib/rooms/roomTypes/direct.ts @@ -44,7 +44,7 @@ roomCoordinator.add(DirectMessageRoomType, { allowMemberAction(room: IRoom, action, userId) { if (isRoomFederated(room)) { - return Federation.actionAllowed(room, action, userId); + return Promise.await(Federation.actionAllowed(room, action, userId)); } switch (action) { case RoomMemberActions.BLOCK: diff --git a/apps/meteor/server/lib/rooms/roomTypes/private.ts b/apps/meteor/server/lib/rooms/roomTypes/private.ts index 0a50f4b65940..050bae1a96da 100644 --- a/apps/meteor/server/lib/rooms/roomTypes/private.ts +++ b/apps/meteor/server/lib/rooms/roomTypes/private.ts @@ -33,7 +33,7 @@ roomCoordinator.add(PrivateRoomType, { allowMemberAction(_room, action, userId) { if (isRoomFederated(_room as IRoom)) { - return Federation.actionAllowed(_room, action, userId); + return Promise.await(Federation.actionAllowed(_room, action, userId)); } switch (action) { case RoomMemberActions.BLOCK: diff --git a/apps/meteor/server/lib/rooms/roomTypes/public.ts b/apps/meteor/server/lib/rooms/roomTypes/public.ts index 5f73674d9736..2d143adae54c 100644 --- a/apps/meteor/server/lib/rooms/roomTypes/public.ts +++ b/apps/meteor/server/lib/rooms/roomTypes/public.ts @@ -31,9 +31,9 @@ roomCoordinator.add(PublicRoomType, { } }, - allowMemberAction(_room, action, userId) { + allowMemberAction(_room, action, userId): boolean { if (isRoomFederated(_room as IRoom)) { - return Federation.actionAllowed(_room, action, userId); + return Promise.await(Federation.actionAllowed(_room, action, userId)); } switch (action) { case RoomMemberActions.BLOCK: diff --git a/apps/meteor/server/services/federation/Federation.ts b/apps/meteor/server/services/federation/Federation.ts index ada638e5745b..6f90bbc0f507 100644 --- a/apps/meteor/server/services/federation/Federation.ts +++ b/apps/meteor/server/services/federation/Federation.ts @@ -22,7 +22,7 @@ const allowedActionsForModerators = allowedActionsInFederatedRooms.filter((actio const allowedRoomSettingsChangesInFederatedRooms: ValueOf[] = [RoomSettingsEnum.NAME, RoomSettingsEnum.TOPIC]; export class Federation { - public static actionAllowed(room: IRoom, action: ValueOf, userId?: IUser['_id']): boolean { + public static async actionAllowed(room: IRoom, action: ValueOf, userId?: IUser['_id']): Promise { if (!isRoomFederated(room)) { return false; } @@ -33,7 +33,7 @@ export class Federation { return true; } - const userSubscription = Promise.await(Subscriptions.findOneByRoomIdAndUserId(room._id, userId)); + const userSubscription = await Subscriptions.findOneByRoomIdAndUserId(room._id, userId); if (!userSubscription) { return true; } diff --git a/apps/meteor/server/services/federation/application/AbstractFederationService.ts b/apps/meteor/server/services/federation/application/AbstractFederationApplicationService.ts similarity index 100% rename from apps/meteor/server/services/federation/application/AbstractFederationService.ts rename to apps/meteor/server/services/federation/application/AbstractFederationApplicationService.ts diff --git a/apps/meteor/server/services/federation/application/room/message/receiver/MessageServiceReceiver.ts b/apps/meteor/server/services/federation/application/room/message/receiver/MessageServiceReceiver.ts index c9f18105f482..f273e22ed7b7 100644 --- a/apps/meteor/server/services/federation/application/room/message/receiver/MessageServiceReceiver.ts +++ b/apps/meteor/server/services/federation/application/room/message/receiver/MessageServiceReceiver.ts @@ -6,7 +6,7 @@ import type { RocketChatMessageAdapter } from '../../../../infrastructure/rocket 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 { AbstractFederationApplicationService } from '../../../AbstractFederationService'; +import { AbstractFederationApplicationService } from '../../../AbstractFederationApplicationService'; import type { FederationMessageReactionEventDto } from '../../input/MessageReceiverDto'; export class FederationMessageServiceReceiver extends AbstractFederationApplicationService { diff --git a/apps/meteor/server/services/federation/application/room/receiver/RoomServiceReceiver.ts b/apps/meteor/server/services/federation/application/room/receiver/RoomServiceReceiver.ts index e722720e6953..2d8a3d238399 100644 --- a/apps/meteor/server/services/federation/application/room/receiver/RoomServiceReceiver.ts +++ b/apps/meteor/server/services/federation/application/room/receiver/RoomServiceReceiver.ts @@ -20,7 +20,7 @@ import type { FederationRoomEditExternalMessageDto, FederationRoomRoomChangePowerLevelsEventDto, } from '../input/RoomReceiverDto'; -import { AbstractFederationApplicationService } from '../../AbstractFederationService'; +import { AbstractFederationApplicationService } from '../../AbstractFederationApplicationService'; import type { RocketChatFileAdapter } from '../../../infrastructure/rocket-chat/adapters/File'; import type { RocketChatNotificationAdapter } from '../../../infrastructure/rocket-chat/adapters/Notification'; import type { InMemoryQueue } from '../../../infrastructure/queue/InMemoryQueue'; diff --git a/apps/meteor/server/services/federation/application/room/sender/RoomInternalValidator.ts b/apps/meteor/server/services/federation/application/room/sender/RoomInternalValidator.ts index 695dbee0bc88..fecc262d80af 100644 --- a/apps/meteor/server/services/federation/application/room/sender/RoomInternalValidator.ts +++ b/apps/meteor/server/services/federation/application/room/sender/RoomInternalValidator.ts @@ -8,7 +8,7 @@ import type { RocketChatFileAdapter } from '../../../infrastructure/rocket-chat/ 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 { AbstractFederationApplicationService } from '../../AbstractFederationService'; +import { AbstractFederationApplicationService } from '../../AbstractFederationApplicationService'; export class FederationRoomInternalValidator extends AbstractFederationApplicationService { constructor( diff --git a/apps/meteor/server/services/federation/application/room/sender/RoomServiceSender.ts b/apps/meteor/server/services/federation/application/room/sender/RoomServiceSender.ts index 7a573b2ff607..4bd7eb9bb29d 100644 --- a/apps/meteor/server/services/federation/application/room/sender/RoomServiceSender.ts +++ b/apps/meteor/server/services/federation/application/room/sender/RoomServiceSender.ts @@ -10,7 +10,7 @@ import type { RocketChatNotificationAdapter } from '../../../infrastructure/rock 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 { AbstractFederationApplicationService } from '../../AbstractFederationService'; +import { AbstractFederationApplicationService } from '../../AbstractFederationApplicationService'; import { getExternalMessageSender } from '../message/sender/message-sender-helper'; import { MATRIX_POWER_LEVELS } from '../../../infrastructure/matrix/definitions/MatrixPowerLevels'; import { ROCKET_CHAT_FEDERATION_ROLES } from '../../../infrastructure/rocket-chat/definitions/FederatedRoomInternalRoles'; diff --git a/apps/meteor/server/services/federation/application/user/receiver/UserServiceReceiver.ts b/apps/meteor/server/services/federation/application/user/receiver/UserServiceReceiver.ts index 8540de4a5765..5edd3b109023 100644 --- a/apps/meteor/server/services/federation/application/user/receiver/UserServiceReceiver.ts +++ b/apps/meteor/server/services/federation/application/user/receiver/UserServiceReceiver.ts @@ -4,7 +4,7 @@ import type { RocketChatNotificationAdapter } from '../../../infrastructure/rock 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 { AbstractFederationApplicationService } from '../../AbstractFederationService'; +import { AbstractFederationApplicationService } from '../../AbstractFederationApplicationService'; import type { FederationUserTypingStatusEventDto } from '../../room/input/UserReceiverDto'; export class FederationUserServiceReceiver extends AbstractFederationApplicationService { diff --git a/apps/meteor/server/services/federation/application/user/sender/UserServiceSender.ts b/apps/meteor/server/services/federation/application/user/sender/UserServiceSender.ts index daaf15e299a2..f3bc032784cc 100644 --- a/apps/meteor/server/services/federation/application/user/sender/UserServiceSender.ts +++ b/apps/meteor/server/services/federation/application/user/sender/UserServiceSender.ts @@ -3,7 +3,7 @@ import type { RocketChatFileAdapter } from '../../../infrastructure/rocket-chat/ 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 { AbstractFederationApplicationService } from '../../AbstractFederationService'; +import { AbstractFederationApplicationService } from '../../AbstractFederationApplicationService'; export class FederationUserServiceSender extends AbstractFederationApplicationService { constructor( diff --git a/apps/meteor/server/services/federation/infrastructure/rocket-chat/adapters/Settings.ts b/apps/meteor/server/services/federation/infrastructure/rocket-chat/adapters/Settings.ts index 74b1d0b3f6d6..3cdacc264b03 100644 --- a/apps/meteor/server/services/federation/infrastructure/rocket-chat/adapters/Settings.ts +++ b/apps/meteor/server/services/federation/infrastructure/rocket-chat/adapters/Settings.ts @@ -13,10 +13,10 @@ const EVERYTHING_REGEX = '.*'; const LISTEN_RULES = EVERYTHING_REGEX; export class RocketChatSettingsAdapter { - public initialize(): void { + public async initialize() { this.addFederationSettings(); this.watchChangesAndUpdateRegistrationFile(); - this.updateSettingsWithProvidedConfigFileIfNecessary(); + await this.updateSettingsWithProvidedConfigFileIfNecessary(); } public getApplicationServiceId(): string { @@ -92,16 +92,14 @@ export class RocketChatSettingsAdapter { 'Federation_Matrix_bridge_localpart', ], ([enabled]) => - Promise.await( - callback( - enabled === true, - this.getApplicationServiceId(), - this.getHomeServerUrl(), - this.getHomeServerDomain(), - this.getBridgeUrl(), - this.getBridgePort(), - this.generateRegistrationFileObject(), - ), + callback( + enabled === true, + this.getApplicationServiceId(), + this.getHomeServerUrl(), + this.getHomeServerDomain(), + this.getBridgeUrl(), + this.getBridgePort(), + this.generateRegistrationFileObject(), ), ); } @@ -272,20 +270,22 @@ export class RocketChatSettingsAdapter { : resolve(process.cwd(), '../../../matrix-federation-config/registration.yaml'); } - private updateSettingsWithProvidedConfigFileIfNecessary(): void { + private async updateSettingsWithProvidedConfigFileIfNecessary() { const existingConfiguration = this.getRegistrationFileFromHomeserver(); if (!existingConfiguration) { return; } - Promise.await(Settings.updateValueById('Federation_Matrix_enabled', true)); - Promise.await(Settings.updateValueById('Federation_Matrix_id', existingConfiguration.id)); - Promise.await(Settings.updateValueById('Federation_Matrix_hs_token', existingConfiguration.homeserverToken)); - Promise.await(Settings.updateValueById('Federation_Matrix_as_token', existingConfiguration.applicationServiceToken)); - Promise.await(Settings.updateValueById('Federation_Matrix_homeserver_url', existingConfiguration.rocketchat?.homeServerUrl)); - Promise.await(Settings.updateValueById('Federation_Matrix_homeserver_domain', existingConfiguration.rocketchat?.domainName)); - Promise.await(Settings.updateValueById('Federation_Matrix_bridge_url', existingConfiguration.bridgeUrl)); - Promise.await(Settings.updateValueById('Federation_Matrix_bridge_localpart', existingConfiguration.botName)); - Promise.await(Settings.update({ _id: 'Federation_Matrix_registration_file' }, { $set: { hidden: Boolean(existingConfiguration) } })); + await Promise.all([ + Settings.updateValueById('Federation_Matrix_enabled', true), + Settings.updateValueById('Federation_Matrix_id', existingConfiguration.id), + Settings.updateValueById('Federation_Matrix_hs_token', existingConfiguration.homeserverToken), + Settings.updateValueById('Federation_Matrix_as_token', existingConfiguration.applicationServiceToken), + Settings.updateValueById('Federation_Matrix_homeserver_url', existingConfiguration.rocketchat?.homeServerUrl), + Settings.updateValueById('Federation_Matrix_homeserver_domain', existingConfiguration.rocketchat?.domainName), + Settings.updateValueById('Federation_Matrix_bridge_url', existingConfiguration.bridgeUrl), + Settings.updateValueById('Federation_Matrix_bridge_localpart', existingConfiguration.botName), + Settings.update({ _id: 'Federation_Matrix_registration_file' }, { $set: { hidden: Boolean(existingConfiguration) } }), + ]); } } diff --git a/apps/meteor/server/services/federation/infrastructure/rocket-chat/hooks/index.ts b/apps/meteor/server/services/federation/infrastructure/rocket-chat/hooks/index.ts index 78893cc2847f..620c227fe112 100644 --- a/apps/meteor/server/services/federation/infrastructure/rocket-chat/hooks/index.ts +++ b/apps/meteor/server/services/federation/infrastructure/rocket-chat/hooks/index.ts @@ -189,7 +189,7 @@ export class FederationHooks { ); } - public static afterRoomRoleChanged(federationRoomService: FederationRoomServiceSender, data?: Record): void { + public static async afterRoomRoleChanged(federationRoomService: FederationRoomServiceSender, data?: Record) { if (!data || !settings.get('Federation_Matrix_enabled')) { return; } @@ -218,7 +218,7 @@ export class FederationHooks { if (!handlers[`${role}-${action}`]) { return; } - Promise.await(handlers[`${role}-${action}`](internalUserId, internalTargetUserId, internalRoomId)); + await handlers[`${role}-${action}`](internalUserId, internalTargetUserId, internalRoomId); } public static afterRoomNameChanged(callback: (roomId: string, changedRoomName: string) => Promise): void { diff --git a/apps/meteor/server/services/federation/service.ts b/apps/meteor/server/services/federation/service.ts index 0aac84a08601..566fb07a6056 100644 --- a/apps/meteor/server/services/federation/service.ts +++ b/apps/meteor/server/services/federation/service.ts @@ -61,7 +61,6 @@ export abstract class AbstractFederationService extends ServiceClassInternal { this.internalQueueInstance = internalQueueInstance; this.internalSettingsAdapter = internalSettingsAdapter; this.bridge = federationBridge; - this.initialize(); this.internalFileAdapter = FederationFactory.buildInternalFileAdapter(); this.internalRoomAdapter = FederationFactory.buildInternalRoomAdapter(); this.internalUserAdapter = FederationFactory.buildInternalUserAdapter(); @@ -129,9 +128,9 @@ export abstract class AbstractFederationService extends ServiceClassInternal { return this.onDisableFederation(); } - private initialize(): void { + public async initialize() { this.internalSettingsAdapter = FederationFactory.buildInternalSettingsAdapter(); - this.internalSettingsAdapter.initialize(); + await this.internalSettingsAdapter.initialize(); this.cancelSettingsObserver = this.internalSettingsAdapter.onFederationEnabledStatusChanged( this.onFederationEnabledSettingChange.bind(this), ); @@ -152,7 +151,7 @@ export abstract class AbstractFederationService extends ServiceClassInternal { this.internalQueueInstance, this.bridge, ); - const federationMessageServiceReceiver = FederationFactory.buildMessageServiceReceiver( + const federationMessageServiceReceiver = await FederationFactory.buildMessageServiceReceiver( this.internalRoomAdapter, this.internalUserAdapter, this.internalMessageAdapter, @@ -317,4 +316,10 @@ export class FederationService extends AbstractBaseFederationService implements FederationRoomSenderConverter.toCreateDirectMessageRoomDto(internalInviterId, internalRoomId, externalInviteeId), ); } + + static async createFederationService(): Promise { + const federationService = new FederationService(); + await federationService.initialize(); + return federationService; + } } diff --git a/apps/meteor/server/services/team/service.ts b/apps/meteor/server/services/team/service.ts index f1100c56ae47..1041c1cd885c 100644 --- a/apps/meteor/server/services/team/service.ts +++ b/apps/meteor/server/services/team/service.ts @@ -158,7 +158,7 @@ export class TeamService extends ServiceClassInternal implements ITeamService { } if (updateRoom && typeof type !== 'undefined') { - saveRoomType(team.roomId, type === TEAM_TYPE.PRIVATE ? 'p' : 'c', user); + await saveRoomType(team.roomId, type === TEAM_TYPE.PRIVATE ? 'p' : 'c', user); } await Team.updateNameAndType(teamId, updateData); diff --git a/apps/meteor/tests/unit/server/federation/Federation.spec.ts b/apps/meteor/tests/unit/server/federation/Federation.spec.ts index 24d19f9e4f26..834040935b88 100644 --- a/apps/meteor/tests/unit/server/federation/Federation.spec.ts +++ b/apps/meteor/tests/unit/server/federation/Federation.spec.ts @@ -22,26 +22,26 @@ describe('Federation[Server] - Federation', () => { afterEach(() => findOneByRoomIdAndUserIdStub.reset()); describe('#actionAllowed()', () => { - it('should return false if the room is NOT federated', () => { - expect(Federation.actionAllowed({ t: 'c' } as any, RoomMemberActions.INVITE)).to.be.false; + it('should return false if the room is NOT federated', async () => { + await expect(Federation.actionAllowed({ t: 'c' } as any, RoomMemberActions.INVITE)).to.eventually.be.false; }); - it('should return false if the room is a DM one', () => { - expect(Federation.actionAllowed({ t: 'd', federated: true } as any, RoomMemberActions.INVITE)).to.be.false; + it('should return false if the room is a DM one', async () => { + await expect(Federation.actionAllowed({ t: 'd', federated: true } as any, RoomMemberActions.INVITE)).to.eventually.be.false; }); - it('should return true if an userId was not provided', () => { - expect(Federation.actionAllowed({ t: 'c', federated: true } as any, RoomMemberActions.INVITE)).to.be.true; + it('should return true if an userId was not provided', async () => { + await expect(Federation.actionAllowed({ t: 'c', federated: true } as any, RoomMemberActions.INVITE)).to.eventually.be.true; }); - it('should return true if there is no subscription for the userId', () => { + it('should return true if there is no subscription for the userId', async () => { findOneByRoomIdAndUserIdStub.returns(undefined); - expect(Federation.actionAllowed({ t: 'c', federated: true } as any, RoomMemberActions.INVITE, 'userId')).to.be.true; + await expect(Federation.actionAllowed({ t: 'c', federated: true } as any, RoomMemberActions.INVITE, 'userId')).to.eventually.be.true; }); - it('should return true if the action is equal to Leave (since any user can leave a channel)', () => { + it('should return true if the action is equal to Leave (since any user can leave a channel)', async () => { findOneByRoomIdAndUserIdStub.returns({}); - expect(Federation.actionAllowed({ t: 'c', federated: true } as any, RoomMemberActions.LEAVE, 'userId')).to.be.true; + await expect(Federation.actionAllowed({ t: 'c', federated: true } as any, RoomMemberActions.LEAVE, 'userId')).to.eventually.be.true; }); const allowedActions = [ @@ -56,36 +56,37 @@ describe('Federation[Server] - Federation', () => { Object.values(RoomMemberActions) .filter((action) => !allowedActions.includes(action as any)) .forEach((action) => { - it('should return false if the action is NOT allowed within the federation context for regular channels', () => { + it('should return false if the action is NOT allowed within the federation context for regular channels', async () => { findOneByRoomIdAndUserIdStub.returns({}); - expect(Federation.actionAllowed({ t: 'c', federated: true } as any, action, 'userId')).to.be.false; + await expect(Federation.actionAllowed({ t: 'c', federated: true } as any, action, 'userId')).to.eventually.be.false; }); }); allowedActions.forEach((action) => { - it('should return true if the action is allowed within the federation context for regular channels and the user is a room owner', () => { + it('should return true if the action is allowed within the federation context for regular channels and the user is a room owner', async () => { findOneByRoomIdAndUserIdStub.returns({ roles: ['owner'] }); - expect(Federation.actionAllowed({ t: 'c', federated: true } as any, action, 'userId')).to.be.true; + await expect(Federation.actionAllowed({ t: 'c', federated: true } as any, action, 'userId')).to.eventually.be.true; }); }); const allowedActionsForModerators = allowedActions.filter((action) => action !== RoomMemberActions.SET_AS_OWNER); allowedActionsForModerators.forEach((action) => { - it('should return true if the action is allowed within the federation context for regular channels and the user is a room moderator', () => { + it('should return true if the action is allowed within the federation context for regular channels and the user is a room moderator', async () => { findOneByRoomIdAndUserIdStub.returns({ roles: ['moderator'] }); - expect(Federation.actionAllowed({ t: 'c', federated: true } as any, action, 'userId')).to.be.true; + await expect(Federation.actionAllowed({ t: 'c', federated: true } as any, action, 'userId')).to.eventually.be.true; }); }); - it('should return false if the action is equal to set owner and the user is a room moderator', () => { + it('should return false if the action is equal to set owner and the user is a room moderator', async () => { findOneByRoomIdAndUserIdStub.returns({ roles: ['moderator'] }); - expect(Federation.actionAllowed({ t: 'c', federated: true } as any, RoomMemberActions.SET_AS_OWNER, 'userId')).to.be.false; + await expect(Federation.actionAllowed({ t: 'c', federated: true } as any, RoomMemberActions.SET_AS_OWNER, 'userId')).to.eventually.be + .false; }); const disallowedActionForRegularUsers = allowedActions.filter((action) => action !== RoomMemberActions.LEAVE); disallowedActionForRegularUsers.forEach((action) => { - it('should return false if the for all other actions (excluding LEAVE) for regular users', () => { + it('should return false if the for all other actions (excluding LEAVE) for regular users', async () => { findOneByRoomIdAndUserIdStub.returns({}); - expect(Federation.actionAllowed({ t: 'c', federated: true } as any, action, 'userId')).to.be.false; + await expect(Federation.actionAllowed({ t: 'c', federated: true } as any, action, 'userId')).to.eventually.be.false; }); }); });