|
@@ -440,7 +440,7 @@ const sentMessageReply = async (req, res, next) => {
|
|
|
|
|
|
const sentMessageForward = async (req, res, next) => {
|
|
|
try {
|
|
|
- const { id, companionIdForwardToAndFrom } = req.body;
|
|
|
+ const { id, companionIdForwardToAndFrom, message, caption } = req.body;
|
|
|
const idTime = Math.round(Date.now() / 1000);
|
|
|
const user = req.user;
|
|
|
const userId = user.id;
|
|
@@ -449,6 +449,11 @@ const sentMessageForward = async (req, res, next) => {
|
|
|
companionIdForwardToAndFrom,
|
|
|
userId
|
|
|
);
|
|
|
+ const companionMessage = await MessageModel.findByFields(
|
|
|
+ userId,
|
|
|
+ userMessage.idTime,
|
|
|
+ userMessage.companionId
|
|
|
+ );
|
|
|
const isCompanionUser = await UserModel.findById(userMessage.companionId);
|
|
|
const isForwardHasChatWithCompanion = await ChatModel.getByField(
|
|
|
userMessage.companionId,
|
|
@@ -458,10 +463,18 @@ const sentMessageForward = async (req, res, next) => {
|
|
|
userId,
|
|
|
companionIdForwardToAndFrom
|
|
|
);
|
|
|
- if (userMessage && isCompanionUser && isChat && isForwardChat) {
|
|
|
+ if (
|
|
|
+ userMessage &&
|
|
|
+ isCompanionUser &&
|
|
|
+ isChat &&
|
|
|
+ isForwardChat &&
|
|
|
+ companionMessage
|
|
|
+ ) {
|
|
|
const newMessage = await MessageModel.add({
|
|
|
- message: userMessage.message,
|
|
|
- caption: userMessage.caption,
|
|
|
+ message,
|
|
|
+ caption,
|
|
|
+ forwardMessage: userMessage.message,
|
|
|
+ forwardCaption: userMessage.caption,
|
|
|
name: user.name,
|
|
|
lastName: user.lastName,
|
|
|
avatarUrl: user.avatarUrl,
|
|
@@ -471,6 +484,7 @@ const sentMessageForward = async (req, res, next) => {
|
|
|
fullType: userMessage.fullType,
|
|
|
forwardName: userMessage.name,
|
|
|
forwardLastName: userMessage.lastName,
|
|
|
+ oldId: userMessage._id,
|
|
|
idTime,
|
|
|
companionIdFlow: userId,
|
|
|
companionIdForwardToAndFrom: userMessage.companionId,
|
|
@@ -478,8 +492,10 @@ const sentMessageForward = async (req, res, next) => {
|
|
|
owner: userId,
|
|
|
});
|
|
|
await MessageModel.add({
|
|
|
- message: userMessage.message,
|
|
|
- caption: userMessage.caption,
|
|
|
+ message,
|
|
|
+ caption,
|
|
|
+ forwardMessage: userMessage.message,
|
|
|
+ forwardCaption: userMessage.caption,
|
|
|
name: isForwardChat.name,
|
|
|
lastName: isForwardChat.lastName,
|
|
|
avatarUrl: user.avatarUrl,
|
|
@@ -493,6 +509,7 @@ const sentMessageForward = async (req, res, next) => {
|
|
|
forwardLastName: isForwardHasChatWithCompanion
|
|
|
? isForwardHasChatWithCompanion.lastName
|
|
|
: isCompanionUser.lastName,
|
|
|
+ oldId: companionMessage._id,
|
|
|
idTime,
|
|
|
companionIdFlow: userId,
|
|
|
companionId: userId,
|
|
@@ -507,7 +524,7 @@ const sentMessageForward = async (req, res, next) => {
|
|
|
total,
|
|
|
seen: total,
|
|
|
watched: false,
|
|
|
- lastMessage: userMessage.message,
|
|
|
+ lastMessage: message,
|
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
|
});
|
|
|
const { total: Total } = await MessageModel.getList(
|
|
@@ -516,7 +533,7 @@ const sentMessageForward = async (req, res, next) => {
|
|
|
);
|
|
|
await ChatModel.update(isForwardChat._id, companionIdForwardToAndFrom, {
|
|
|
total: Total,
|
|
|
- lastMessage: userMessage.message,
|
|
|
+ lastMessage: message,
|
|
|
lastMessageCreatedAt: newMessage.createdAt,
|
|
|
});
|
|
|
return res.status(201).json({
|