core: mark all user messages read (#3530)
This commit is contained in:
parent
2f7632a70f
commit
f65b8a9e78
@ -937,6 +937,8 @@ processChatCommand = \case
|
|||||||
throwChatError (CECommandError $ "reaction already " <> if add then "added" else "removed")
|
throwChatError (CECommandError $ "reaction already " <> if add then "added" else "removed")
|
||||||
when (add && length rs >= maxMsgReactions) $
|
when (add && length rs >= maxMsgReactions) $
|
||||||
throwChatError (CECommandError "too many reactions")
|
throwChatError (CECommandError "too many reactions")
|
||||||
|
APIUserRead userId -> withUserId userId $ \user -> withStore' (`setUserChatsRead` user) >> ok user
|
||||||
|
UserRead -> withUser $ \User {userId} -> processChatCommand $ APIUserRead userId
|
||||||
APIChatRead (ChatRef cType chatId) fromToIds -> withUser $ \_ -> case cType of
|
APIChatRead (ChatRef cType chatId) fromToIds -> withUser $ \_ -> case cType of
|
||||||
CTDirect -> do
|
CTDirect -> do
|
||||||
user <- withStore $ \db -> getUserByContactId db chatId
|
user <- withStore $ \db -> getUserByContactId db chatId
|
||||||
@ -5989,6 +5991,8 @@ chatCommandP =
|
|||||||
"/_delete item " *> (APIDeleteChatItem <$> chatRefP <* A.space <*> A.decimal <* A.space <*> ciDeleteMode),
|
"/_delete item " *> (APIDeleteChatItem <$> chatRefP <* A.space <*> A.decimal <* A.space <*> ciDeleteMode),
|
||||||
"/_delete member item #" *> (APIDeleteMemberChatItem <$> A.decimal <* A.space <*> A.decimal <* A.space <*> A.decimal),
|
"/_delete member item #" *> (APIDeleteMemberChatItem <$> A.decimal <* A.space <*> A.decimal <* A.space <*> A.decimal),
|
||||||
"/_reaction " *> (APIChatItemReaction <$> chatRefP <* A.space <*> A.decimal <* A.space <*> onOffP <* A.space <*> jsonP),
|
"/_reaction " *> (APIChatItemReaction <$> chatRefP <* A.space <*> A.decimal <* A.space <*> onOffP <* A.space <*> jsonP),
|
||||||
|
"/_read user " *> (APIUserRead <$> A.decimal),
|
||||||
|
"/read user" $> UserRead,
|
||||||
"/_read chat " *> (APIChatRead <$> chatRefP <*> optional (A.space *> ((,) <$> ("from=" *> A.decimal) <* A.space <*> ("to=" *> A.decimal)))),
|
"/_read chat " *> (APIChatRead <$> chatRefP <*> optional (A.space *> ((,) <$> ("from=" *> A.decimal) <* A.space <*> ("to=" *> A.decimal)))),
|
||||||
"/_unread chat " *> (APIChatUnread <$> chatRefP <* A.space <*> onOffP),
|
"/_unread chat " *> (APIChatUnread <$> chatRefP <* A.space <*> onOffP),
|
||||||
"/_delete " *> (APIDeleteChat <$> chatRefP <*> (A.space *> "notify=" *> onOffP <|> pure True)),
|
"/_delete " *> (APIDeleteChat <$> chatRefP <*> (A.space *> "notify=" *> onOffP <|> pure True)),
|
||||||
|
@ -256,6 +256,8 @@ data ChatCommand
|
|||||||
| APIDeleteChatItem ChatRef ChatItemId CIDeleteMode
|
| APIDeleteChatItem ChatRef ChatItemId CIDeleteMode
|
||||||
| APIDeleteMemberChatItem GroupId GroupMemberId ChatItemId
|
| APIDeleteMemberChatItem GroupId GroupMemberId ChatItemId
|
||||||
| APIChatItemReaction {chatRef :: ChatRef, chatItemId :: ChatItemId, add :: Bool, reaction :: MsgReaction}
|
| APIChatItemReaction {chatRef :: ChatRef, chatItemId :: ChatItemId, add :: Bool, reaction :: MsgReaction}
|
||||||
|
| APIUserRead UserId
|
||||||
|
| UserRead
|
||||||
| APIChatRead ChatRef (Maybe (ChatItemId, ChatItemId))
|
| APIChatRead ChatRef (Maybe (ChatItemId, ChatItemId))
|
||||||
| APIChatUnread ChatRef Bool
|
| APIChatUnread ChatRef Bool
|
||||||
| APIDeleteChat ChatRef Bool -- `notify` flag is only applied to direct chats
|
| APIDeleteChat ChatRef Bool -- `notify` flag is only applied to direct chats
|
||||||
|
@ -43,6 +43,7 @@ module Simplex.Chat.Store.Direct
|
|||||||
deletePCCIncognitoProfile,
|
deletePCCIncognitoProfile,
|
||||||
updateContactUsed,
|
updateContactUsed,
|
||||||
updateContactUnreadChat,
|
updateContactUnreadChat,
|
||||||
|
setUserChatsRead,
|
||||||
updateContactStatus,
|
updateContactStatus,
|
||||||
updateGroupUnreadChat,
|
updateGroupUnreadChat,
|
||||||
setConnectionVerified,
|
setConnectionVerified,
|
||||||
@ -78,6 +79,7 @@ import Data.Text (Text)
|
|||||||
import Data.Time.Clock (UTCTime (..), getCurrentTime)
|
import Data.Time.Clock (UTCTime (..), getCurrentTime)
|
||||||
import Database.SQLite.Simple (NamedParam (..), Only (..), (:.) (..))
|
import Database.SQLite.Simple (NamedParam (..), Only (..), (:.) (..))
|
||||||
import Database.SQLite.Simple.QQ (sql)
|
import Database.SQLite.Simple.QQ (sql)
|
||||||
|
import Simplex.Chat.Messages
|
||||||
import Simplex.Chat.Store.Shared
|
import Simplex.Chat.Store.Shared
|
||||||
import Simplex.Chat.Types
|
import Simplex.Chat.Types
|
||||||
import Simplex.Chat.Types.Preferences
|
import Simplex.Chat.Types.Preferences
|
||||||
@ -392,6 +394,13 @@ updateContactUnreadChat db User {userId} Contact {contactId} unreadChat = do
|
|||||||
updatedAt <- getCurrentTime
|
updatedAt <- getCurrentTime
|
||||||
DB.execute db "UPDATE contacts SET unread_chat = ?, updated_at = ? WHERE user_id = ? AND contact_id = ?" (unreadChat, updatedAt, userId, contactId)
|
DB.execute db "UPDATE contacts SET unread_chat = ?, updated_at = ? WHERE user_id = ? AND contact_id = ?" (unreadChat, updatedAt, userId, contactId)
|
||||||
|
|
||||||
|
setUserChatsRead :: DB.Connection -> User -> IO ()
|
||||||
|
setUserChatsRead db User {userId} = do
|
||||||
|
updatedAt <- getCurrentTime
|
||||||
|
DB.execute db "UPDATE contacts SET unread_chat = ?, updated_at = ? WHERE user_id = ? AND unread_chat = ?" (False, updatedAt, userId, True)
|
||||||
|
DB.execute db "UPDATE groups SET unread_chat = ?, updated_at = ? WHERE user_id = ? AND unread_chat = ?" (False, updatedAt, userId, True)
|
||||||
|
DB.execute db "UPDATE chat_items SET item_status = ?, updated_at = ? WHERE user_id = ? AND item_status = ?" (CISRcvRead, updatedAt, userId, CISRcvNew)
|
||||||
|
|
||||||
updateContactStatus :: DB.Connection -> User -> Contact -> ContactStatus -> IO Contact
|
updateContactStatus :: DB.Connection -> User -> Contact -> ContactStatus -> IO Contact
|
||||||
updateContactStatus db User {userId} ct@Contact {contactId} contactStatus = do
|
updateContactStatus db User {userId} ct@Contact {contactId} contactStatus = do
|
||||||
currentTs <- getCurrentTime
|
currentTs <- getCurrentTime
|
||||||
|
@ -175,6 +175,8 @@ testAddContact = versionTestMatrix2 runTestAddContact
|
|||||||
bob #$> ("/_read chat @2 from=1 to=100", id, "ok")
|
bob #$> ("/_read chat @2 from=1 to=100", id, "ok")
|
||||||
alice #$> ("/_read chat @2", id, "ok")
|
alice #$> ("/_read chat @2", id, "ok")
|
||||||
bob #$> ("/_read chat @2", id, "ok")
|
bob #$> ("/_read chat @2", id, "ok")
|
||||||
|
alice #$> ("/read user", id, "ok")
|
||||||
|
alice #$> ("/_read user 1", id, "ok")
|
||||||
|
|
||||||
testDuplicateContactsSeparate :: HasCallStack => FilePath -> IO ()
|
testDuplicateContactsSeparate :: HasCallStack => FilePath -> IO ()
|
||||||
testDuplicateContactsSeparate =
|
testDuplicateContactsSeparate =
|
||||||
|
Loading…
Reference in New Issue
Block a user