IO-2426 Add FCM Cache update for conversation aggregate count.

This commit is contained in:
Patrick Fic
2023-11-07 08:55:59 -08:00
parent 4e1dd52bea
commit 3e05b21c90

View File

@@ -12,6 +12,13 @@ export default async function FcmHandler({ client, payload }) {
}, },
}, },
}); });
client.cache.modify({
fields: {
messages_aggregate(cached) {
return { aggregate: { count: cached.aggregate.count + 1 } };
},
},
});
break; break;
case "messaging-outbound": case "messaging-outbound":
client.cache.modify({ client.cache.modify({
@@ -30,6 +37,7 @@ export default async function FcmHandler({ client, payload }) {
}); });
break; break;
case "messaging-mark-conversation-read": case "messaging-mark-conversation-read":
let previousUnreadCount = 0;
client.cache.modify({ client.cache.modify({
id: client.cache.identify({ id: client.cache.identify({
__typename: "conversations", __typename: "conversations",
@@ -37,10 +45,22 @@ export default async function FcmHandler({ client, payload }) {
}), }),
fields: { fields: {
messages_aggregate(cached) { messages_aggregate(cached) {
previousUnreadCount = cached.aggregate.count;
return { aggregate: { count: 0 } }; return { aggregate: { count: 0 } };
}, },
}, },
}); });
client.cache.modify({
fields: {
messages_aggregate(cached) {
return {
aggregate: {
count: cached.aggregate.count - previousUnreadCount,
},
};
},
},
});
break; break;
default: default:
console.log("No payload type set."); console.log("No payload type set.");