|
@@ -178,19 +178,22 @@ const removeMessage = async (req, res, next) => {
|
|
|
{ owner: userMessage.companionId, companionId: userId },
|
|
|
{}
|
|
|
);
|
|
|
+ const seenCalculate = (seen, total) => {
|
|
|
+ if (seen <= total) {
|
|
|
+ return seen;
|
|
|
+ } else {
|
|
|
+ return total;
|
|
|
+ }
|
|
|
+ };
|
|
|
await ChatModel.update(isChat._id, userId, {
|
|
|
total: total,
|
|
|
- seen: total - isChat.seen > 0 ? isChat.seen : total,
|
|
|
- seenCompanion:
|
|
|
- total - isChat.seenCompanion > 0 ? isChat.seenCompanion : total,
|
|
|
+ seen: seenCalculate(isChat.seen, total),
|
|
|
+ seenCompanion: seenCalculate(isChat.seenCompanion, total),
|
|
|
});
|
|
|
await ChatModel.update(isCompanionChat._id, userMessage.companionId, {
|
|
|
total: Total,
|
|
|
- seen: Total - isCompanionChat.seen > 0 ? isCompanionChat.seen : Total,
|
|
|
- seenCompanion:
|
|
|
- total - isCompanionChat.seenCompanion > 0
|
|
|
- ? isCompanionChat.seenCompanion
|
|
|
- : total,
|
|
|
+ seen: seenCalculate(isCompanionChat.seen, Total),
|
|
|
+ seenCompanion: seenCalculate(isCompanionChat.seenCompanion, Total),
|
|
|
});
|
|
|
return res.json({
|
|
|
status: 'success',
|
|
@@ -206,7 +209,6 @@ const removeSelected = async (req, res, next) => {
|
|
|
try {
|
|
|
const userId = req.user.id;
|
|
|
const { selectedArr, companionId } = req.body;
|
|
|
- const totalDeleted = selectedArr.length;
|
|
|
const toDeleteMessage = async (id) => {
|
|
|
const userMessage = await MessageModel.remove(id, userId);
|
|
|
await MessageModel.findByFieldsAndUpdateMany(companionId, id, userId, {
|
|
@@ -255,19 +257,26 @@ const removeSelected = async (req, res, next) => {
|
|
|
{ owner: userId, companionId },
|
|
|
{}
|
|
|
);
|
|
|
+ const { total: Total } = await MessageModel.getList(
|
|
|
+ { owner: companionId, companionId: userId },
|
|
|
+ {}
|
|
|
+ );
|
|
|
+ const seenCalculate = (seen, total) => {
|
|
|
+ if (seen <= total) {
|
|
|
+ return seen;
|
|
|
+ } else {
|
|
|
+ return total;
|
|
|
+ }
|
|
|
+ };
|
|
|
await ChatModel.update(isChat._id, userId, {
|
|
|
total: total,
|
|
|
- seen: total - isChat.seen > 0 ? total - isChat.seen : 0,
|
|
|
- seenCompanion:
|
|
|
- total - isChat.seenCompanion > 0 ? total - isChat.seenCompanion : 0,
|
|
|
+ seen: seenCalculate(isChat.seen, total),
|
|
|
+ seenCompanion: seenCalculate(isChat.seenCompanion, total),
|
|
|
});
|
|
|
await ChatModel.update(isCompanionChat._id, companionId, {
|
|
|
- total: total,
|
|
|
- seen: total - isCompanionChat.seen > 0 ? total - isCompanionChat.seen : 0,
|
|
|
- seenCompanion:
|
|
|
- total - isCompanionChat.seenCompanion > 0
|
|
|
- ? total - isCompanionChat.seenCompanion
|
|
|
- : 0,
|
|
|
+ total: Total,
|
|
|
+ seen: seenCalculate(isCompanionChat.seen, Total),
|
|
|
+ seenCompanion: seenCalculate(isCompanionChat.seenCompanion, Total),
|
|
|
});
|
|
|
return res.json({
|
|
|
status: 'success',
|
|
@@ -485,8 +494,12 @@ const sentMessageForward = async (req, res, next) => {
|
|
|
number: user.number,
|
|
|
type: 'text',
|
|
|
fullType: userMessage.fullType,
|
|
|
- forwardName: userMessage.name,
|
|
|
- forwardLastName: userMessage.lastName,
|
|
|
+ forwardName:
|
|
|
+ user.number === userMessage.number ? user.name : isCompanionUser.name,
|
|
|
+ forwardLastName:
|
|
|
+ user.number === userMessage.number
|
|
|
+ ? user.lastName
|
|
|
+ : isCompanionUser.lastName,
|
|
|
oldId: userMessage._id,
|
|
|
idTime,
|
|
|
companionIdFlow: userId,
|
|
@@ -506,12 +519,12 @@ const sentMessageForward = async (req, res, next) => {
|
|
|
number: user.number,
|
|
|
type: 'text',
|
|
|
fullType: userMessage.fullType,
|
|
|
- forwardName: isForwardHasChatWithCompanion
|
|
|
- ? isForwardHasChatWithCompanion.name
|
|
|
- : isCompanionUser.name,
|
|
|
- forwardLastName: isForwardHasChatWithCompanion
|
|
|
- ? isForwardHasChatWithCompanion.lastName
|
|
|
- : isCompanionUser.lastName,
|
|
|
+ forwardName:
|
|
|
+ user.number === userMessage.number ? user.name : isCompanionUser.name,
|
|
|
+ forwardLastName:
|
|
|
+ user.number === userMessage.number
|
|
|
+ ? user.lastName
|
|
|
+ : isCompanionUser.lastName,
|
|
|
oldId: companionMessage._id,
|
|
|
idTime,
|
|
|
companionIdFlow: userId,
|