|
@@ -464,7 +464,7 @@ const sentMessage = async (req, res, next) => {
|
|
|
|
|
|
const callMessage = async (req, res, next) => {
|
|
const callMessage = async (req, res, next) => {
|
|
try {
|
|
try {
|
|
- const { id, reject, duration } = req.body;
|
|
|
|
|
|
+ const { id, duration } = 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;
|
|
@@ -475,7 +475,6 @@ const callMessage = async (req, res, next) => {
|
|
if (companion && isChat && isCompanionChat) {
|
|
if (companion && isChat && isCompanionChat) {
|
|
const newMessage = await MessageModel.add({
|
|
const newMessage = await MessageModel.add({
|
|
initiator: true,
|
|
initiator: true,
|
|
- reject,
|
|
|
|
duration,
|
|
duration,
|
|
message: 'Outgoing Call',
|
|
message: 'Outgoing Call',
|
|
name,
|
|
name,
|
|
@@ -490,7 +489,6 @@ const callMessage = async (req, res, next) => {
|
|
owner: userId,
|
|
owner: userId,
|
|
});
|
|
});
|
|
await MessageModel.add({
|
|
await MessageModel.add({
|
|
- reject,
|
|
|
|
duration,
|
|
duration,
|
|
message: 'Incoming Call',
|
|
message: 'Incoming Call',
|
|
name: isCompanionChat.name,
|
|
name: isCompanionChat.name,
|
|
@@ -536,6 +534,47 @@ const callMessage = async (req, res, next) => {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+const updateMessageCall = async (req, res, next) => {
|
|
|
|
+ try {
|
|
|
|
+ const { id, duration } = req.body;
|
|
|
|
+ const userId = req.user.id;
|
|
|
|
+ const userMessage = await MessageModel.getById(id, userId);
|
|
|
|
+ const isChat = await ChatModel.getByField(userMessage.companionId, userId);
|
|
|
|
+ const isCompanionChat = await ChatModel.getByField(
|
|
|
|
+ userId,
|
|
|
|
+ userMessage.companionId
|
|
|
|
+ );
|
|
|
|
+ const messageOne = duration ? 'Outgoing Call' : 'Canceled Call';
|
|
|
|
+ const messageTwo = duration ? 'Incoming Call' : 'Missed Call';
|
|
|
|
+ await MessageModel.updateMessage(id, userId, {
|
|
|
|
+ message: messageOne,
|
|
|
|
+ duration,
|
|
|
|
+ });
|
|
|
|
+ await MessageModel.findByFieldsAndUpdate(
|
|
|
|
+ userId,
|
|
|
|
+ userMessage.idTime,
|
|
|
|
+ userMessage.companionId,
|
|
|
|
+ {
|
|
|
|
+ message: messageTwo,
|
|
|
|
+ duration,
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+ await ChatModel.update(isChat._id, userId, {
|
|
|
|
+ lastMessage: messageOne,
|
|
|
|
+ });
|
|
|
|
+ await ChatModel.update(isCompanionChat._id, userMessage.companionId, {
|
|
|
|
+ lastMessage: messageTwo,
|
|
|
|
+ });
|
|
|
|
+ return res.status(200).json({
|
|
|
|
+ status: 'success',
|
|
|
|
+ code: 200,
|
|
|
|
+ data: {},
|
|
|
|
+ });
|
|
|
|
+ } catch (e) {
|
|
|
|
+ next(e);
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+
|
|
const sentMessageReply = async (req, res, next) => {
|
|
const sentMessageReply = async (req, res, next) => {
|
|
try {
|
|
try {
|
|
const { id, message, caption } = req.body;
|
|
const { id, message, caption } = req.body;
|
|
@@ -1107,6 +1146,7 @@ module.exports = {
|
|
listMessagesById,
|
|
listMessagesById,
|
|
sentMessage,
|
|
sentMessage,
|
|
callMessage,
|
|
callMessage,
|
|
|
|
+ updateMessageCall,
|
|
sentMessageReply,
|
|
sentMessageReply,
|
|
sentMessageForward,
|
|
sentMessageForward,
|
|
imageMessage,
|
|
imageMessage,
|