Skip to content

Commit

Permalink
fix: message list not refreshing after some time of inactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
raaymax committed Mar 24, 2024
1 parent 27bce06 commit c66f499
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
6 changes: 6 additions & 0 deletions packages/app/src/js/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ window.client = client;
client.req = (msg) => Request.send(msg, client);
client.notif = (msg) => Notification.send(msg, client);

document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
client.emit('win.visible');
}
});

export { client };
20 changes: 4 additions & 16 deletions packages/app/src/js/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ client
type: 'info',
});
})
// FIXME: temporal fix for mesages not refreshing after some time
.on('win.visible', () => store.dispatch(async (dispatch, getState) => {
await methods.messages.load(getState().stream.main);
}))
.on('message', (msg) => actions.messages.add({ ...msg, pending: false }))
.on('notification', () => { try { play(); } catch (err) { /* ignore */ } })
.on('notification', () => { try { navigator.vibrate([100, 30, 100]); } catch (err) { /* ignore */ } })
Expand All @@ -38,19 +42,3 @@ client
},
});
});

/*
setTimeout(() => {
const data = {title: 'oko', text: 'dupa', url: 'https://google.com/'};
const formData = new FormData();
for(const name in data) {
formData.append(name, data[name]);
}
fetch('http://localhost:8080/share/', {
method: 'POST',
body: formData,
});
}, 2000);
*/
3 changes: 2 additions & 1 deletion packages/rpc/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface Transport {
on: (event: string, callback: (data: Message) => void) => void;
once: (event: string, callback: (data: Message) => void) => void;
off: (event: string, callback: (data: Message) => void) => void;
emit: (event: string, data?: Message) => void;
}

export class WebSocketTransport implements Transport {
Expand Down Expand Up @@ -88,7 +89,7 @@ export class WebSocketTransport implements Transport {
return this;
}

private emit(event: string, data?: Message) {
emit(event: string, data?: Message) {
if (!this.bus.exists(event)) {
return;
}
Expand Down

0 comments on commit c66f499

Please sign in to comment.