-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(conversationsStore) - cache conversations to BrowserStorage #10203
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested, works fine. Only some naming preferences.
Checked that LS is pruned on logout, not security issues ✅
From the UX side: after reload, a user sees an old conversations list with old last messages. That could be confusing. Should we add any small load indicator?
BrowserStorage
is reused by tabs. If we store conversations in the browser storage, we should do it only once.
Currently it is used only for initialization. But if we open 5 tabs with Talk, then we have 5 apps with 5 conversation re-fetchings and 5 parallel updating localStorage
. The most optimal solution here could be to run re-fetching only on one tab/worker and listen to the storage
windows event or BroadcastChannel
.
Upd: instead of shared worker, it could be easier and better for browser support to use Web Locks API |
Notes about using Web Locks API here. We don't have actually a "resource" that we want to block. But we can use a Leader pattern. Then we can create a helper like async function onTalkLeaderTab(() => {
// Promise of waiting to be a leader
return new Promise((resolve) =>
// Request "being a leader"
navigator.locks.request('talk:leader', () => {
// Since we got this "resource" this tab is a leader. Resolve promise
resolve()
// Infinity promise, resource is blocked forever, while tab is not closed
return new Promise(() => {})
}
}
onTalkLeaderTab()
.then(() => {
// Now we are the leader
// Start the setInterval for re-fetching or anything
}) One important thing: it only works with HTTPS Then we can use the |
3263f12
to
b12044b
Compare
b12044b
to
2b2cdb2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested, everything seems to work fine. Tested with 2-3 tabs, with changing leader, creating new conversations, deleting conversations.
Follow-up: because x-talk-hash header is checked not in any HTTP response, but only in re-fetching conversations for the |
d9aab00
to
8a94079
Compare
Rebased, follow-up fixed with additional broadcasted message specifically for talk hash. |
112a2a4
to
358ea29
Compare
…serStorage Signed-off-by: Maksim Sukharev <[email protected]>
f9f8028
to
7d86c4d
Compare
…ery 30 seconds only from one source Signed-off-by: Maksim Sukharev <[email protected]>
7d86c4d
to
2bd8ce1
Compare
Follow-ups:
|
/backport to stable27 |
☑️ Resolves
patchConversations()
action, which is called approx. every 30 seconds/apps/spreed/not-found
🖼️ Screenshots
🚧 Tasks
🏁 Checklist
docs/
has been updated or is not required