feature/IO-3000-messaging-sockets-migrations2 -
- A lot of a lot of testing.... Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -58,48 +58,49 @@ exports.status = async (req, res) => {
|
||||
logger.log("sms-status-update-error", "ERROR", "api", null, {
|
||||
msid: SmsSid,
|
||||
fields: { status: SmsStatus },
|
||||
error
|
||||
stack: error.stack,
|
||||
message: error.message
|
||||
});
|
||||
res.status(500).json({ error: "Failed to update message status." });
|
||||
}
|
||||
};
|
||||
|
||||
exports.markConversationRead = async (req, res) => {
|
||||
const { conversationid, imexshopid, bodyshopid } = req.body;
|
||||
const {
|
||||
ioRedis,
|
||||
ioHelpers: { getBodyshopRoom, getBodyshopConversationRoom }
|
||||
} = req;
|
||||
const { conversation, imexshopid, bodyshopid } = req.body;
|
||||
|
||||
// Alternatively, support both payload formats
|
||||
const conversationId = conversation?.id || req.body.conversationId;
|
||||
|
||||
if (!conversationId || !imexshopid || !bodyshopid) {
|
||||
return res.status(400).json({ error: "Invalid conversation data provided." });
|
||||
}
|
||||
|
||||
try {
|
||||
// Mark messages in the conversation as read
|
||||
const response = await client.request(queries.MARK_MESSAGES_AS_READ, {
|
||||
conversationId: conversationid
|
||||
conversationId
|
||||
});
|
||||
|
||||
const updatedMessages = response.update_messages.affected_rows;
|
||||
|
||||
logger.log("conversation-mark-read", "DEBUG", "api", null, {
|
||||
conversationid,
|
||||
imexshopid,
|
||||
bodyshopid,
|
||||
updatedMessages
|
||||
});
|
||||
const updatedMessageIds = response.update_messages.returning.map((message) => message.id);
|
||||
|
||||
const broadcastRoom = getBodyshopRoom(bodyshopid);
|
||||
|
||||
ioRedis.to(broadcastRoom).emit("conversation-changed", {
|
||||
type: "conversation-marked-read",
|
||||
conversationId: conversationid
|
||||
conversationId,
|
||||
affectedMessages: response.update_messages.affected_rows,
|
||||
messageIds: updatedMessageIds
|
||||
});
|
||||
|
||||
res.status(200).json({ success: true, message: "Conversation marked as read." });
|
||||
} catch (error) {
|
||||
logger.log("conversation-mark-read-error", "ERROR", "api", null, {
|
||||
conversationid,
|
||||
imexshopid,
|
||||
error
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: "Conversation marked as read."
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error marking conversation as read:", error);
|
||||
res.status(500).json({ error: "Failed to mark conversation as read." });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user