Display all server roles separately.

This commit is contained in:
Paul 2021-08-08 21:50:29 +01:00
parent a19ff58e12
commit d5b0d8d9cf
3 changed files with 46 additions and 9 deletions

View file

@ -50,7 +50,9 @@ export default function MemberList({
const type = entries[index].type; const type = entries[index].type;
return ( return (
<ListCategory first={index === 0}> <ListCategory first={index === 0}>
{type === "online" ? ( {type === "role" ? (
<>{entries[index].name}</>
) : type === "online" ? (
<Text id="app.status.online" /> <Text id="app.status.online" />
) : ( ) : (
<Text id="app.status.offline" /> <Text id="app.status.offline" />

View file

@ -39,12 +39,24 @@ function useEntries(channel: Channel, keys: string[], isServer?: boolean) {
offline: [], offline: [],
}; };
const categoryInfo: { [key: string]: string } = {};
keys.forEach((key) => { keys.forEach((key) => {
let u; let u, s;
if (isServer) { if (isServer) {
const { server, user } = JSON.parse(key); const { server, user } = JSON.parse(key);
if (server !== channel.server_id) return; if (server !== channel.server_id) return;
u = client.users.get(user); u = client.users.get(user);
s = client.servers.get(server);
if (s?.roles) {
for (const id of Object.keys(s.roles)) {
if (categories[id]) continue;
// Check if hoisted.
categories[id] = [];
categoryInfo[id] = s.roles[id].name;
}
}
} else { } else {
u = client.users.get(key); u = client.users.get(key);
} }
@ -55,16 +67,28 @@ function useEntries(channel: Channel, keys: string[], isServer?: boolean) {
const sort = member?.nickname ?? u.username; const sort = member?.nickname ?? u.username;
const entry = [u, sort] as [User, string]; const entry = [u, sort] as [User, string];
if (!u.online || u.status?.presence === Presence.Invisible) {
categories.offline.push(entry);
} else {
if (isServer) { if (isServer) {
// Sort users into hoisted roles here. // Sort users into hoisted roles here.
if (member?.roles && s?.roles) {
let success = false;
for (const id of member.roles) {
if (categories[id]) {
categories[id].push(entry);
success = true;
}
break;
}
if (success) return;
}
} else { } else {
// Sort users into "participants" list here. // Sort users into "participants" list here.
// For voice calls. // For voice calls.
} }
if (!u.online || u.status?.presence === Presence.Invisible) {
categories.offline.push(entry);
} else {
categories.online.push(entry); categories.online.push(entry);
} }
}); });
@ -75,6 +99,16 @@ function useEntries(channel: Channel, keys: string[], isServer?: boolean) {
const entries: MemberListGroup[] = []; const entries: MemberListGroup[] = [];
Object.keys(categoryInfo).forEach((key) => {
if (categories[key].length > 0) {
entries.push({
type: "role",
name: categoryInfo[key],
users: categories[key].map((x) => x[0]),
});
}
});
if (categories.online.length > 0) { if (categories.online.length > 0) {
entries.push({ entries.push({
type: "online", type: "online",

View file

@ -79,6 +79,7 @@ export function grabFiles(
const files = (e.currentTarget as HTMLInputElement)?.files; const files = (e.currentTarget as HTMLInputElement)?.files;
if (!files) return; if (!files) return;
for (const file of files) { for (const file of files) {
alert(file.size);
if (file.size > maxFileSize) { if (file.size > maxFileSize) {
return tooLarge(); return tooLarge();
} }