Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure Admin role tag is visible to all users in channel messages #784

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading