From 9504e50b70a9848d8808c5ac0eb2bbe4e0e53fe5 Mon Sep 17 00:00:00 2001 From: DomW Date: Mon, 11 Nov 2024 13:07:28 +0000 Subject: [PATCH] refactor(join-room-api): feature flag join room token gated chat api post (#2417) * refactor(join-room-api): feature flag join room token gated chat api post * feat: add enableTokenGatedChat feature flag --- src/lib/feature-flags.ts | 8 ++++++++ src/store/chat/api.ts | 44 ++++++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/lib/feature-flags.ts b/src/lib/feature-flags.ts index f6d67be7c..bde2c12fa 100644 --- a/src/lib/feature-flags.ts +++ b/src/lib/feature-flags.ts @@ -129,6 +129,14 @@ export class FeatureFlags { set enableMeows(value: boolean) { this._setBoolean('enableMeows', value); } + + get enableTokenGatedChat() { + return this._getBoolean('enableTokenGatedChat', false); + } + + set enableTokenGatedChat(value: boolean) { + this._setBoolean('enableTokenGatedChat', value); + } } export const featureFlags = new FeatureFlags(); diff --git a/src/store/chat/api.ts b/src/store/chat/api.ts index 927307274..4b8b747f8 100644 --- a/src/store/chat/api.ts +++ b/src/store/chat/api.ts @@ -1,28 +1,36 @@ import { post } from '../../lib/api/rest'; import { JoinRoomApiErrorCode } from './utils'; +import { featureFlags } from '../../lib/feature-flags'; export async function joinRoom(aliasOrId: string): Promise<{ success: boolean; response: any; message: string }> { - try { - const response = await post('/matrix/room/join').send({ - roomAliasORId: aliasOrId, - }); - return { - success: true, - response: response.body, - message: 'OK', - }; - } catch (error: any) { - if (error?.response?.status === 400) { + if (featureFlags.enableTokenGatedChat) { + try { + const response = await post('/matrix/room/join').send({ + roomAliasORId: aliasOrId, + }); + return { + success: true, + response: response.body, + message: 'OK', + }; + } catch (error: any) { + if (error?.response?.status === 400) { + return { + success: false, + response: error.response.body.code, + message: error.response.body.message, + }; + } return { success: false, - response: error.response.body.code, - message: error.response.body.message, + response: JoinRoomApiErrorCode.UNKNOWN_ERROR, + message: '', }; } - return { - success: false, - response: JoinRoomApiErrorCode.UNKNOWN_ERROR, - message: '', - }; } + return { + success: false, + response: JoinRoomApiErrorCode.ROOM_NOT_FOUND, + message: '', + }; }