Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion apps/meteor/app/apps/server/bridges/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -109,7 +110,8 @@ export class AppRoomBridge extends RoomBridge {
protected async update(room: IRoom, members: Array<string> = [], appId: string): Promise<void> {
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.');
}

Expand Down Expand Up @@ -170,6 +172,27 @@ export class AppRoomBridge extends RoomBridge {
return rid;
}

protected async archiveRoom(room: IRoom, appId: string): Promise<boolean> {
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<boolean> {
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<IUser[]> {
this.orch.debugLog(`The App ${appId} is getting room moderators for room id: ${roomId}`);
return this.getUsersByRoomIdAndSubscriptionRole(roomId, 'moderator');
Expand Down
6 changes: 6 additions & 0 deletions apps/meteor/app/apps/server/converters/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export class AppRoomsConverter {
...room.source,
},
}),
...(room.isArchived && { archived: room.isArchived }),
};

return Object.assign(newRoom, room._unmappedProperties_);
Expand Down Expand Up @@ -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;
Expand Down