Browse Source

make forward

unknown 2 years ago
parent
commit
e5472f9991
1 changed files with 15 additions and 4 deletions
  1. 15 4
      controllers/messages.js

+ 15 - 4
controllers/messages.js

@@ -449,13 +449,19 @@ const sentMessageForward = async (req, res, next) => {
 			companionIdForwardToAndFrom,
 			userId
 		);
+		const isCompanionUser = await UserModel.findById(userMessage.companionId);
+		const isForwardHasChatWithCompanion = await ChatModel.getByField(
+			userMessage.companionId,
+			companionIdForwardToAndFrom
+		);
 		const isForwardChat = await ChatModel.getByField(
 			userId,
 			companionIdForwardToAndFrom
 		);
-		if (userMessage && isChat && isForwardChat) {
+		if (userMessage && isCompanionUser && isChat && isForwardChat) {
 			const newMessage = await MessageModel.add({
 				message: userMessage.message,
+				caption: userMessage.caption,
 				name: user.name,
 				lastName: user.lastName,
 				avatarUrl: user.avatarUrl,
@@ -464,7 +470,7 @@ const sentMessageForward = async (req, res, next) => {
 				type: 'text',
 				fullType: userMessage.fullType,
 				forwardName: userMessage.name,
-				forwardLastName: userMessage.lastMessage,
+				forwardLastName: userMessage.lastName,
 				idTime,
 				companionIdFlow: userId,
 				companionIdForwardToAndFrom: userMessage.companionId,
@@ -473,6 +479,7 @@ const sentMessageForward = async (req, res, next) => {
 			});
 			await MessageModel.add({
 				message: userMessage.message,
+				caption: userMessage.caption,
 				name: isForwardChat.name,
 				lastName: isForwardChat.lastName,
 				avatarUrl: user.avatarUrl,
@@ -480,8 +487,12 @@ const sentMessageForward = async (req, res, next) => {
 				number: user.number,
 				type: 'text',
 				fullType: userMessage.fullType,
-				forwardName: userMessage.name,
-				forwardLastName: userMessage.lastMessage,
+				forwardName: isForwardHasChatWithCompanion
+					? isForwardHasChatWithCompanion.name
+					: isCompanionUser.name,
+				forwardLastName: isForwardHasChatWithCompanion
+					? isForwardHasChatWithCompanion.lastName
+					: isCompanionUser.lastName,
 				idTime,
 				companionIdFlow: userId,
 				companionId: userId,