mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-23 19:23:36 +00:00
foldr
This commit is contained in:
1 parent
065cc170da
commit
fd5e5d295f
1 file changed
+8
-6
@@ -1086,15 +1086,12 @@ getDirectChatAround_ db user ct@Contact {contactId} aroundItemId count search =
|
|||||||
|
|
||||||
getDirectChatInitial_ :: DB.Connection -> User -> Contact -> Int -> ExceptT StoreError IO (Chat 'CTDirect, ChatLandingSection)
|
getDirectChatInitial_ :: DB.Connection -> User -> Contact -> Int -> ExceptT StoreError IO (Chat 'CTDirect, ChatLandingSection)
|
||||||
getDirectChatInitial_ db user@User {userId} ct@Contact {contactId} count = do
|
getDirectChatInitial_ db user@User {userId} ct@Contact {contactId} count = do
|
||||||
firstUnreadItem <- liftIO getDirectChatMinUnreadItemId_
|
firstUnreadItemId_ <- liftIO getDirectChatMinUnreadItemId_
|
||||||
case firstUnreadItem of
|
case firstUnreadItemId_ of
|
||||||
Just firstUnreadItemId -> do
|
Just firstUnreadItemId -> do
|
||||||
chat <- getDirectChatAround_ db user ct firstUnreadItemId count ""
|
chat <- getDirectChatAround_ db user ct firstUnreadItemId count ""
|
||||||
let Chat {chatItems} = chat
|
|
||||||
let chatItemIds = map (cchatItemId) chatItems
|
|
||||||
lastItemId <- liftIO $ getDirectChatItemIdsLast_ db user ct 1 ""
|
lastItemId <- liftIO $ getDirectChatItemIdsLast_ db user ct 1 ""
|
||||||
let lastItemIdInChat = head lastItemId `elem` chatItemIds
|
pure (chat, landingSection chat lastItemId)
|
||||||
pure (chat, if lastItemIdInChat then CLSLatest else CLSUnread)
|
|
||||||
Nothing -> liftIO $ (,CLSLatest) <$> getDirectChatLast_ db user ct count ""
|
Nothing -> liftIO $ (,CLSLatest) <$> getDirectChatLast_ db user ct count ""
|
||||||
where
|
where
|
||||||
getDirectChatMinUnreadItemId_ :: IO (Maybe ChatItemId)
|
getDirectChatMinUnreadItemId_ :: IO (Maybe ChatItemId)
|
||||||
@@ -1108,6 +1105,11 @@ getDirectChatInitial_ db user@User {userId} ct@Contact {contactId} count = do
|
|||||||
WHERE user_id = ? AND contact_id = ? AND item_status = ?
|
WHERE user_id = ? AND contact_id = ? AND item_status = ?
|
||||||
|]
|
|]
|
||||||
(userId, contactId, CISRcvNew)
|
(userId, contactId, CISRcvNew)
|
||||||
|
landingSection :: Chat 'CTDirect -> [ChatItemId] -> ChatLandingSection
|
||||||
|
landingSection Chat {chatItems} [lastItemId] = do
|
||||||
|
let lastItemIdInChat = foldr (\ci acc -> acc || cchatItemId ci == lastItemId) False chatItems
|
||||||
|
if lastItemIdInChat then CLSLatest else CLSUnread
|
||||||
|
landingSection _ _ = CLSUnread
|
||||||
|
|
||||||
getGroupChat :: DB.Connection -> VersionRangeChat -> User -> Int64 -> ChatPagination -> Maybe String -> ExceptT StoreError IO (Chat 'CTGroup, ChatLandingSection)
|
getGroupChat :: DB.Connection -> VersionRangeChat -> User -> Int64 -> ChatPagination -> Maybe String -> ExceptT StoreError IO (Chat 'CTGroup, ChatLandingSection)
|
||||||
getGroupChat db vr user groupId pagination search_ = do
|
getGroupChat db vr user groupId pagination search_ = do
|
||||||
|
|||||||
Reference in new issue
Block a user