forked from nishant8BITS/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheraseRoom.js
More file actions
45 lines (36 loc) · 1.17 KB
/
eraseRoom.js
File metadata and controls
45 lines (36 loc) · 1.17 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* globals RocketChat */
Meteor.methods({
eraseRoom(rid) {
check(rid, String);
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'eraseRoom'
});
}
const room = RocketChat.models.Rooms.findOneById(rid);
if (!room) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', {
method: 'eraseRoom'
});
}
if (Apps && Apps.isLoaded()) {
const prevent = Promise.await(Apps.getBridges().getListenerBridge().roomEvent('IPreRoomDeletePrevent', room));
if (prevent) {
throw new Meteor.Error('error-app-prevented-deleting', 'A Rocket.Chat App prevented the room erasing.');
}
}
if (!RocketChat.roomTypes.roomTypes[room.t].canBeDeleted(room)) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'eraseRoom'
});
}
RocketChat.models.Messages.removeFilesByRoomId(rid);
RocketChat.models.Messages.removeByRoomId(rid);
RocketChat.models.Subscriptions.removeByRoomId(rid);
const result = RocketChat.models.Rooms.removeById(rid);
if (Apps && Apps.isLoaded()) {
Apps.getBridges().getListenerBridge().roomEvent('IPostRoomDeleted', room);
}
return result;
}
});