This commit is contained in:
Timothy Jaeryang Baek
2026-07-26 23:55:37 -04:00
parent e5a08d5220
commit 8ddf119570
4 changed files with 24 additions and 4 deletions
+1 -2
View File
@@ -694,13 +694,12 @@ class ChatTable:
await session.commit()
return result.rowcount or 0
async def mark_root_chats_read_by_user_id(self, user_id: str, db: AsyncSession | None = None) -> int:
async def mark_chats_read_by_user_id(self, user_id: str, db: AsyncSession | None = None) -> int:
async with get_async_db_context(db) as session:
result = await session.execute(
update(Chat)
.where(
Chat.user_id == user_id,
Chat.folder_id.is_(None),
Chat.archived == False,
Chat.meta['internal'].as_boolean().is_not(True),
)
+5 -2
View File
@@ -256,11 +256,14 @@ async def get_session_user_chat_list(
@router.post('/read')
async def mark_root_chats_read_by_user_id(
async def mark_chats_read_by_user_id(
user=Depends(get_verified_user),
db: AsyncSession = Depends(get_async_session),
):
return {'updated_count': await Chats.mark_root_chats_read_by_user_id(user.id, db=db)}
return {
'updated_count': await Chats.mark_chats_read_by_user_id(user.id, db=db),
'folder_unread_counts': await get_folder_unread_counts(user.id, db=db),
}
############################
+7
View File
@@ -137,6 +137,7 @@
upsertChat?: (chat: Record<string, unknown>) => unknown;
setChatActive?: (chatId: string, active: boolean) => boolean;
setChatReadAt?: (chatId: string, lastReadAt: number) => boolean;
setAllChatsRead?: () => unknown;
}
> = {};
@@ -455,7 +456,13 @@
if (!res) return;
showChatsMenu = false;
if (res.folder_unread_counts) {
applyFolderUnreadCounts(res.folder_unread_counts);
}
setAllChatsRead();
for (const folder of Object.values(folderRegistry)) {
folder?.setAllChatsRead?.();
}
};
const importChatHandler = async (items, pinned = false, folderId = null) => {
@@ -392,6 +392,17 @@
return found;
}
return false;
},
setAllChatsRead: () => {
if (chats) {
chats = sortFolderChats(
chats.map((chat) =>
!chat.user_id || chat.user_id === $user?.id
? { ...chat, last_read_at: chat.updated_at }
: chat
)
);
}
}
};
if (folderElement) {