fix: fix again the thing above i cant be asked to write commit messages anymore

This commit is contained in:
Paul Makles 2022-01-04 15:07:46 +00:00
parent a09fbe685d
commit dbf681c2e9

View file

@ -45,124 +45,122 @@ function useEntries(
const [entries, setEntries] = useState<MemberListGroup[]>([]); const [entries, setEntries] = useState<MemberListGroup[]>([]);
function sort(keys: string[]) { function sort(keys: string[]) {
defer(() => { const categories: { [key: string]: [User, string][] } = {
const categories: { [key: string]: [User, string][] } = { online: [],
online: [], offline: [],
offline: [], };
};
const categoryInfo: { [key: string]: string } = {}; const categoryInfo: { [key: string]: string } = {};
let roles: Server["roles"] | undefined; let roles: Server["roles"] | undefined;
let roleList: string[]; let roleList: string[];
if ( if (
channel.channel_type === "TextChannel" || channel.channel_type === "TextChannel" ||
channel.channel_type === "VoiceChannel" channel.channel_type === "VoiceChannel"
) { ) {
roles = channel.server?.roles; roles = channel.server?.roles;
if (roles) { if (roles) {
const list = Object.keys(roles) const list = Object.keys(roles)
.map((id) => { .map((id) => {
return [id, roles![id], roles![id].rank ?? 0] as [ return [id, roles![id], roles![id].rank ?? 0] as [
string, string,
Role, Role,
number, number,
]; ];
}) })
.filter(([, role]) => role.hoist); .filter(([, role]) => role.hoist);
list.sort((b, a) => b[2] - a[2]); list.sort((b, a) => b[2] - a[2]);
list.forEach(([id, role]) => { list.forEach(([id, role]) => {
if (categories[id]) return; if (categories[id]) return;
categories[id] = []; categories[id] = [];
categoryInfo[id] = role.name; categoryInfo[id] = role.name;
}); });
roleList = list.map((x) => x[0]); roleList = list.map((x) => x[0]);
} }
}
keys.forEach((key) => {
let u;
if (isServer) {
const { server, user } = JSON.parse(key);
if (server !== channel.server_id) return;
u = client.users.get(user);
} else {
u = client.users.get(key);
} }
keys.forEach((key) => { if (!u) return;
let u;
const member = client.members.get(key);
const sort = member?.nickname ?? u.username;
const entry = [u, sort] as [User, string];
if (!u.online || u.status?.presence === Presence.Invisible) {
categories.offline.push(entry);
} else {
if (isServer) { if (isServer) {
const { server, user } = JSON.parse(key); // Sort users into hoisted roles here.
if (server !== channel.server_id) return; if (member?.roles && roles) {
u = client.users.get(user); let success = false;
} else { for (const role of roleList) {
u = client.users.get(key); if (member.roles.includes(role)) {
} categories[role].push(entry);
success = true;
if (!u) return; break;
const member = client.members.get(key);
const sort = member?.nickname ?? u.username;
const entry = [u, sort] as [User, string];
if (!u.online || u.status?.presence === Presence.Invisible) {
categories.offline.push(entry);
} else {
if (isServer) {
// Sort users into hoisted roles here.
if (member?.roles && roles) {
let success = false;
for (const role of roleList) {
if (member.roles.includes(role)) {
categories[role].push(entry);
success = true;
break;
}
} }
if (success) return;
} }
} else {
// Sort users into "participants" list here. if (success) return;
// For voice calls.
} }
} else {
categories.online.push(entry); // Sort users into "participants" list here.
// For voice calls.
} }
});
Object.keys(categories).forEach((key) => categories.online.push(entry);
categories[key].sort((a, b) => a[1].localeCompare(b[1])),
);
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) {
entries.push({
type: "online",
users: categories.online.map((x) => x[0]),
});
} }
if (categories.offline.length > 0) {
entries.push({
type: "offline",
users: categories.offline.map((x) => x[0]),
});
}
setEntries(entries);
}); });
Object.keys(categories).forEach((key) =>
categories[key].sort((a, b) => a[1].localeCompare(b[1])),
);
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) {
entries.push({
type: "online",
users: categories.online.map((x) => x[0]),
});
}
if (categories.offline.length > 0) {
entries.push({
type: "offline",
users: categories.offline.map((x) => x[0]),
});
}
setEntries(entries);
} }
useEffect(() => { useEffect(() => {
return autorun(() => sort(generateKeys())); return autorun(() => sort(generateKeys()));
// eslint-disable-next-line // eslint-disable-next-line
}, [generateKeys]); }, []);
return entries; return entries;
} }