Skip to content

Open-source and local-first Slack and Notion alternative that puts you in control of your data

Delete node user state on delete

Hakan Shehud052300ea032
diff --git a/server/src/sockets/socket-connection.ts b/server/src/sockets/socket-connection.ts
index a57d97d8..18802c72 100644
--- a/server/src/sockets/socket-connection.ts
+++ b/server/src/sockets/socket-connection.ts
@@ -99,12 +99,25 @@ export class SocketConnection {
}
} else if (messageInput.type === 'local_node_delete') {
this.pendingSyncs.delete(messageInput.nodeId);
+
await database
.deleteFrom('node_device_states')
.where('device_id', '=', this.deviceId)
.where('node_id', '=', messageInput.nodeId)
.execute();
+ const userId = this.workspaceUsers.find(
+ (wu) => wu.workspaceId === messageInput.workspaceId,
+ )?.userId;
+
+ if (userId) {
+ await database
+ .deleteFrom('node_user_states')
+ .where('node_id', '=', messageInput.nodeId)
+ .where('user_id', '=', userId)
+ .execute();
+ }
+
if (this.pendingSyncs.size === 0) {
this.sendPendingChanges();
}