|
@@ -438,6 +438,87 @@ const sentMessageReply = async (req, res, next) => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+const sentMessageForward = async (req, res, next) => {
|
|
|
+ try {
|
|
|
+ const { id, companionIdForwardToAndFrom } = req.body;
|
|
|
+ const idTime = Math.round(Date.now() / 1000);
|
|
|
+ const user = req.user;
|
|
|
+ const userId = user.id;
|
|
|
+ const userMessage = await MessageModel.getById(id, userId);
|
|
|
+ const isChat = await ChatModel.getByField(
|
|
|
+ companionIdForwardToAndFrom,
|
|
|
+ userId
|
|
|
+ );
|
|
|
+ const isForwardChat = await ChatModel.getByField(
|
|
|
+ userId,
|
|
|
+ companionIdForwardToAndFrom
|
|
|
+ );
|
|
|
+ if (userMessage && isChat && isForwardChat) {
|
|
|
+ const newMessage = await MessageModel.add({
|
|
|
+ message: userMessage.message,
|
|
|
+ name: user.name,
|
|
|
+ lastName: user.lastName,
|
|
|
+ avatarUrl: user.avatarUrl,
|
|
|
+ color: user.color,
|
|
|
+ number: user.number,
|
|
|
+ type: 'text',
|
|
|
+ fullType: userMessage.fullType,
|
|
|
+ forwardName: userMessage.name,
|
|
|
+ forwardLastName: userMessage.lastMessage,
|
|
|
+ idTime,
|
|
|
+ companionIdFlow: userId,
|
|
|
+ companionIdForwardToAndFrom: userMessage.companionId,
|
|
|
+ companionId: companionIdForwardToAndFrom,
|
|
|
+ owner: userId,
|
|
|
+ });
|
|
|
+ await MessageModel.add({
|
|
|
+ message: userMessage.message,
|
|
|
+ name: isForwardChat.name,
|
|
|
+ lastName: isForwardChat.lastName,
|
|
|
+ avatarUrl: user.avatarUrl,
|
|
|
+ color: user.color,
|
|
|
+ number: user.number,
|
|
|
+ type: 'text',
|
|
|
+ fullType: userMessage.fullType,
|
|
|
+ forwardName: userMessage.name,
|
|
|
+ forwardLastName: userMessage.lastMessage,
|
|
|
+ idTime,
|
|
|
+ companionIdFlow: userId,
|
|
|
+ companionId: userId,
|
|
|
+ companionIdForwardToAndFrom: userMessage.companionId,
|
|
|
+ owner: companionIdForwardToAndFrom,
|
|
|
+ });
|
|
|
+ const { total } = await MessageModel.getList(
|
|
|
+ { owner: userId, companionId: companionIdForwardToAndFrom },
|
|
|
+ {}
|
|
|
+ );
|
|
|
+ await ChatModel.update(isChat._id, userId, {
|
|
|
+ total,
|
|
|
+ seen: total,
|
|
|
+ watched: false,
|
|
|
+ lastMessage: userMessage.message,
|
|
|
+ lastMessageCreatedAt: newMessage.createdAt,
|
|
|
+ });
|
|
|
+ const { total: Total } = await MessageModel.getList(
|
|
|
+ { owner: companionIdForwardToAndFrom, companionId: userId },
|
|
|
+ {}
|
|
|
+ );
|
|
|
+ await ChatModel.update(isForwardChat._id, companionIdForwardToAndFrom, {
|
|
|
+ total: Total,
|
|
|
+ lastMessage: userMessage.message,
|
|
|
+ lastMessageCreatedAt: newMessage.createdAt,
|
|
|
+ });
|
|
|
+ return res.status(201).json({
|
|
|
+ status: 'success',
|
|
|
+ code: 201,
|
|
|
+ data: newMessage,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ next(e);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
const imageMessage = async (req, res, next) => {
|
|
|
try {
|
|
|
const userId = req.user.id;
|
|
@@ -804,6 +885,7 @@ module.exports = {
|
|
|
listMessagesById,
|
|
|
sentMessage,
|
|
|
sentMessageReply,
|
|
|
+ sentMessageForward,
|
|
|
imageMessage,
|
|
|
audioMessage,
|
|
|
videoMessage,
|