diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index 591a8b9465b28..78116f00d071a 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -9,6 +9,7 @@ import type { ISubscription, IUser as ICoreUser } from '@rocket.chat/core-typing import type { AppServerOrchestrator } from '../orchestrator'; import { Rooms, Subscriptions, Users } from '../../../models/server'; import { addUserToRoom } from '../../../lib/server/functions/addUserToRoom'; +import { archiveRoom, unarchiveRoom } from '../../../lib/server'; export class AppRoomBridge extends RoomBridge { // eslint-disable-next-line no-empty-function @@ -109,7 +110,8 @@ export class AppRoomBridge extends RoomBridge { protected async update(room: IRoom, members: Array = [], appId: string): Promise { this.orch.debugLog(`The App ${appId} is updating a room.`); - if (!room.id || !Rooms.findOneById(room.id)) { + const roomBeforeUpdate = Rooms.findOneById(room.id); + if (!room.id || !roomBeforeUpdate) { throw new Error('A room must exist to update.'); } @@ -170,6 +172,27 @@ export class AppRoomBridge extends RoomBridge { return rid; } + protected async archiveRoom(room: IRoom, appId: string): Promise { + this.orch.debugLog(`The App ${appId} is archiving a room`); + try { + archiveRoom(room.id); + } catch (error) { + this.orch.getRocketChatLogger().error(error); + return false; + } + return true; + } + + protected async unarchiveRoom(room: IRoom, appId: string): Promise { + this.orch.debugLog(`The App ${appId} is unarchiving a room`); + try { + unarchiveRoom(room.id); + } catch (error) { + this.orch.getRocketChatLogger().error(error); + return false; + } + return true; + protected getModerators(roomId: string, appId: string): Promise { this.orch.debugLog(`The App ${appId} is getting room moderators for room id: ${roomId}`); return this.getUsersByRoomIdAndSubscriptionRole(roomId, 'moderator'); diff --git a/apps/meteor/app/apps/server/converters/rooms.js b/apps/meteor/app/apps/server/converters/rooms.js index 4a9f6225af15a..93e07b035f174 100644 --- a/apps/meteor/app/apps/server/converters/rooms.js +++ b/apps/meteor/app/apps/server/converters/rooms.js @@ -101,6 +101,7 @@ export class AppRoomsConverter { ...room.source, }, }), + ...(room.isArchived && { archived: room.isArchived }), }; return Object.assign(newRoom, room._unmappedProperties_); @@ -129,6 +130,11 @@ export class AppRoomsConverter { _USERNAMES: '_USERNAMES', description: 'description', source: 'source', + isArchived: (room) => { + const stat = Boolean(room.archived); + delete room.archived; + return stat; + }, isDefault: (room) => { const result = !!room.default; delete room.default;