refac
This commit is contained in:
@@ -3,7 +3,7 @@ import { getChatList, getPinnedChatList } from '$lib/apis/chats';
|
||||
|
||||
type ChatListItem = {
|
||||
id: string;
|
||||
[key: string]: any;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
|
||||
const chatsStore = writable<ChatListItem[] | null>(null);
|
||||
@@ -90,6 +90,21 @@ export const loadNextChatListPage = async (token: string = ''): Promise<ChatList
|
||||
}
|
||||
};
|
||||
|
||||
export const setChatActive = (chatId: string, active: boolean): boolean => {
|
||||
let found = false;
|
||||
const updateChat = (chat: ChatListItem) => {
|
||||
if (chat.id !== chatId) {
|
||||
return chat;
|
||||
}
|
||||
found = true;
|
||||
return { ...chat, active };
|
||||
};
|
||||
|
||||
chatsStore.update((items) => (items ? items.map(updateChat) : items));
|
||||
pinnedChatsStore.update((items) => items.map(updateChat));
|
||||
return found;
|
||||
};
|
||||
|
||||
export const resetChatListState = () => {
|
||||
requestGeneration += 1;
|
||||
currentPage = 1;
|
||||
|
||||
@@ -31,7 +31,6 @@ export const mobile = writable(false);
|
||||
export const socket: Writable<null | Socket> = writable(null);
|
||||
export const socketConnected: Writable<boolean> = writable(true);
|
||||
export const activeUserIds: Writable<null | string[]> = writable(null);
|
||||
export const activeChatIds: Writable<Set<string>> = writable(new Set());
|
||||
export const USAGE_POOL: Writable<null | string[]> = writable(null);
|
||||
|
||||
export const theme = writable('system');
|
||||
|
||||
Reference in New Issue
Block a user