Fetch updates to communication when SSE pushes a message

This commit is contained in:
Eli Ribble 2026-05-11 23:21:16 +00:00
parent eac81778bd
commit 85fd1d081d
No known key found for this signature in database

View file

@ -14,8 +14,11 @@ export const useCommunicationStore = defineStore("communication", () => {
// Subscription // Subscription
SSEManager.subscribe((msg: SSEMessageResource) => { SSEManager.subscribe((msg: SSEMessageResource) => {
if (msg.resource.startsWith("rmo:")) { if (
fetchAll(); msg.resource.startsWith("sync:communication") &&
msg.type == "updated"
) {
fetchOne(msg.uri);
} }
}); });
// Actions // Actions
@ -44,6 +47,18 @@ export const useCommunicationStore = defineStore("communication", () => {
loading.value = false; loading.value = false;
} }
} }
async function fetchOne(uri: string) {
const data = (await apiClient.JSONGet(uri)) as CommunicationDTO;
if (!all.value) {
return;
}
for (var i = 0; i < all.value.length; i++) {
const c = all.value[i];
if (c.uri == data.uri) {
all.value[i] = Communication.fromJSON(data);
}
}
}
return { return {
// State // State
all, all,