Skip to content

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

Add collaborator removed event in server

Hakan Shehuf3b7d03eaa5a
diff --git a/apps/server/src/services/node-service.ts b/apps/server/src/services/node-service.ts
index ddc65dc5..aaa8e728 100644
--- a/apps/server/src/services/node-service.ts
+++ b/apps/server/src/services/node-service.ts
@@ -468,6 +468,20 @@ class NodeService {
workspaceId: context.workspaceId,
});
+ const removedCollaboratorIds = Object.keys(
+ collaboratorChanges.removedCollaborators
+ );
+
+ if (removedCollaboratorIds.length > 0) {
+ for (const userId of removedCollaboratorIds) {
+ eventBus.publish({
+ type: 'collaborator_removed',
+ userId,
+ nodeId: input.nodeId,
+ });
+ }
+ }
+
return {
type: 'success',
output: {
diff --git a/apps/server/src/services/synapse-service.ts b/apps/server/src/services/synapse-service.ts
index 968cab40..f94ea7c8 100644
--- a/apps/server/src/services/synapse-service.ts
+++ b/apps/server/src/services/synapse-service.ts
@@ -10,7 +10,10 @@ import {
import { logService } from '@/services/log-service';
import { mapCollaborationRevocation, mapNodeTransaction } from '@/lib/nodes';
import { eventBus } from '@/lib/event-bus';
-import { NodeTransactionCreatedEvent } from '@/types/events';
+import {
+ CollaboratorRemovedEvent,
+ NodeTransactionCreatedEvent,
+} from '@/types/events';
interface SynapseUserCursor {
workspaceId: string;
@@ -35,6 +38,8 @@ class SynapseService {
eventBus.subscribe((event) => {
if (event.type === 'node_transaction_created') {
this.handleNodeTransactionCreatedEvent(event);
+ } else if (event.type === 'collaborator_removed') {
+ this.handleCollaboratorRemovedEvent(event);
}
});
}
@@ -290,6 +295,18 @@ class SynapseService {
}
}
+ private handleCollaboratorRemovedEvent(event: CollaboratorRemovedEvent) {
+ const deviceIds = this.getPendingRevocationsCursors(event.userId);
+ for (const deviceId of deviceIds) {
+ const socketConnection = this.connections.get(deviceId);
+ if (socketConnection === undefined) {
+ continue;
+ }
+
+ this.sendPendingRevocations(socketConnection, event.userId);
+ }
+ }
+
private getPendingNodeTransactionCursors(
workspaceId: string
): Map<string, string[]> {
@@ -310,7 +327,7 @@ class SynapseService {
return userDevices;
}
- private getPendingCollaborationCursors(userId: string): string[] {
+ private getPendingRevocationsCursors(userId: string): string[] {
const userDevices: string[] = [];
for (const connection of this.connections.values()) {
const connectionUsers = connection.revocations.values();
diff --git a/apps/server/src/types/events.ts b/apps/server/src/types/events.ts
index e5fd8a87..a0b48639 100644
--- a/apps/server/src/types/events.ts
+++ b/apps/server/src/types/events.ts
@@ -5,4 +5,10 @@ export type NodeTransactionCreatedEvent = {
workspaceId: string;
};
-export type Event = NodeTransactionCreatedEvent;
+export type CollaboratorRemovedEvent = {
+ type: 'collaborator_removed';
+ userId: string;
+ nodeId: string;
+};
+
+export type Event = NodeTransactionCreatedEvent | CollaboratorRemovedEvent;