import { Messages, Rooms, Subscriptions } from '@rocket.chat/models'; import { callbacks } from '../callbacks'; import { FileUpload } from '../media/file-upload'; import { notifyOnRoomChangedById, notifyOnSubscriptionChanged } from '../notifyListener'; export const deleteRoom = async function (rid: string): Promise { await FileUpload.removeFilesByRoomId(rid); await Messages.removeByRoomId(rid); await callbacks.run('beforeDeleteRoom', rid); await Subscriptions.removeByRoomId(rid, { async onTrash(doc) { void notifyOnSubscriptionChanged(doc, 'removed'); }, }); await FileUpload.getStore('Avatars').deleteByRoomId(rid); await callbacks.run('afterDeleteRoom', rid); const { deletedCount } = await Rooms.removeById(rid); if (deletedCount) { void notifyOnRoomChangedById(rid, 'removed'); } };