From 4b1ce959ef973bf887cd10d5666ccb075c3470f6 Mon Sep 17 00:00:00 2001 From: Anirban Singha Date: Fri, 3 Jan 2025 19:03:43 +0530 Subject: [PATCH] fix: ensure Admin role tag is visible to all users in channel messages --- packages/api/src/EmbeddedChatApi.ts | 35 ++++++++++++++++++++ packages/react/src/hooks/useFetchChatData.js | 8 ++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/packages/api/src/EmbeddedChatApi.ts b/packages/api/src/EmbeddedChatApi.ts index c2fdabb69..408f811c5 100644 --- a/packages/api/src/EmbeddedChatApi.ts +++ b/packages/api/src/EmbeddedChatApi.ts @@ -605,6 +605,41 @@ export default class EmbeddedChatApi { } } + async getUserRoles() { + try { + const { userId, authToken } = (await this.auth.getCurrentUser()) || {}; + const response = await fetch( + `${this.host}/api/v1/method.call/getUserRoles`, + { + body: JSON.stringify({ + message: JSON.stringify({ + msg: "method", + id: null, + method: "getUserRoles", + params: [], + }), + }), + headers: { + "Content-Type": "application/json", + "X-Auth-Token": authToken, + "X-User-Id": userId, + }, + method: "POST", + } + ); + + const result = await response.json(); + + if (result.success && result.message) { + const parsedMessage = JSON.parse(result.message); + return parsedMessage; + } + return null; + } catch (err) { + console.error(err); + } + } + async sendTypingStatus(username: string, typing: boolean) { try { this.rcClient.methodCall( diff --git a/packages/react/src/hooks/useFetchChatData.js b/packages/react/src/hooks/useFetchChatData.js index 9eb04e9be..583ad431e 100644 --- a/packages/react/src/hooks/useFetchChatData.js +++ b/packages/react/src/hooks/useFetchChatData.js @@ -55,10 +55,10 @@ const useFetchChatData = (showRoles) => { if (showRoles) { const { roles } = await RCInstance.getChannelRoles(isChannelPrivate); - const fetchedAdmins = await RCInstance.getUsersInRole('admin'); - const adminUsernames = fetchedAdmins?.users?.map( - (user) => user.username - ); + const fetchedRoles = await RCInstance.getUserRoles(); + const fetchedAdmins = fetchedRoles?.result; + + const adminUsernames = fetchedAdmins?.map((user) => user.username); setAdmins(adminUsernames); const rolesObj =