Reducing excessive calls to open group blocklist.

pull/2174/head
warrickct 4 years ago
parent 75191ae757
commit 380d55066a

@ -231,6 +231,8 @@ window.getOpenGroupBlockList = () => {
return window.groupBlockList;
};
window.openGroupBlockList = window?.getOpenGroupBlockList();
const { locale: localFromEnv } = config;
window.i18n = i18n.setup(localFromEnv, localeMessages);

@ -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<boolean> => {
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');

@ -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);

1
ts/window.d.ts vendored

@ -75,5 +75,6 @@ declare global {
getStartInTray: () => Promise<boolean>;
libsession: any;
getOpenGroupBlockList: () => Array<string>;
openGroupBlockList: Array<string>;
}
}

Loading…
Cancel
Save