Fetch updates to communication when SSE pushes a message
This commit is contained in:
parent
eac81778bd
commit
85fd1d081d
1 changed files with 17 additions and 2 deletions
|
|
@ -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,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue