fix: User presence is not updated when leaving a document

This commit is contained in:
Tom Moor
2023-05-22 21:05:40 -04:00
parent 4e75b4029a
commit 3317bf2396
5 changed files with 47 additions and 79 deletions

View File

@@ -85,9 +85,7 @@ class WebsocketProvider extends React.Component<Props> {
stars,
memberships,
policies,
presence,
comments,
views,
subscriptions,
fileOperations,
notifications,
@@ -105,12 +103,6 @@ class WebsocketProvider extends React.Component<Props> {
});
});
this.socket.on("disconnect", () => {
// when the socket is disconnected we need to clear all presence state as
// it's no longer reliable.
presence.clear();
});
// on reconnection, reset the transports option, as the Websocket
// connection may have failed (caused by proxy, firewall, browser, ...)
this.socket.io.on("reconnect_attempt", () => {
@@ -468,33 +460,6 @@ class WebsocketProvider extends React.Component<Props> {
this.socket.on("leave", (event: any) => {
this.socket?.emit("leave", event);
});
// received whenever we join a document room, the payload includes
// userIds that are present/viewing and those that are editing.
this.socket.on("document.presence", (event: any) => {
presence.init(event.documentId, event.userIds, event.editingIds);
});
// received whenever a new user joins a document room, aka they
// navigate to / start viewing a document
this.socket.on("user.join", (event: any) => {
presence.touch(event.documentId, event.userId, event.isEditing);
views.touch(event.documentId, event.userId);
});
// received whenever a new user leaves a document room, aka they
// navigate away / stop viewing a document
this.socket.on("user.leave", (event: any) => {
presence.leave(event.documentId, event.userId);
views.touch(event.documentId, event.userId);
});
// received when another client in a document room wants to change
// or update it's presence. Currently the only property is whether
// the client is in editing state or not.
this.socket.on("user.presence", (event: any) => {
presence.touch(event.documentId, event.userId, event.isEditing);
});
};
render() {