From 380d55066ab082202482b46185d21414fdf25d3c Mon Sep 17 00:00:00 2001 From: warrickct Date: Mon, 7 Mar 2022 09:47:23 +1100 Subject: [PATCH] Reducing excessive calls to open group blocklist. --- preload.js | 2 ++ .../apis/open_group_api/opengroupV2/JoinOpenGroupV2.ts | 8 +++++++- .../apis/open_group_api/opengroupV2/OpenGroupManagerV2.ts | 3 ++- ts/window.d.ts | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/preload.js b/preload.js index 0f990ad8e..f024a6ffe 100644 --- a/preload.js +++ b/preload.js @@ -231,6 +231,8 @@ window.getOpenGroupBlockList = () => { return window.groupBlockList; }; +window.openGroupBlockList = window?.getOpenGroupBlockList(); + const { locale: localFromEnv } = config; window.i18n = i18n.setup(localFromEnv, localeMessages); diff --git a/ts/session/apis/open_group_api/opengroupV2/JoinOpenGroupV2.ts b/ts/session/apis/open_group_api/opengroupV2/JoinOpenGroupV2.ts index 42179e6df..9407a85c4 100644 --- a/ts/session/apis/open_group_api/opengroupV2/JoinOpenGroupV2.ts +++ b/ts/session/apis/open_group_api/opengroupV2/JoinOpenGroupV2.ts @@ -51,10 +51,16 @@ export function parseOpenGroupV2(urlWithPubkey: string): OpenGroupV2Room | undef * @returns true - group is in the blocklist, false - the group is not in the blocklist */ export const isGroupInBlockList = async (serverPubKey: string): Promise => { - const blockList = window?.getOpenGroupBlockList(); + if (!window?.openGroupBlockList) { + // should already be there since this is called in preload + window.getOpenGroupBlockList(); + } + + const blockList = window?.openGroupBlockList; if (!blockList || !blockList.length) { return false; } + const sodium = await getSodium(); // generic hash is blake2b const serverPubKeyBlake2bHash = sodium.crypto_generichash(32, serverPubKey, null, 'hex'); diff --git a/ts/session/apis/open_group_api/opengroupV2/OpenGroupManagerV2.ts b/ts/session/apis/open_group_api/opengroupV2/OpenGroupManagerV2.ts index d2e279d7f..d8b1b3abd 100644 --- a/ts/session/apis/open_group_api/opengroupV2/OpenGroupManagerV2.ts +++ b/ts/session/apis/open_group_api/opengroupV2/OpenGroupManagerV2.ts @@ -15,6 +15,7 @@ import { OpenGroupServerPoller } from './OpenGroupServerPoller'; import _ from 'lodash'; import autoBind from 'auto-bind'; +import { isGroupInBlockList } from './JoinOpenGroupV2'; let instance: OpenGroupManagerV2 | undefined; @@ -127,7 +128,7 @@ export class OpenGroupManagerV2 { [...allRoomInfos.values()].map(async infos => { try { const roomConvoId = getOpenGroupV2ConversationId(infos.serverUrl, infos.roomId); - if (!allConvos.get(roomConvoId)) { + if (!allConvos.get(roomConvoId) || (await isGroupInBlockList(infos.serverPublicKey))) { // remove the roomInfos locally for this open group room await removeV2OpenGroupRoom(roomConvoId); getOpenGroupManager().removeRoomFromPolledRooms(infos); diff --git a/ts/window.d.ts b/ts/window.d.ts index 9d6bc4192..85417105c 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -75,5 +75,6 @@ declare global { getStartInTray: () => Promise; libsession: any; getOpenGroupBlockList: () => Array; + openGroupBlockList: Array; } }