add APIChatRead chat command (#282)

This commit is contained in:
Efim Poberezkin
2022-02-08 17:27:43 +04:00
committed by GitHub
parent b3a4c21c4b
commit b06838b651
4 changed files with 36 additions and 1 deletions
+2
View File
@@ -88,6 +88,7 @@ data ChatCommand
| APIGetChat ChatType Int64 ChatPagination
| APIGetChatItems Int
| APISendMessage ChatType Int64 MsgContent
| APIChatRead ChatType Int64 (ChatItemId, ChatItemId)
| APIDeleteChat ChatType Int64
| APIAcceptContact Int64
| APIRejectContact Int64
@@ -134,6 +135,7 @@ data ChatResponse
| CRChatItemUpdated {chatItem :: AChatItem}
| CRMsgIntegrityError {msgerror :: MsgErrorType} -- TODO make it chat item to support in mobile
| CRCmdAccepted {corr :: CorrId}
| CRCmdOk
| CRChatHelp {helpSection :: HelpSection}
| CRWelcome {user :: User}
| CRGroupCreated {groupInfo :: GroupInfo}
+28 -1
View File
@@ -116,6 +116,8 @@ module Simplex.Chat.Store
getGroupChat,
getChatItemIdByAgentMsgId,
updateDirectChatItem,
updateDirectChatItemsRead,
updateGroupChatItemsRead,
)
where
@@ -2408,7 +2410,8 @@ updateDirectChatItem :: (StoreMonad m, MsgDirectionI d) => SQLiteStore -> ChatIt
updateDirectChatItem st itemId itemStatus =
liftIOEither . withTransaction st $ \db -> runExceptT $ do
ci <- ExceptT $ getDirectChatItem_ db itemId
liftIO $ DB.execute db "UPDATE chat_items SET item_status = ? WHERE chat_item_id = ?" (itemStatus, itemId)
currentTs <- liftIO getCurrentTime
liftIO $ DB.execute db "UPDATE chat_items SET item_status = ?, updated_at = ? WHERE chat_item_id = ?" (itemStatus, currentTs, itemId)
pure ci {meta = (meta ci) {itemStatus}}
getDirectChatItem_ :: forall d. MsgDirectionI d => DB.Connection -> ChatItemId -> IO (Either StoreError (ChatItem 'CTDirect d))
@@ -2433,6 +2436,30 @@ getDirectChatItem_ db itemId = do
correctDir :: CChatItem c -> Either StoreError (ChatItem c d)
correctDir (CChatItem _ ci) = first SEInternalError $ checkDirection ci
updateDirectChatItemsRead :: (StoreMonad m) => SQLiteStore -> Int64 -> (ChatItemId, ChatItemId) -> m ()
updateDirectChatItemsRead st contactId (fromItemId, toItemId) = do
currentTs <- liftIO getCurrentTime
liftIO . withTransaction st $ \db ->
DB.execute
db
[sql|
UPDATE chat_items SET item_status = ?, updated_at = ?
WHERE contact_id = ? AND chat_item_id >= ? AND chat_item_id <= ? AND item_sent = ?
|]
(CISRcvRead, currentTs, contactId, fromItemId, toItemId, SMDRcv)
updateGroupChatItemsRead :: (StoreMonad m) => SQLiteStore -> Int64 -> (ChatItemId, ChatItemId) -> m ()
updateGroupChatItemsRead st groupId (fromItemId, toItemId) = do
currentTs <- liftIO getCurrentTime
liftIO . withTransaction st $ \db ->
DB.execute
db
[sql|
UPDATE chat_items SET item_status = ?, updated_at = ?
WHERE group_id = ? AND chat_item_id >= ? AND chat_item_id <= ? AND item_sent = ?
|]
(CISRcvRead, currentTs, groupId, fromItemId, toItemId, SMDRcv)
type ChatItemRow = (Int64, ChatItemTs, ACIContent, Text, ACIStatus, UTCTime)
type MaybeChatItemRow = (Maybe Int64, Maybe ChatItemTs, Maybe ACIContent, Maybe Text, Maybe ACIStatus, Maybe UTCTime)
+1
View File
@@ -42,6 +42,7 @@ responseToView cmd = \case
CRChatItemUpdated _ -> []
CRMsgIntegrityError mErr -> viewMsgIntegrityError mErr
CRCmdAccepted _ -> r []
CRCmdOk -> r ["ok"]
CRChatHelp section -> case section of
HSMain -> r chatHelpInfo
HSFiles -> r filesHelpInfo