Skip to content

Commit

Permalink
refactor(join-room-api): feature flag join room token gated chat api …
Browse files Browse the repository at this point in the history
…post (#2417)

* refactor(join-room-api): feature flag join room token gated chat api post

* feat: add enableTokenGatedChat feature flag
  • Loading branch information
domw30 authored Nov 11, 2024
1 parent 912a49f commit 9504e50
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
8 changes: 8 additions & 0 deletions src/lib/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
44 changes: 26 additions & 18 deletions src/store/chat/api.ts
Original file line number Diff line number Diff line change
@@ -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: '',
};
}

0 comments on commit 9504e50

Please sign in to comment.