mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
core: return user unread counts on ListUsers command (#1763)
* core: return user unread counts on ListUsers command * split * tests * refactor * viewUserInfo * refactor * remove omit nothing * corrections * fix Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
This commit is contained in:
@@ -26,6 +26,7 @@ module Simplex.Chat.Store
|
||||
chatStoreFile,
|
||||
agentStoreFile,
|
||||
createUserRecord,
|
||||
getUsersInfo,
|
||||
getUsers,
|
||||
setActiveUser,
|
||||
getSetActiveUser,
|
||||
@@ -450,6 +451,19 @@ createUserRecord db (AgentUserId auId) Profile {displayName, fullName, image, pr
|
||||
DB.execute db "UPDATE users SET contact_id = ? WHERE user_id = ?" (contactId, userId)
|
||||
pure $ toUser (userId, auId, contactId, profileId, activeUser, displayName, fullName, image, userPreferences)
|
||||
|
||||
getUsersInfo :: DB.Connection -> IO [UserInfo]
|
||||
getUsersInfo db = getUsers db >>= mapM getUserInfo
|
||||
where
|
||||
getUserInfo :: User -> IO UserInfo
|
||||
getUserInfo user@User {userId} = do
|
||||
count_ <-
|
||||
maybeFirstRow fromOnly $
|
||||
DB.query
|
||||
db
|
||||
"SELECT COUNT(1) FROM chat_items WHERE user_id = ? AND item_status = ? GROUP BY user_id"
|
||||
(userId, CISRcvNew)
|
||||
pure UserInfo {user, unreadCount = fromMaybe 0 count_}
|
||||
|
||||
getUsers :: DB.Connection -> IO [User]
|
||||
getUsers db =
|
||||
map toUser <$> DB.query_ db userQuery
|
||||
|
||||
Reference in New Issue
Block a user