Spaces:
Running
Running
Download utils/dialog.js from 4send/messenger: direct link, hf CLI and curl.
- Browser
- Download file 2.15 kB
-
https://huggingface.co/spaces/4send/messenger/resolve/main/utils/dialog.js
- Command line
-
hf download hf://spaces/4send/messenger/utils/dialog.js
-
curl -L -o dialog.js https://huggingface.co/spaces/4send/messenger/resolve/main/utils/dialog.js
2.15 kB
| const Message = require('../models/Message'); | |
| const Dialog = require('../models/Dialog'); | |
| const getDialogId = (u1, u2) => [String(u1).toLowerCase(), String(u2).toLowerCase()].sort().join('_'); | |
| const updateDialogLastMessage = async (dialogId) => { | |
| try { | |
| const lastMsg = await Message.findOne({ dialog_id: dialogId, isService: { $ne: true } }).sort({ timestamp: -1 }).lean(); | |
| if (lastMsg) { | |
| await Dialog.updateOne( | |
| { dialog_id: dialogId }, | |
| { | |
| $set: { | |
| lastMessageText: lastMsg.is_encrypted ? '🔒' : lastMsg.text, | |
| lastSender: lastMsg.sender, | |
| lastMessageTimestamp: lastMsg.timestamp, | |
| lastIsAudio: lastMsg.isAudio || false, | |
| lastIsMusic: lastMsg.isMusic || false, | |
| lastIsVideoNote: lastMsg.isVideoNote || false, | |
| lastIsEncrypted: lastMsg.is_encrypted || false, | |
| lastFileUrl: lastMsg.fileUrls && lastMsg.fileUrls.length > 0 ? lastMsg.fileUrls[0] : (lastMsg.fileUrl || null), | |
| lastFileName: lastMsg.fileName || null | |
| }, | |
| $unset: { lastCallType: '', lastCallDuration: '', lastCallWithVideo: '' } | |
| } | |
| ); | |
| } else { | |
| await Dialog.updateOne( | |
| { dialog_id: dialogId }, | |
| { | |
| $set: { | |
| lastMessageText: '', | |
| lastSender: null, | |
| lastMessageTimestamp: new Date(0), | |
| lastIsAudio: false, | |
| lastIsMusic: false, | |
| lastIsVideoNote: false, | |
| lastIsEncrypted: false, | |
| lastFileUrl: null, | |
| lastFileName: null | |
| }, | |
| $unset: { lastCallType: '', lastCallDuration: '', lastCallWithVideo: '' } | |
| } | |
| ); | |
| } | |
| } catch {} | |
| }; | |
| module.exports = { getDialogId, updateDialogLastMessage }; | |