|
@@ -30,7 +30,7 @@ const removeMessage = async (req, res, next) => {
|
|
const DIR_VIDEOS = process.env.DIR_VIDEOS;
|
|
const DIR_VIDEOS = process.env.DIR_VIDEOS;
|
|
const DIR_FILES = process.env.DIR_FILES;
|
|
const DIR_FILES = process.env.DIR_FILES;
|
|
const userMessage = await MessageModel.remove(id, userId);
|
|
const userMessage = await MessageModel.remove(id, userId);
|
|
- const companionMessage = await MessageModel.removeByFields(
|
|
|
|
|
|
+ await MessageModel.removeByFields(
|
|
userId,
|
|
userId,
|
|
userMessage.idTime,
|
|
userMessage.idTime,
|
|
userMessage.companionId
|
|
userMessage.companionId
|
|
@@ -51,19 +51,34 @@ const removeMessage = async (req, res, next) => {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (userMessage && companionMessage) {
|
|
|
|
- return res.json({
|
|
|
|
- status: 'success',
|
|
|
|
- code: 200,
|
|
|
|
- data: {},
|
|
|
|
- });
|
|
|
|
- } else {
|
|
|
|
- return res.status(404).json({
|
|
|
|
- status: 'error',
|
|
|
|
- code: 404,
|
|
|
|
- data: 'Not Found',
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
|
|
+ const isChat = await ChatModel.getByField(userMessage.companionId, userId);
|
|
|
|
+ const isCompanionChat = await ChatModel.getByField(
|
|
|
|
+ userId,
|
|
|
|
+ userMessage.companionId
|
|
|
|
+ );
|
|
|
|
+ const { total } = await MessageModel.getList(
|
|
|
|
+ { owner: userId, companionId: userMessage.companionId },
|
|
|
|
+ {}
|
|
|
|
+ );
|
|
|
|
+ const { total: Total } = await MessageModel.getList(
|
|
|
|
+ { owner: userMessage.companionId, companionId: userId },
|
|
|
|
+ {}
|
|
|
|
+ );
|
|
|
|
+ await ChatModel.update(isChat._id, userId, {
|
|
|
|
+ total: total,
|
|
|
|
+ seen: total - isChat.seen > 0 ? isChat.seen : total,
|
|
|
|
+ watched: false,
|
|
|
|
+ });
|
|
|
|
+ await ChatModel.update(isCompanionChat._id, userMessage.companionId, {
|
|
|
|
+ total: Total,
|
|
|
|
+ seen: Total - isCompanionChat.seen > 0 ? isCompanionChat.seen : Total,
|
|
|
|
+ watched: true,
|
|
|
|
+ });
|
|
|
|
+ return res.json({
|
|
|
|
+ status: 'success',
|
|
|
|
+ code: 200,
|
|
|
|
+ data: {},
|
|
|
|
+ });
|
|
} catch (e) {
|
|
} catch (e) {
|
|
next(e);
|
|
next(e);
|
|
}
|
|
}
|