mirror of
https://github.com/colanode/colanode.git
synced 2025-12-29 00:25:03 +01:00
Add collaborator removed event in server
This commit is contained in:
@@ -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: {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user