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