From 23e00319ffa6472a9b914213692eb0b04a9431a0 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Thu, 2 Dec 2021 12:37:19 +0000 Subject: [PATCH] Improve deduplication script --- src/ConnectionManager.ts | 4 ++-- src/Connections/BaseConnection.ts | 2 +- src/Connections/IConnection.ts | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ConnectionManager.ts b/src/ConnectionManager.ts index f674dd31..167fb348 100644 --- a/src/ConnectionManager.ts +++ b/src/ConnectionManager.ts @@ -44,7 +44,7 @@ export class ConnectionManager { public push(...connections: IConnection[]) { // NOTE: Double loop for (const connection of connections) { - if (!this.connections.find((c) => c === connection)) { + if (!this.connections.find(c => c.connectionId === connection.connectionId)) { this.connections.push(connection); } } @@ -204,7 +204,7 @@ export class ConnectionManager { const connections: IConnection[] = []; for (const event of state) { const conn = await this.createConnectionForState(roomId, new StateEvent(event)); - if (conn) { connections.push(conn); } + if (conn) { this.push(conn); } } return connections; } diff --git a/src/Connections/BaseConnection.ts b/src/Connections/BaseConnection.ts index a01afc91..a09c9c6c 100644 --- a/src/Connections/BaseConnection.ts +++ b/src/Connections/BaseConnection.ts @@ -12,6 +12,6 @@ export abstract class BaseConnection { } public get connectionId(): string { - return FormatUtil.hashId(`${this.canonicalStateType}/${this.stateKey}`); + return FormatUtil.hashId(`${this.roomId}/${this.canonicalStateType}/${this.stateKey}`); } } \ No newline at end of file diff --git a/src/Connections/IConnection.ts b/src/Connections/IConnection.ts index 7573e200..ca3e075d 100644 --- a/src/Connections/IConnection.ts +++ b/src/Connections/IConnection.ts @@ -3,8 +3,14 @@ import { IssuesOpenedEvent, IssuesEditedEvent } from "@octokit/webhooks-types"; import { GetConnectionsResponseItem } from "../provisioning/api"; export interface IConnection { + /** + * The roomId that this connection serves. + */ roomId: string; + /** + * The unique connection ID. This is a opaque hash of the roomId, connection type and state key. + */ get connectionId(): string; /** * When a room gets an update to it's state.