mirror of
https://github.com/Blah-IM/Weblah.git
synced 2025-07-08 15:05:33 +00:00
refactor: update to new room info protocol
This commit is contained in:
parent
48f9c32918
commit
f34ad89b79
2 changed files with 25 additions and 9 deletions
|
@ -33,14 +33,25 @@
|
|||
return server;
|
||||
}
|
||||
|
||||
async function loadChat(server: BlahChatServerConnection) {
|
||||
const { room, messages: blahMessages } = await server.fetchRoom(roomId);
|
||||
async function loadChatInfo(server: BlahChatServerConnection) {
|
||||
const room = await server.fetchRoomInfo(roomId);
|
||||
chat = {
|
||||
id: roomId,
|
||||
name: room.title,
|
||||
type: 'group'
|
||||
};
|
||||
messages = [...blahMessages.map(messageFromBlah), ...messages];
|
||||
}
|
||||
|
||||
async function loadChatHistory(server: BlahChatServerConnection) {
|
||||
const history = await server.fetchRoomHistory(roomId);
|
||||
messages = [
|
||||
...history.map(messageFromBlah).toSorted((a, b) => a.date.getTime() - b.date.getTime()),
|
||||
...messages
|
||||
];
|
||||
}
|
||||
|
||||
async function loadChat(server: BlahChatServerConnection) {
|
||||
return await Promise.allSettled([loadChatInfo(server), loadChatHistory(server)]);
|
||||
}
|
||||
|
||||
$: if (browser) initConnection($currentKeyPair).then((server) => loadChat(server));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue