IO-3000 Adjusted first approach at messaging WS changes.

This commit is contained in:
Patrick Fic
2024-11-19 15:52:57 -08:00
parent 289a666b6d
commit 299a675a9c
22 changed files with 1952 additions and 2570 deletions

View File

@@ -11,6 +11,10 @@ const { admin } = require("../firebase/firebase-handler");
exports.status = (req, res) => {
const { SmsSid, SmsStatus } = req.body;
const {
ioRedis,
ioHelpers: { getBodyshopRoom, getBodyshopConversationRoom }
} = req;
client
.request(queries.UPDATE_MESSAGE_STATUS, {
msid: SmsSid,
@@ -21,6 +25,17 @@ exports.status = (req, res) => {
msid: SmsSid,
fields: { status: SmsStatus }
});
// TODO Verify
const message = response.update_messages.returning[0];
const conversationRoom = getBodyshopConversationRoom({
bodyshopId: message.conversation.bodyshopid,
conversationId: message.conversationid
});
ioRedis.to(conversationRoom).emit("message-changed", {
message
});
})
.catch((error) => {
logger.log("sms-status-update-error", "ERROR", "api", null, {
@@ -34,18 +49,44 @@ exports.status = (req, res) => {
exports.markConversationRead = async (req, res) => {
const { conversationid, imexshopid } = req.body;
admin.messaging().send({
topic: `${imexshopid}-messaging`,
// notification: {
// title: `ImEX Online Message - ${data.phone_num}`,
// body: message.image_path ? `Image ${message.text}` : message.text,
// imageUrl: "https://thinkimex.com/img/logo512.png",
// },
data: {
type: "messaging-mark-conversation-read",
conversationid: conversationid || ""
}
const {
ioRedis,
ioHelpers: { getBodyshopRoom, getBodyshopConversationRoom }
} = req;
//Server side, mark the conversation as read
//TODO: Convert this to run on server side. Stolen from chat-conversation.container.jsx
// const [markConversationRead] = useMutation(MARK_MESSAGES_AS_READ_BY_CONVERSATION, {
// variables: { conversationId: selectedConversation },
// refetchQueries: ["UNREAD_CONVERSATION_COUNT"],
//
// update(cache) {
// cache.modify({
// id: cache.identify({
// __typename: "conversations",
// id: selectedConversation
// }),
// fields: {
// messages_aggregate(cached) {
// return { aggregate: { count: 0 } };
// }
// }
// });
// }
// });
const broadcastRoom = getBodyshopRoom(r2.insert_messages.returning[0].conversation.bodyshop.id);
ioRedis.to(broadcastRoom).emit("conversation-changed", {
//type: "conversation-marked-unread" //TODO: Flush out what this looks like.
// isoutbound: true,
// conversationId: conversationid,
// updated_at: r2.insert_messages.returning[0].updated_at,
// msid: message.sid,
// summary: true
});
res.send(200);
};