Open-source and local-first Slack and Notion alternative that puts you in control of your data
TypeScript chatchat-applicationcrdteditorelectronknowledge-baselocal-firstnotionnotion-alternativerealtime-collaborationself-hostedslacksqliteteam-collaborationwikiyjs
Use node type for transactions
Hakan Shehuf33e301eabb0
diff --git a/apps/server/src/services/node-service.ts b/apps/server/src/services/node-service.tsindex aaa8e728..32acfa49 100644--- a/apps/server/src/services/node-service.ts+++ b/apps/server/src/services/node-service.ts@@ -96,6 +96,7 @@ class NodeService {type: 'node_transaction_created',transactionId: transactionId,nodeId: input.nodeId,+ nodeType: input.attributes.type,workspaceId: input.workspaceId,});@@ -234,6 +235,7 @@ class NodeService {type: 'node_transaction_created',transactionId: transactionId,nodeId: input.nodeId,+ nodeType: node.type,workspaceId: input.workspaceId,});@@ -313,6 +315,7 @@ class NodeService {type: 'node_transaction_created',transactionId: input.id,nodeId: input.nodeId,+ nodeType: attributes.type,workspaceId: context.workspaceId,});@@ -465,6 +468,7 @@ class NodeService {type: 'node_transaction_created',transactionId: input.id,nodeId: input.nodeId,+ nodeType: node.type,workspaceId: context.workspaceId,});@@ -566,6 +570,7 @@ class NodeService {type: 'node_transaction_created',transactionId: input.id,nodeId: input.nodeId,+ nodeType: node.type,workspaceId: workspaceUser.workspace_id,});diff --git a/apps/server/src/services/synapse-service.ts b/apps/server/src/services/synapse-service.tsindex f94ea7c8..e574d30c 100644--- a/apps/server/src/services/synapse-service.ts+++ b/apps/server/src/services/synapse-service.ts@@ -6,6 +6,7 @@ import {CollaborationRevocationsBatchMessage,Message,NodeTransactionsBatchMessage,+ NodeType,} from '@colanode/core';import { logService } from '@/services/log-service';import { mapCollaborationRevocation, mapNodeTransaction } from '@/lib/nodes';@@ -30,6 +31,8 @@ interface SynapseConnection {revocations: Map<string, SynapseUserCursor>;}+const PUBLIC_NODES: NodeType[] = ['workspace', 'user'];+class SynapseService {private readonly logger = logService.createLogger('synapse-service');private readonly connections: Map<string, SynapseConnection> = new Map();@@ -270,27 +273,37 @@ class SynapseService {return;}- const collaborations = await database- .selectFrom('collaborations')- .selectAll()- .where((eb) =>- eb.and([eb('user_id', 'in', userIds), eb('node_id', '=', event.nodeId)])- )- .execute();+ let usersToSend: string[] = [];+ if (PUBLIC_NODES.includes(event.nodeType)) {+ usersToSend = userIds;+ } else {+ const collaborations = await database+ .selectFrom('collaborations')+ .selectAll()+ .where((eb) =>+ eb.and([+ eb('user_id', 'in', userIds),+ eb('node_id', '=', event.nodeId),+ ])+ )+ .execute();++ usersToSend = collaborations.map((c) => c.user_id);+ }- if (collaborations.length === 0) {+ if (usersToSend.length === 0) {return;}- for (const collaboration of collaborations) {- const deviceIds = userDevices.get(collaboration.user_id) ?? [];+ for (const userId of usersToSend) {+ const deviceIds = userDevices.get(userId) ?? [];for (const deviceId of deviceIds) {const socketConnection = this.connections.get(deviceId);if (socketConnection === undefined) {continue;}- this.sendPendingTransactions(socketConnection, collaboration.user_id);+ this.sendPendingTransactions(socketConnection, userId);}}}diff --git a/apps/server/src/types/events.ts b/apps/server/src/types/events.tsindex a0b48639..52758102 100644--- a/apps/server/src/types/events.ts+++ b/apps/server/src/types/events.ts@@ -1,7 +1,10 @@+import { NodeType } from '@colanode/core';+export type NodeTransactionCreatedEvent = {type: 'node_transaction_created';transactionId: string;nodeId: string;+ nodeType: NodeType;workspaceId: string;};