Remove remaining references to useUser(s).

Add Channel object.
This commit is contained in:
Paul
2021-07-29 16:55:07 +01:00
parent 7c119fd1a8
commit 551dc7562e
13 changed files with 126 additions and 54 deletions

View File

@@ -9,11 +9,6 @@ import {
ClientStatus,
StatusContext,
} from "../context/revoltjs/RevoltClient";
import {
useChannels,
useForceUpdate,
useUser,
} from "../context/revoltjs/hooks";
import Header from "../components/ui/Header";
@@ -32,13 +27,9 @@ export default function Open() {
);
}
const ctx = useForceUpdate();
const channels = useChannels(undefined, ctx);
const user = useUser(id, ctx);
useEffect(() => {
if (id === "saved") {
for (const channel of channels) {
for (const channel of client.channels.toArray()) {
if (channel?.channel_type === "SavedMessages") {
history.push(`/channel/${channel._id}`);
return;
@@ -53,12 +44,15 @@ export default function Open() {
return;
}
let user = client.users.get(id);
if (user) {
const channel: string | undefined = channels.find(
(channel) =>
channel?.channel_type === "DirectMessage" &&
channel.recipients.includes(id),
)?._id;
const channel: string | undefined = client.channels
.toArray()
.find(
(channel) =>
channel?.channel_type === "DirectMessage" &&
channel.recipients.includes(id),
)?._id;
if (channel) {
history.push(`/channel/${channel}`);