|
@@ -181,12 +181,16 @@ const removeMessage = async (req, res, next) => {
|
|
|
await ChatModel.update(isChat._id, userId, {
|
|
|
total: total,
|
|
|
seen: total - isChat.seen > 0 ? isChat.seen : total,
|
|
|
- watched: false,
|
|
|
+ seenCompanion:
|
|
|
+ total - isChat.seenCompanion > 0 ? isChat.seenCompanion : total,
|
|
|
});
|
|
|
await ChatModel.update(isCompanionChat._id, userMessage.companionId, {
|
|
|
total: Total,
|
|
|
seen: Total - isCompanionChat.seen > 0 ? isCompanionChat.seen : Total,
|
|
|
- watched: true,
|
|
|
+ seenCompanion:
|
|
|
+ total - isCompanionChat.seenCompanion > 0
|
|
|
+ ? isCompanionChat.seenCompanion
|
|
|
+ : total,
|
|
|
});
|
|
|
return res.json({
|
|
|
status: 'success',
|
|
@@ -251,22 +255,19 @@ const removeSelected = async (req, res, next) => {
|
|
|
{ owner: userId, companionId },
|
|
|
{}
|
|
|
);
|
|
|
- const { total: Total } = await MessageModel.getList(
|
|
|
- { owner: companionId, companionId: userId },
|
|
|
- {}
|
|
|
- );
|
|
|
await ChatModel.update(isChat._id, userId, {
|
|
|
total: total,
|
|
|
- seen: isChat.seen - totalDeleted > 0 ? isChat.seen - totalDeleted : 0,
|
|
|
- watched: false,
|
|
|
+ seen: total - isChat.seen > 0 ? total - isChat.seen : 0,
|
|
|
+ seenCompanion:
|
|
|
+ total - isChat.seenCompanion > 0 ? total - isChat.seenCompanion : 0,
|
|
|
});
|
|
|
await ChatModel.update(isCompanionChat._id, companionId, {
|
|
|
- total: Total,
|
|
|
- seen:
|
|
|
- isCompanionChat.seen - totalDeleted > 0
|
|
|
- ? isCompanionChat.seen - totalDeleted
|
|
|
+ total: total,
|
|
|
+ seen: total - isCompanionChat.seen > 0 ? total - isCompanionChat.seen : 0,
|
|
|
+ seenCompanion:
|
|
|
+ total - isCompanionChat.seenCompanion > 0
|
|
|
+ ? total - isCompanionChat.seenCompanion
|
|
|
: 0,
|
|
|
- watched: true,
|
|
|
});
|
|
|
return res.json({
|
|
|
status: 'success',
|
|
@@ -335,6 +336,7 @@ const sentMessage = async (req, res, next) => {
|
|
|
);
|
|
|
await ChatModel.update(isCompanionChat._id, id, {
|
|
|
total: Total,
|
|
|
+ seenCompanion: Total,
|
|
|
lastMessage: message,
|
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
|
});
|
|
@@ -424,6 +426,7 @@ const sentMessageReply = async (req, res, next) => {
|
|
|
);
|
|
|
await ChatModel.update(isCompanionChat._id, userMessage.companionId, {
|
|
|
total: Total,
|
|
|
+ seenCompanion: Total,
|
|
|
lastMessage: message,
|
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
|
});
|
|
@@ -533,6 +536,7 @@ const sentMessageForward = async (req, res, next) => {
|
|
|
);
|
|
|
await ChatModel.update(isForwardChat._id, companionIdForwardToAndFrom, {
|
|
|
total: Total,
|
|
|
+ seenCompanion: Total,
|
|
|
lastMessage: message,
|
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
|
});
|
|
@@ -618,6 +622,7 @@ const imageMessage = async (req, res, next) => {
|
|
|
);
|
|
|
await ChatModel.update(isCompanionChat._id, id, {
|
|
|
total: Total,
|
|
|
+ seenCompanion: Total,
|
|
|
lastMessage: imgUrl,
|
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
|
});
|
|
@@ -704,6 +709,7 @@ const audioMessage = async (req, res, next) => {
|
|
|
);
|
|
|
await ChatModel.update(isCompanionChat._id, id, {
|
|
|
total: Total,
|
|
|
+ seenCompanion: Total,
|
|
|
lastMessage: audioUrl,
|
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
|
});
|
|
@@ -790,6 +796,7 @@ const videoMessage = async (req, res, next) => {
|
|
|
);
|
|
|
await ChatModel.update(isCompanionChat._id, id, {
|
|
|
total: Total,
|
|
|
+ seenCompanion: Total,
|
|
|
lastMessage: videoUrl,
|
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
|
});
|
|
@@ -889,6 +896,7 @@ const fileMessage = async (req, res, next) => {
|
|
|
);
|
|
|
await ChatModel.update(isCompanionChat._id, id, {
|
|
|
total: Total,
|
|
|
+ seenCompanion: Total,
|
|
|
lastMessage: fileUrl,
|
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
|
});
|