From 8bc1ec2dffa82b809cb9851ef661353dcc6d000c Mon Sep 17 00:00:00 2001 From: Lucas Reis Date: Mon, 7 Aug 2023 04:41:47 -0300 Subject: [PATCH] Fix: Show admin on channel members (#7472) * feat: adding the scheme_admin info on the channel members user_list sections * feat: adding the scheme_admin info on channel members when there is a search in the textbox --- app/components/user_list/index.tsx | 34 ++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/app/components/user_list/index.tsx b/app/components/user_list/index.tsx index 6e6e9bb08..38a6c598d 100644 --- a/app/components/user_list/index.tsx +++ b/app/components/user_list/index.tsx @@ -67,12 +67,12 @@ export function createProfilesSections(intl: IntlShape, profiles: UserProfile[], return []; } - const sections = new Map(); + const sections = new Map(); if (members?.length) { // when channel members are provided, build the sections by admins and members const membersDictionary = new Map(); - const membersSections = new Map(); + const membersSections = new Map(); const {formatMessage} = intl; members.forEach((m) => membersDictionary.set(m.user_id, m)); profiles.forEach((p) => { @@ -80,7 +80,7 @@ export function createProfilesSections(intl: IntlShape, profiles: UserProfile[], if (member) { const sectionKey = sectionRoleKeyExtractor(member.scheme_admin!).id; const section = membersSections.get(sectionKey) || []; - section.push(p); + section.push({...p, scheme_admin: member.scheme_admin}); membersSections.set(sectionKey, section); } }); @@ -111,6 +111,28 @@ export function createProfilesSections(intl: IntlShape, profiles: UserProfile[], return results; } +function createProfiles(profiles: UserProfile[], members?: ChannelMembership[]): UserProfileWithChannelAdmin[] { + if (!profiles.length) { + return []; + } + + const profileMap = new Map(); + profiles.forEach((profile) => { + profileMap.set(profile.id, profile); + }); + + if (members?.length) { + members.forEach((m) => { + const profileFound = profileMap.get(m.user_id); + if (profileFound) { + profileFound.scheme_admin = m.scheme_admin; + } + }); + } + + return Array.from(profileMap.values()); +} + const getStyleFromTheme = makeStyleSheetFromTheme((theme) => { return { list: { @@ -195,7 +217,7 @@ export default function UserList({ } if (term) { - return profiles; + return createProfiles(profiles, channelMembers); } return createProfilesSections(intl, profiles, channelMembers); @@ -337,7 +359,7 @@ export default function UserList({ }; if (term) { - return renderFlatList(data as UserProfile[]); + return renderFlatList(data as UserProfileWithChannelAdmin[]); } - return renderSectionList(data as Array>); + return renderSectionList(data as Array>); }