Skip to content

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

Add more cleanups on collaboration delete

Hakan Shehuc356fbd68c50
diff --git a/apps/desktop/src/main/jobs/connect-socket.ts b/apps/desktop/src/main/jobs/connect-socket.ts
index bfe7986d..04676919 100644
--- a/apps/desktop/src/main/jobs/connect-socket.ts
+++ b/apps/desktop/src/main/jobs/connect-socket.ts
@@ -34,7 +34,7 @@ export class ConnectSocketJobHandler implements JobHandler<ConnectSocketInput> {
return;
}
- this.debug(`Connecting to socket for account ${account.email}`);
+ this.debug(`Checking connection to socket for account ${account.email}`);
socketService.checkConnection(account);
}
}
diff --git a/apps/desktop/src/main/services/collaboration-service.ts b/apps/desktop/src/main/services/collaboration-service.ts
index 5e98e574..ce9b3719 100644
--- a/apps/desktop/src/main/services/collaboration-service.ts
+++ b/apps/desktop/src/main/services/collaboration-service.ts
@@ -42,17 +42,45 @@ class CollaborationService {
.execute();
if (collaboration.deletedAt) {
- await workspaceDatabase.transaction().execute(async (tx) => {
- await tx
- .deleteFrom('entries')
- .where('id', '=', collaboration.entryId)
- .execute();
+ await workspaceDatabase
+ .deleteFrom('entries')
+ .where('root_id', '=', collaboration.entryId)
+ .execute();
- await tx
- .deleteFrom('entry_transactions')
- .where('entry_id', '=', collaboration.entryId)
- .execute();
- });
+ await workspaceDatabase
+ .deleteFrom('entry_transactions')
+ .where('root_id', '=', collaboration.entryId)
+ .execute();
+
+ await workspaceDatabase
+ .deleteFrom('entry_interactions')
+ .where('root_id', '=', collaboration.entryId)
+ .execute();
+
+ await workspaceDatabase
+ .deleteFrom('messages')
+ .where('root_id', '=', collaboration.entryId)
+ .execute();
+
+ await workspaceDatabase
+ .deleteFrom('message_reactions')
+ .where('root_id', '=', collaboration.entryId)
+ .execute();
+
+ await workspaceDatabase
+ .deleteFrom('message_interactions')
+ .where('root_id', '=', collaboration.entryId)
+ .execute();
+
+ await workspaceDatabase
+ .deleteFrom('files')
+ .where('root_id', '=', collaboration.entryId)
+ .execute();
+
+ await workspaceDatabase
+ .deleteFrom('file_interactions')
+ .where('root_id', '=', collaboration.entryId)
+ .execute();
eventBus.publish({
type: 'collaboration_deleted',
diff --git a/apps/desktop/src/main/services/sync-service.ts b/apps/desktop/src/main/services/sync-service.ts
index b17b2716..128b1030 100644
--- a/apps/desktop/src/main/services/sync-service.ts
+++ b/apps/desktop/src/main/services/sync-service.ts
@@ -282,7 +282,7 @@ class SyncService {
});
}
- private removeRootNodeSynchronizers(userId: string, rootId: string) {
+ private async removeRootNodeSynchronizers(userId: string, rootId: string) {
const keys = Array.from(this.synchronizers.keys());
for (const key of keys) {
@@ -291,56 +291,20 @@ class SyncService {
continue;
}
- if (
- synchronizer.input.type === 'entry_transactions' &&
- synchronizer.input.rootId === rootId
- ) {
- this.synchronizers.delete(key);
- } else if (
- synchronizer.input.type === 'messages' &&
- synchronizer.input.rootId === rootId
- ) {
- this.synchronizers.delete(key);
- } else if (
- synchronizer.input.type === 'message_reactions' &&
- synchronizer.input.rootId === rootId
- ) {
- this.synchronizers.delete(key);
- } else if (
- synchronizer.input.type === 'files' &&
- synchronizer.input.rootId === rootId
- ) {
- this.synchronizers.delete(key);
- } else if (
- synchronizer.input.type === 'entry_interactions' &&
- synchronizer.input.rootId === rootId
- ) {
- this.synchronizers.delete(key);
- } else if (
- synchronizer.input.type === 'file_interactions' &&
- synchronizer.input.rootId === rootId
- ) {
- this.synchronizers.delete(key);
- } else if (
- synchronizer.input.type === 'message_interactions' &&
- synchronizer.input.rootId === rootId
- ) {
- this.synchronizers.delete(key);
- } else if (
- synchronizer.input.type === 'file_tombstones' &&
- synchronizer.input.rootId === rootId
- ) {
- this.synchronizers.delete(key);
- } else if (
- synchronizer.input.type === 'message_tombstones' &&
- synchronizer.input.rootId === rootId
- ) {
- this.synchronizers.delete(key);
+ if (synchronizer.userId !== userId) {
+ continue;
}
+
+ if (!this.isRootNodeSynchronizer(synchronizer, rootId)) {
+ continue;
+ }
+
+ await synchronizer.delete();
+ this.synchronizers.delete(key);
}
}
- private removeWorkspaceSynchronizers(userId: string) {
+ private async removeWorkspaceSynchronizers(userId: string) {
const keys = Array.from(this.synchronizers.keys());
for (const key of keys) {
@@ -350,12 +314,13 @@ class SyncService {
}
if (synchronizer.userId === userId) {
+ await synchronizer.delete();
this.synchronizers.delete(key);
}
}
}
- private removeAccountSynchronizers(accountId: string) {
+ private async removeAccountSynchronizers(accountId: string) {
const keys = Array.from(this.synchronizers.keys());
for (const key of keys) {
@@ -365,10 +330,81 @@ class SyncService {
}
if (synchronizer.accountId === accountId) {
+ await synchronizer.delete();
this.synchronizers.delete(key);
}
}
}
+
+ private isRootNodeSynchronizer(
+ synchronizer: BaseSynchronizer<SynchronizerInput>,
+ rootId: string
+ ) {
+ if (
+ synchronizer.input.type === 'entry_transactions' &&
+ synchronizer.input.rootId === rootId
+ ) {
+ return true;
+ }
+
+ if (
+ synchronizer.input.type === 'entry_interactions' &&
+ synchronizer.input.rootId === rootId
+ ) {
+ return true;
+ }
+
+ if (
+ synchronizer.input.type === 'messages' &&
+ synchronizer.input.rootId === rootId
+ ) {
+ return true;
+ }
+
+ if (
+ synchronizer.input.type === 'message_reactions' &&
+ synchronizer.input.rootId === rootId
+ ) {
+ return true;
+ }
+
+ if (
+ synchronizer.input.type === 'message_interactions' &&
+ synchronizer.input.rootId === rootId
+ ) {
+ return true;
+ }
+
+ if (
+ synchronizer.input.type === 'message_tombstones' &&
+ synchronizer.input.rootId === rootId
+ ) {
+ return true;
+ }
+
+ if (
+ synchronizer.input.type === 'files' &&
+ synchronizer.input.rootId === rootId
+ ) {
+ return true;
+ }
+
+ if (
+ synchronizer.input.type === 'file_interactions' &&
+ synchronizer.input.rootId === rootId
+ ) {
+ return true;
+ }
+
+ if (
+ synchronizer.input.type === 'file_tombstones' &&
+ synchronizer.input.rootId === rootId
+ ) {
+ return true;
+ }
+
+ return false;
+ }
}
export const syncService = new SyncService();
diff --git a/apps/desktop/src/main/synchronizers/base.ts b/apps/desktop/src/main/synchronizers/base.ts
index 65e25710..c347ca10 100644
--- a/apps/desktop/src/main/synchronizers/base.ts
+++ b/apps/desktop/src/main/synchronizers/base.ts
@@ -129,6 +129,13 @@ export abstract class BaseSynchronizer<TInput extends SynchronizerInput> {
.execute();
}
+ public async delete() {
+ await this.database
+ .deleteFrom('cursors')
+ .where('key', '=', this.cursorKey)
+ .execute();
+ }
+
private generateId(userId: string, input: TInput) {
const idObj = {
userId,