Skip to content

Commit

Permalink
fix: ensure Admin role tag is visible to all users in channel messages
Browse files Browse the repository at this point in the history
  • Loading branch information
SinghaAnirban005 committed Jan 3, 2025
1 parent cb012e7 commit 4b1ce95
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
35 changes: 35 additions & 0 deletions packages/api/src/EmbeddedChatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions packages/react/src/hooks/useFetchChatData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 4b1ce95

Please sign in to comment.