|
@@ -462,6 +462,80 @@ const sentMessage = async (req, res, next) => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+const callMessage = async (req, res, next) => {
|
|
|
+ try {
|
|
|
+ const { id, reject, duration } = req.body;
|
|
|
+ const idTime = Math.round(Date.now() / 1000);
|
|
|
+ const user = req.user;
|
|
|
+ const userId = user.id;
|
|
|
+ const companion = await UserModel.findById(id);
|
|
|
+ const isChat = await ChatModel.getByField(id, userId);
|
|
|
+ const isCompanionChat = await ChatModel.getByField(userId, id);
|
|
|
+ const { name, lastName, avatarUrl, color, number } = user;
|
|
|
+ if (companion && isChat && isCompanionChat) {
|
|
|
+ const newMessage = await MessageModel.add({
|
|
|
+ initiator: true,
|
|
|
+ reject,
|
|
|
+ duration,
|
|
|
+ message: 'Outgoing Call',
|
|
|
+ name,
|
|
|
+ lastName,
|
|
|
+ avatarUrl,
|
|
|
+ color,
|
|
|
+ number,
|
|
|
+ type: 'text',
|
|
|
+ idTime,
|
|
|
+ companionIdFlow: userId,
|
|
|
+ companionId: id,
|
|
|
+ owner: userId,
|
|
|
+ });
|
|
|
+ await MessageModel.add({
|
|
|
+ reject,
|
|
|
+ duration,
|
|
|
+ message: 'Incoming Call',
|
|
|
+ name: isCompanionChat.name,
|
|
|
+ lastName: isCompanionChat.lastName,
|
|
|
+ avatarUrl,
|
|
|
+ color,
|
|
|
+ number,
|
|
|
+ type: 'text',
|
|
|
+ idTime,
|
|
|
+ companionIdFlow: userId,
|
|
|
+ companionId: userId,
|
|
|
+ owner: id,
|
|
|
+ });
|
|
|
+ const { total } = await MessageModel.getList(
|
|
|
+ { owner: userId, companionId: id },
|
|
|
+ {}
|
|
|
+ );
|
|
|
+ await ChatModel.update(isChat._id, userId, {
|
|
|
+ total,
|
|
|
+ seen: total,
|
|
|
+ watched: false,
|
|
|
+ lastMessage: 'Outgoing Call',
|
|
|
+ lastMessageCreatedAt: newMessage.createdAt,
|
|
|
+ });
|
|
|
+ const { total: Total } = await MessageModel.getList(
|
|
|
+ { owner: id, companionId: userId },
|
|
|
+ {}
|
|
|
+ );
|
|
|
+ await ChatModel.update(isCompanionChat._id, id, {
|
|
|
+ total: Total,
|
|
|
+ seenCompanion: Total,
|
|
|
+ lastMessage: 'Incoming Call',
|
|
|
+ lastMessageCreatedAt: newMessage.createdAt,
|
|
|
+ });
|
|
|
+ return res.status(201).json({
|
|
|
+ status: 'success',
|
|
|
+ code: 201,
|
|
|
+ data: newMessage,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ next(e);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
const sentMessageReply = async (req, res, next) => {
|
|
|
try {
|
|
|
const { id, message, caption } = req.body;
|
|
@@ -1032,6 +1106,7 @@ module.exports = {
|
|
|
unpinAllMessage,
|
|
|
listMessagesById,
|
|
|
sentMessage,
|
|
|
+ callMessage,
|
|
|
sentMessageReply,
|
|
|
sentMessageForward,
|
|
|
imageMessage,
|