mirror of
https://github.com/colanode/colanode.git
synced 2025-12-29 00:25:03 +01:00
Use node type for transactions
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
if (collaborations.length === 0) {
|
||||
usersToSend = collaborations.map((c) => c.user_id);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { NodeType } from '@colanode/core';
|
||||
|
||||
export type NodeTransactionCreatedEvent = {
|
||||
type: 'node_transaction_created';
|
||||
transactionId: string;
|
||||
nodeId: string;
|
||||
nodeType: NodeType;
|
||||
workspaceId: string;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user