MCPcopy Create free account
hub / github.com/async-labs/async / deleteForClearHistory

Method deleteForClearHistory

api/server/models/Message.ts:305–367  ·  view source on GitHub ↗
({ userId, id })

Source from the content-addressed store, hash-verified

303 }
304
305 public static async deleteForClearHistory({ userId, id }) {
306 if (!id) {
307 throw new Error('Bad data');
308 }
309
310 const messageToBeDeleted = await this.findOne({ _id: id }).setOptions({ lean: true });
311
312 if (!messageToBeDeleted) {
313 throw new Error(id);
314 }
315
316 const { chat } = await this.checkPermission({ userId, chatId: messageToBeDeleted.chatId });
317
318 //
319 await User.markMessageAsReadForParticipantsOfChatAfterMessageIsDeletedByUser({
320 userIdsToNotify: chat.chatParticipantIds.filter((id) => id !== userId),
321 messageId: id,
322 });
323
324 // call markMessageAsReadBySomeoneAfterMessageIsDeletedByUser
325 await User.updateOne(
326 { _id: userId },
327 {
328 $pull: {
329 unreadBySomeoneMessageIds: id,
330 },
331 },
332 );
333
334 // const allThreadMessages = await this.find({
335 // parentMessageId: id,
336 // }).setOptions({ lean: true });
337
338 // if (allThreadMessages.length > 0) {
339 // for (const threadMessage of allThreadMessages) {
340 // await this.deleteOne({ _id: threadMessage._id.toString() });
341
342 // const arrayOfFileUrls = threadMessage.files.map((f) => {
343 // return f['fileUrl'];
344 // });
345
346 // if (arrayOfFileUrls.length > 0) {
347 // deleteFiles(arrayOfFileUrls).catch((err) => console.log(err));
348 // }
349 // }
350 // }
351
352 await this.deleteOne({ _id: id });
353
354 const arrayOfFileUrls = messageToBeDeleted.files.map((f) => {
355 return f['fileUrl'];
356 });
357
358 if (arrayOfFileUrls.length > 0) {
359 deleteFiles(arrayOfFileUrls).catch((err) => console.log(err));
360 }
361
362 // 2 browsers, same user fix

Callers

nothing calls this directly

Tested by

no test coverage detected