feat: dm channels

This commit is contained in:
Timothy Jaeryang Baek
2025-11-27 07:27:32 -05:00
parent f2c56fc839
commit acccb9afdd
13 changed files with 989 additions and 216 deletions
+22 -13
View File
@@ -56,6 +56,7 @@
import Spinner from '$lib/components/common/Spinner.svelte';
import { getUserSettings } from '$lib/apis/users';
import dayjs from 'dayjs';
import { getChannels } from '$lib/apis/channels';
const unregisterServiceWorkers = async () => {
if ('serviceWorker' in navigator) {
@@ -485,20 +486,28 @@
const data = event?.data?.data ?? null;
if ($channels) {
channels.set(
$channels.map((ch) => {
if (ch.id === event.channel_id) {
if (type === 'message') {
return {
...ch,
unread_count: (ch.unread_count ?? 0) + 1,
last_message_at: event.created_at
};
if ($channels.find((ch) => ch.id === event.channel_id)) {
channels.set(
$channels.map((ch) => {
if (ch.id === event.channel_id) {
if (type === 'message') {
return {
...ch,
unread_count: (ch.unread_count ?? 0) + 1,
last_message_at: event.created_at
};
}
}
}
return ch;
})
);
return ch;
})
);
} else {
await channels.set(
(await getChannels(localStorage.token)).sort((a, b) =>
a.type === b.type ? 0 : a.type === 'dm' ? 1 : -1
)
);
}
}
if (type === 'message') {