-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Expand file tree
/
Copy pathsaveRoomTopic.ts
More file actions
31 lines (26 loc) · 989 Bytes
/
saveRoomTopic.ts
File metadata and controls
31 lines (26 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { Message, Room } from '@rocket.chat/core-services';
import type { IUser } from '@rocket.chat/core-typings';
import { Rooms } from '@rocket.chat/models';
import { Match } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
import { callbacks } from '../../../../lib/callbacks';
export const saveRoomTopic = async (
rid: string,
roomTopic: string | undefined,
user: Pick<IUser, 'username' | '_id' | 'federation' | 'federated'>,
sendMessage = true,
) => {
if (!Match.test(rid, String)) {
throw new Meteor.Error('invalid-room', 'Invalid room', {
function: 'RocketChat.saveRoomTopic',
});
}
const room = await Rooms.findOneById(rid);
await Room.beforeTopicChange(room!);
const update = await Rooms.setTopicById(rid, roomTopic);
if (update && sendMessage) {
await Message.saveSystemMessage('room_changed_topic', rid, roomTopic || '', user);
}
await callbacks.run('afterRoomTopicChange', undefined, { room, topic: roomTopic, user });
return update;
};