|
@@ -122,14 +122,22 @@ const removeMessage = async (req, res, next) => {
|
|
const userId = req.user.id;
|
|
const userId = req.user.id;
|
|
const userMessage = await MessageModel.remove(id, userId);
|
|
const userMessage = await MessageModel.remove(id, userId);
|
|
await MessageModel.findByFieldsAndUpdateMany(
|
|
await MessageModel.findByFieldsAndUpdateMany(
|
|
- userMessage.companionId,
|
|
|
|
- id,
|
|
|
|
- userId,
|
|
|
|
{
|
|
{
|
|
|
|
+ oldId: userMessage._id,
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ deleted: true,
|
|
replyMessage: null,
|
|
replyMessage: null,
|
|
replyName: null,
|
|
replyName: null,
|
|
replyLastName: null,
|
|
replyLastName: null,
|
|
replyCaption: null,
|
|
replyCaption: null,
|
|
|
|
+ forwardMessage: null,
|
|
|
|
+ forwardMessage: null,
|
|
|
|
+ forwardName: null,
|
|
|
|
+ forwardLastName: null,
|
|
|
|
+ forwardCaption: null,
|
|
|
|
+ fullType: null,
|
|
|
|
+ companionIdForwardToAndFrom: null,
|
|
oldId: null,
|
|
oldId: null,
|
|
}
|
|
}
|
|
);
|
|
);
|
|
@@ -138,23 +146,32 @@ const removeMessage = async (req, res, next) => {
|
|
userMessage.idTime,
|
|
userMessage.idTime,
|
|
userMessage.companionId
|
|
userMessage.companionId
|
|
);
|
|
);
|
|
- await MessageModel.removeByFields(
|
|
|
|
- userId,
|
|
|
|
- userMessage.idTime,
|
|
|
|
- userMessage.companionId
|
|
|
|
- );
|
|
|
|
await MessageModel.findByFieldsAndUpdateMany(
|
|
await MessageModel.findByFieldsAndUpdateMany(
|
|
- userId,
|
|
|
|
- companionMessage._id,
|
|
|
|
- userMessage.companionId,
|
|
|
|
{
|
|
{
|
|
|
|
+ oldId: companionMessage._id,
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ deleted: true,
|
|
replyMessage: null,
|
|
replyMessage: null,
|
|
replyName: null,
|
|
replyName: null,
|
|
replyLastName: null,
|
|
replyLastName: null,
|
|
replyCaption: null,
|
|
replyCaption: null,
|
|
|
|
+ forwardMessage: null,
|
|
|
|
+ forwardMessage: null,
|
|
|
|
+ forwardName: null,
|
|
|
|
+ forwardLastName: null,
|
|
|
|
+ forwardCaption: null,
|
|
|
|
+ fullType: null,
|
|
|
|
+ companionIdForwardToAndFrom: null,
|
|
oldId: null,
|
|
oldId: null,
|
|
}
|
|
}
|
|
);
|
|
);
|
|
|
|
+ await MessageModel.removeByFields(
|
|
|
|
+ userId,
|
|
|
|
+ userMessage.idTime,
|
|
|
|
+ userMessage.companionId
|
|
|
|
+ );
|
|
|
|
+
|
|
if (userMessage.type !== 'text') {
|
|
if (userMessage.type !== 'text') {
|
|
const params = {
|
|
const params = {
|
|
Bucket: AWS_BUCKET_NAME,
|
|
Bucket: AWS_BUCKET_NAME,
|
|
@@ -224,27 +241,48 @@ const removeSelected = async (req, res, next) => {
|
|
const { selectedArr, companionId } = req.body;
|
|
const { selectedArr, companionId } = req.body;
|
|
const toDeleteMessage = async (id) => {
|
|
const toDeleteMessage = async (id) => {
|
|
const userMessage = await MessageModel.remove(id, userId);
|
|
const userMessage = await MessageModel.remove(id, userId);
|
|
- await MessageModel.findByFieldsAndUpdateMany(companionId, id, userId, {
|
|
|
|
- replyMessage: null,
|
|
|
|
- replyName: null,
|
|
|
|
- replyLastName: null,
|
|
|
|
- replyCaption: null,
|
|
|
|
- oldId: null,
|
|
|
|
- });
|
|
|
|
|
|
+ await MessageModel.findByFieldsAndUpdateMany(
|
|
|
|
+ {
|
|
|
|
+ oldId: userMessage._id,
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ deleted: true,
|
|
|
|
+ replyMessage: null,
|
|
|
|
+ replyName: null,
|
|
|
|
+ replyLastName: null,
|
|
|
|
+ replyCaption: null,
|
|
|
|
+ forwardMessage: null,
|
|
|
|
+ forwardMessage: null,
|
|
|
|
+ forwardName: null,
|
|
|
|
+ forwardLastName: null,
|
|
|
|
+ forwardCaption: null,
|
|
|
|
+ fullType: null,
|
|
|
|
+ companionIdForwardToAndFrom: null,
|
|
|
|
+ oldId: null,
|
|
|
|
+ }
|
|
|
|
+ );
|
|
const companionMessage = await MessageModel.findByFields(
|
|
const companionMessage = await MessageModel.findByFields(
|
|
userId,
|
|
userId,
|
|
userMessage.idTime,
|
|
userMessage.idTime,
|
|
companionId
|
|
companionId
|
|
);
|
|
);
|
|
await MessageModel.findByFieldsAndUpdateMany(
|
|
await MessageModel.findByFieldsAndUpdateMany(
|
|
- userId,
|
|
|
|
- companionMessage._id,
|
|
|
|
- companionId,
|
|
|
|
{
|
|
{
|
|
|
|
+ oldId: companionMessage._id,
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ deleted: true,
|
|
replyMessage: null,
|
|
replyMessage: null,
|
|
replyName: null,
|
|
replyName: null,
|
|
replyLastName: null,
|
|
replyLastName: null,
|
|
replyCaption: null,
|
|
replyCaption: null,
|
|
|
|
+ forwardMessage: null,
|
|
|
|
+ forwardMessage: null,
|
|
|
|
+ forwardName: null,
|
|
|
|
+ forwardLastName: null,
|
|
|
|
+ forwardCaption: null,
|
|
|
|
+ fullType: null,
|
|
|
|
+ companionIdForwardToAndFrom: null,
|
|
oldId: null,
|
|
oldId: null,
|
|
}
|
|
}
|
|
);
|
|
);
|
|
@@ -493,10 +531,6 @@ const sentMessageForward = async (req, res, next) => {
|
|
userMessage.companionId
|
|
userMessage.companionId
|
|
);
|
|
);
|
|
const isCompanionUser = await UserModel.findById(userMessage.companionId);
|
|
const isCompanionUser = await UserModel.findById(userMessage.companionId);
|
|
- const isForwardHasChatWithCompanion = await ChatModel.getByField(
|
|
|
|
- userMessage.companionId,
|
|
|
|
- companionIdForwardToAndFrom
|
|
|
|
- );
|
|
|
|
const isForwardChat = await ChatModel.getByField(
|
|
const isForwardChat = await ChatModel.getByField(
|
|
userId,
|
|
userId,
|
|
companionIdForwardToAndFrom
|
|
companionIdForwardToAndFrom
|
|
@@ -652,7 +686,7 @@ const imageMessage = async (req, res, next) => {
|
|
total,
|
|
total,
|
|
seen: total,
|
|
seen: total,
|
|
watched: false,
|
|
watched: false,
|
|
- lastMessage: imgUrl,
|
|
|
|
|
|
+ lastMessage: fullType,
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
});
|
|
});
|
|
const { total: Total } = await MessageModel.getList(
|
|
const { total: Total } = await MessageModel.getList(
|
|
@@ -662,7 +696,7 @@ const imageMessage = async (req, res, next) => {
|
|
await ChatModel.update(isCompanionChat._id, id, {
|
|
await ChatModel.update(isCompanionChat._id, id, {
|
|
total: Total,
|
|
total: Total,
|
|
seenCompanion: Total,
|
|
seenCompanion: Total,
|
|
- lastMessage: imgUrl,
|
|
|
|
|
|
+ lastMessage: fullType,
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
});
|
|
});
|
|
return res.status(201).json({
|
|
return res.status(201).json({
|
|
@@ -739,7 +773,7 @@ const audioMessage = async (req, res, next) => {
|
|
total,
|
|
total,
|
|
seen: total,
|
|
seen: total,
|
|
watched: false,
|
|
watched: false,
|
|
- lastMessage: audioUrl,
|
|
|
|
|
|
+ lastMessage: fullType,
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
});
|
|
});
|
|
const { total: Total } = await MessageModel.getList(
|
|
const { total: Total } = await MessageModel.getList(
|
|
@@ -749,7 +783,7 @@ const audioMessage = async (req, res, next) => {
|
|
await ChatModel.update(isCompanionChat._id, id, {
|
|
await ChatModel.update(isCompanionChat._id, id, {
|
|
total: Total,
|
|
total: Total,
|
|
seenCompanion: Total,
|
|
seenCompanion: Total,
|
|
- lastMessage: audioUrl,
|
|
|
|
|
|
+ lastMessage: fullType,
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
});
|
|
});
|
|
return res.status(201).json({
|
|
return res.status(201).json({
|
|
@@ -826,7 +860,7 @@ const videoMessage = async (req, res, next) => {
|
|
total,
|
|
total,
|
|
seen: total,
|
|
seen: total,
|
|
watched: false,
|
|
watched: false,
|
|
- lastMessage: videoUrl,
|
|
|
|
|
|
+ lastMessage: fullType,
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
});
|
|
});
|
|
const { total: Total } = await MessageModel.getList(
|
|
const { total: Total } = await MessageModel.getList(
|
|
@@ -836,7 +870,7 @@ const videoMessage = async (req, res, next) => {
|
|
await ChatModel.update(isCompanionChat._id, id, {
|
|
await ChatModel.update(isCompanionChat._id, id, {
|
|
total: Total,
|
|
total: Total,
|
|
seenCompanion: Total,
|
|
seenCompanion: Total,
|
|
- lastMessage: videoUrl,
|
|
|
|
|
|
+ lastMessage: fullType,
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
});
|
|
});
|
|
return res.status(201).json({
|
|
return res.status(201).json({
|
|
@@ -926,7 +960,7 @@ const fileMessage = async (req, res, next) => {
|
|
total,
|
|
total,
|
|
seen: total,
|
|
seen: total,
|
|
watched: false,
|
|
watched: false,
|
|
- lastMessage: fileUrl,
|
|
|
|
|
|
+ lastMessage: fullType,
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
});
|
|
});
|
|
const { total: Total } = await MessageModel.getList(
|
|
const { total: Total } = await MessageModel.getList(
|
|
@@ -936,7 +970,7 @@ const fileMessage = async (req, res, next) => {
|
|
await ChatModel.update(isCompanionChat._id, id, {
|
|
await ChatModel.update(isCompanionChat._id, id, {
|
|
total: Total,
|
|
total: Total,
|
|
seenCompanion: Total,
|
|
seenCompanion: Total,
|
|
- lastMessage: fileUrl,
|
|
|
|
|
|
+ lastMessage: fullType,
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
});
|
|
});
|
|
return res.status(201).json({
|
|
return res.status(201).json({
|