add friends & blocked users

This commit is contained in:
V 2023-09-05 05:18:26 +02:00
parent 1757d17661
commit 1cfeaf77c1
No known key found for this signature in database
GPG Key ID: A1DC0CFB5615D905
2 changed files with 74 additions and 6 deletions

@ -7,16 +7,17 @@
import "./styles.css"; import "./styles.css";
import { classNameFactory } from "@api/Styles"; import { classNameFactory } from "@api/Styles";
import { openImageModal } from "@utils/discord"; import { openImageModal, openUserProfile } from "@utils/discord";
import { classes } from "@utils/misc"; import { classes } from "@utils/misc";
import { ModalRoot, ModalSize, openModal } from "@utils/modal"; import { ModalRoot, ModalSize, openModal } from "@utils/modal";
import { useAwaiter } from "@utils/react"; import { LazyComponent, useAwaiter } from "@utils/react";
import { findByPropsLazy } from "@webpack"; import { findByCode, findByPropsLazy } from "@webpack";
import { Forms, GuildChannelStore, GuildMemberStore, Parser, SnowflakeUtils, TabBar, UserUtils, useState } from "@webpack/common"; import { FluxDispatcher, Forms, GuildChannelStore, GuildMemberStore, Parser, PresenceStore, RelationshipStore, ScrollerThin, SnowflakeUtils, TabBar, useEffect, UserStore, UserUtils, useState, useStateFromStores } from "@webpack/common";
import { Guild, User } from "discord-types/general"; import { Guild, User } from "discord-types/general";
const IconUtils = findByPropsLazy("getGuildBannerURL"); const IconUtils = findByPropsLazy("getGuildBannerURL");
const IconClasses = findByPropsLazy("icon", "acronym", "childWrapper"); const IconClasses = findByPropsLazy("icon", "acronym", "childWrapper");
const UserRow = LazyComponent(() => findByCode(".listDiscriminator"));
const cl = classNameFactory("vc-gp-"); const cl = classNameFactory("vc-gp-");
@ -49,7 +50,17 @@ interface GuildProps {
guild: Guild; guild: Guild;
} }
const fetched = {
friends: false,
blocked: false
};
function GuildProfileModal({ guild }: GuildProps) { function GuildProfileModal({ guild }: GuildProps) {
useEffect(() => {
fetched.friends = false;
fetched.blocked = false;
}, []);
const [currentTab, setCurrentTab] = useState<TabKeys>("ServerInfo"); const [currentTab, setCurrentTab] = useState<TabKeys>("ServerInfo");
const Tab = Tabs[currentTab].component; const Tab = Tabs[currentTab].component;
@ -175,9 +186,54 @@ function ServerInfoTab({ guild }: GuildProps) {
} }
function FriendsTab({ guild }: GuildProps) { function FriendsTab({ guild }: GuildProps) {
return null; return UserList("friends", guild, RelationshipStore.getFriendIDs());
} }
function BlockedUsersTab({ guild }: GuildProps) { function BlockedUsersTab({ guild }: GuildProps) {
return null; const blockedIds = Object.keys(RelationshipStore.getRelationships()).filter(id => RelationshipStore.isBlocked(id));
return UserList("blocked", guild, blockedIds);
}
function UserList(type: "friends" | "blocked", guild: Guild, ids: string[]) {
const missing = [] as string[];
const members = [] as string[];
for (const id of ids) {
if (GuildMemberStore.isMember(guild.id, id))
members.push(id);
else
missing.push(id);
}
// Used for side effects (rerender on member request success)
useStateFromStores(
[GuildMemberStore],
() => GuildMemberStore.getMemberIds(guild.id),
null,
(old, curr) => old.length === curr.length
);
useEffect(() => {
if (!fetched[type] && missing.length) {
fetched[type] = true;
FluxDispatcher.dispatch({
type: "GUILD_MEMBERS_REQUEST",
guildIds: [guild.id],
userIds: missing
});
}
}, []);
return (
<ScrollerThin fade className={cl("scroller")}>
{members.map(id =>
<UserRow
user={UserStore.getUser(id)}
status={PresenceStore.getStatus(id) || "offline"}
onSelect={() => openUserProfile(id)}
onContextMenu={() => { }}
/>
)}
</ScrollerThin>
);
} }

@ -1,3 +1,6 @@
.vc-gp-content {
}
.vc-gp-root { .vc-gp-root {
height: 100%; height: 100%;
user-select: text; user-select: text;
@ -78,3 +81,12 @@
border-radius: 50%; border-radius: 50%;
cursor: pointer; cursor: pointer;
} }
.vc-gp-scroller {
width: 100%;
max-height: 500px;
}
.vc-gp-scroller [class^=listRow]:hover {
background-color: var(--background-modifier-hover);
}