diff --git a/src/definition/accessors/INotifier.ts b/src/definition/accessors/INotifier.ts index 17324d4ad..a41fb22c4 100644 --- a/src/definition/accessors/INotifier.ts +++ b/src/definition/accessors/INotifier.ts @@ -51,16 +51,6 @@ export interface INotifier { */ notifyRoom(room: IRoom, message: IMessage): Promise; - /** - * Sends a direct message to a user. - * @param user The user to send the message to - * @param partialMsg The partial message to send - * @returns A Promise that resolves when the message has been sent - * @throws {Error} if the room could not be created - * @throws {Error} if the message could not be sent - */ - sendDirectMessage(user: IUser, partialMsg: Omit): Promise; - /** * Notifies all of the users a typing indicator in the provided scope. * diff --git a/src/definition/messages/IMessage.ts b/src/definition/messages/IMessage.ts index 50e50b0e9..afbc21b86 100644 --- a/src/definition/messages/IMessage.ts +++ b/src/definition/messages/IMessage.ts @@ -1,6 +1,6 @@ import type { Block } from '@rocket.chat/ui-kit'; -import type { IRoom, RoomType } from '../rooms'; +import type { IRoom } from '../rooms'; import type { IBlock } from '../uikit'; import type { IUser, IUserLookup } from '../users'; import type { IMessageAttachment } from './IMessageAttachment'; @@ -32,7 +32,3 @@ export interface IMessage { pinnedAt?: Date; pinnedBy?: IUserLookup; } - -export interface IDirectMessage extends Omit { - room: Pick & { type: RoomType.DIRECT_MESSAGE }; -} diff --git a/src/definition/messages/index.ts b/src/definition/messages/index.ts index 94701e1f3..a46a0310e 100644 --- a/src/definition/messages/index.ts +++ b/src/definition/messages/index.ts @@ -1,4 +1,4 @@ -import { IDirectMessage, IMessage } from './IMessage'; +import { IMessage } from './IMessage'; import { IMessageAction } from './IMessageAction'; import { IMessageAttachment } from './IMessageAttachment'; import { IMessageAttachmentAuthor } from './IMessageAttachmentAuthor'; @@ -32,7 +32,6 @@ import { MessageActionType } from './MessageActionType'; import { MessageProcessingType } from './MessageProcessingType'; export { - IDirectMessage, IMessage, IMessageAttachment, IMessageAttachmentAuthor, diff --git a/src/server/accessors/Modify.ts b/src/server/accessors/Modify.ts index db54714e5..7abd4bc1c 100644 --- a/src/server/accessors/Modify.ts +++ b/src/server/accessors/Modify.ts @@ -44,7 +44,7 @@ export class Modify implements IModify { this.deleter = new ModifyDeleter(this.bridges, this.appId); this.updater = new ModifyUpdater(this.bridges, this.appId); this.extender = new ModifyExtender(this.bridges, this.appId); - this.notifier = new Notifier(this.bridges.getUserBridge(), this.bridges.getMessageBridge(), this.bridges.getRoomBridge(), this.appId); + this.notifier = new Notifier(this.bridges.getUserBridge(), this.bridges.getMessageBridge(), this.appId); this.uiController = new UIController(this.appId, this.bridges); this.scheduler = new SchedulerModify(this.bridges.getSchedulerBridge(), this.appId); this.oauthApps = new OAuthAppsModify(this.bridges.getOAuthAppsBridge(), this.appId); diff --git a/src/server/accessors/Notifier.ts b/src/server/accessors/Notifier.ts index 6e594b05a..8e81cc2e9 100644 --- a/src/server/accessors/Notifier.ts +++ b/src/server/accessors/Notifier.ts @@ -1,19 +1,14 @@ import type { IMessageBuilder, INotifier } from '../../definition/accessors'; import type { ITypingOptions } from '../../definition/accessors/INotifier'; import { TypingScope } from '../../definition/accessors/INotifier'; -import type { IDirectMessage, IMessage } from '../../definition/messages'; -import { RoomType, type IRoom } from '../../definition/rooms'; +import type { IMessage } from '../../definition/messages'; +import type { IRoom } from '../../definition/rooms'; import type { IUser } from '../../definition/users'; -import type { MessageBridge, RoomBridge, UserBridge } from '../bridges'; +import type { MessageBridge, UserBridge } from '../bridges'; import { MessageBuilder } from './MessageBuilder'; export class Notifier implements INotifier { - constructor( - private readonly userBridge: UserBridge, - private readonly msgBridge: MessageBridge, - private readonly roomBridge: RoomBridge, - private readonly appId: string, - ) {} + constructor(private readonly userBridge: UserBridge, private readonly msgBridge: MessageBridge, private readonly appId: string) {} public async notifyUser(user: IUser, message: IMessage): Promise { if (!message.sender || !message.sender.id) { @@ -35,30 +30,6 @@ export class Notifier implements INotifier { await this.msgBridge.doNotifyRoom(room, message, this.appId); } - /** - * Sends a direct message to a user. - * - * @param {IUser} user - The user to send the message to. - * @param {Omit} partialMsg - The partial message to send, without `room` parameter. - * @returns {Promise} A Promise that resolves when the message has been sent. - */ - public async sendDirectMessage(user: IUser, partialMsg: Omit): Promise { - const sender = partialMsg.sender || (await this.userBridge.doGetAppUser(this.appId)); - const dmRoom = (await this.roomBridge.doGetDirectByUsernames([user.username, sender.username], this.appId)) || (await this.createDMRoom(user, sender)); - - const message: IDirectMessage = { - ...partialMsg, - room: { - type: RoomType.DIRECT_MESSAGE, - id: dmRoom.id, - creator: sender, - }, - sender, - }; - - await this.msgBridge.doCreate(message, this.appId); - } - public async typing(options: ITypingOptions): Promise<() => Promise> { options.scope = options.scope || TypingScope.Room; @@ -75,32 +46,4 @@ export class Notifier implements INotifier { public getMessageBuilder(): IMessageBuilder { return new MessageBuilder(); } - - /** - * Creates a new direct message room between two users. - * - * @param {IUser} user - The first user to create the room for. - * @param {IUser} sender - The second user to create the room for. - * @returns {Promise>} A Promise that resolves with the newly created direct message room id. - */ - private async createDMRoom(user: IUser, sender: IUser): Promise> { - const newDMrid = await this.roomBridge.doCreate( - { - type: RoomType.DIRECT_MESSAGE, - // Leave the usernames field empty for now. It will be deprecated in 2.0.0. - usernames: [], - creator: sender, - // Leave the ID field empty for now. It will be generated by the server. - id: '', - // Leave the slugified name field empty for now. It will be generated by the server. - slugifiedName: '', - }, - [user.username, sender.username], - this.appId, - ); - - return { - id: newDMrid, - }; - } } diff --git a/src/server/bridges/MessageBridge.ts b/src/server/bridges/MessageBridge.ts index 6b659f19d..ea3af1437 100644 --- a/src/server/bridges/MessageBridge.ts +++ b/src/server/bridges/MessageBridge.ts @@ -1,5 +1,5 @@ import type { ITypingOptions } from '../../definition/accessors/INotifier'; -import type { IMessage, IDirectMessage } from '../../definition/messages'; +import type { IMessage } from '../../definition/messages'; import type { IRoom } from '../../definition/rooms'; import type { IUser } from '../../definition/users'; import { PermissionDeniedError } from '../errors/PermissionDeniedError'; @@ -12,7 +12,7 @@ export interface ITypingDescriptor extends ITypingOptions { } export abstract class MessageBridge extends BaseBridge { - public async doCreate(message: IMessage | IDirectMessage, appId: string): Promise { + public async doCreate(message: IMessage, appId: string): Promise { if (this.hasWritePermission(appId)) { return this.create(message, appId); } @@ -54,7 +54,7 @@ export abstract class MessageBridge extends BaseBridge { } } - protected abstract create(message: IMessage | IDirectMessage, appId: string): Promise; + protected abstract create(message: IMessage, appId: string): Promise; protected abstract update(message: IMessage, appId: string): Promise; diff --git a/src/server/managers/AppAccessorManager.ts b/src/server/managers/AppAccessorManager.ts index 75d047554..a3a04848c 100644 --- a/src/server/managers/AppAccessorManager.ts +++ b/src/server/managers/AppAccessorManager.ts @@ -177,7 +177,7 @@ export class AppAccessorManager { const persist = new PersistenceRead(this.bridges.getPersistenceBridge(), appId); const room = new RoomRead(this.bridges.getRoomBridge(), appId); const user = new UserRead(this.bridges.getUserBridge(), appId); - const noti = new Notifier(this.bridges.getUserBridge(), this.bridges.getMessageBridge(), this.bridges.getRoomBridge(), appId); + const noti = new Notifier(this.bridges.getUserBridge(), this.bridges.getMessageBridge(), appId); const livechat = new LivechatRead(this.bridges.getLivechatBridge(), appId); const upload = new UploadRead(this.bridges.getUploadBridge(), appId); const cloud = new CloudWorkspaceRead(this.bridges.getCloudWorkspaceBridge(), appId); diff --git a/tests/server/accessors/Modify.spec.ts b/tests/server/accessors/Modify.spec.ts index 13117855a..57e8cd7c1 100644 --- a/tests/server/accessors/Modify.spec.ts +++ b/tests/server/accessors/Modify.spec.ts @@ -1,7 +1,7 @@ import { Expect, SetupFixture, Test } from 'alsatian'; import { Modify } from '../../../src/server/accessors'; -import type { AppBridges, MessageBridge, ModerationBridge, RoomBridge, SchedulerBridge, UiInteractionBridge, UserBridge } from '../../../src/server/bridges'; +import type { AppBridges, MessageBridge, ModerationBridge, SchedulerBridge, UiInteractionBridge, UserBridge } from '../../../src/server/bridges'; import type { OAuthAppsBridge } from '../../../src/server/bridges/OAuthAppsBridge'; export class ModifyAccessorTestFixture { @@ -16,9 +16,6 @@ export class ModifyAccessorTestFixture { getMessageBridge(): MessageBridge { return {} as MessageBridge; }, - getRoomBridge() { - return {} as RoomBridge; - }, getUiInteractionBridge(): UiInteractionBridge { return {} as UiInteractionBridge; }, diff --git a/tests/server/accessors/Notifier.spec.ts b/tests/server/accessors/Notifier.spec.ts index cd652458e..26d9fde7c 100644 --- a/tests/server/accessors/Notifier.spec.ts +++ b/tests/server/accessors/Notifier.spec.ts @@ -4,7 +4,7 @@ import type { IMessage } from '../../../src/definition/messages'; import type { IRoom } from '../../../src/definition/rooms'; import type { IUser } from '../../../src/definition/users'; import { MessageBuilder, Notifier } from '../../../src/server/accessors'; -import type { MessageBridge, RoomBridge, UserBridge } from '../../../src/server/bridges'; +import type { MessageBridge, UserBridge } from '../../../src/server/bridges'; import { TestData } from '../../test-data/utilities'; export class NotifierAccessorTestFixture { @@ -12,8 +12,6 @@ export class NotifierAccessorTestFixture { private mockMsgBridge: MessageBridge; - private mockRoomBridge: RoomBridge; - @SetupFixture public setupFixture() { this.mockMsgBridge = { @@ -29,9 +27,9 @@ export class NotifierAccessorTestFixture { @AsyncTest() public async useNotifier() { - Expect(() => new Notifier(this.mockUserBridge, this.mockMsgBridge, this.mockRoomBridge, 'testing')).not.toThrow(); + Expect(() => new Notifier(this.mockUserBridge, this.mockMsgBridge, 'testing')).not.toThrow(); - const noti = new Notifier(this.mockUserBridge, this.mockMsgBridge, this.mockRoomBridge, 'testing'); + const noti = new Notifier(this.mockUserBridge, this.mockMsgBridge, 'testing'); await Expect(() => noti.notifyRoom(TestData.getRoom(), TestData.getMessage())).not.toThrowAsync(); await Expect(() => noti.notifyUser(TestData.getUser(), TestData.getMessage())).not.toThrowAsync(); Expect(noti.getMessageBuilder() instanceof MessageBuilder).toBe(true); diff --git a/tests/server/managers/AppAccessorManager.spec.ts b/tests/server/managers/AppAccessorManager.spec.ts index 17e66ca5f..49ded7c6b 100644 --- a/tests/server/managers/AppAccessorManager.spec.ts +++ b/tests/server/managers/AppAccessorManager.spec.ts @@ -127,7 +127,7 @@ export class AppAccessorManagerTestFixture { Expect(this.bridges.getServerSettingBridge).toHaveBeenCalled().exactly(1); Expect(this.bridges.getEnvironmentalVariableBridge).toHaveBeenCalled().exactly(1); Expect(this.bridges.getPersistenceBridge).toHaveBeenCalled().exactly(1); - Expect(this.bridges.getRoomBridge).toHaveBeenCalled().exactly(2); + Expect(this.bridges.getRoomBridge).toHaveBeenCalled().exactly(1); Expect(this.bridges.getUserBridge).toHaveBeenCalled().exactly(2); Expect(this.bridges.getMessageBridge).toHaveBeenCalled().exactly(2); }