diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index 3987250fa0..6d3a96b97b 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -869,7 +869,7 @@ processChatCommand = \case else pure $ CRChatItemNotChanged user (AChatItem SCTGroup SMDSnd (GroupChat gInfo) ci) _ -> throwChatError CEInvalidChatItemUpdate CChatItem SMDRcv _ -> throwChatError CEInvalidChatItemUpdate - CTLocal -> pure $ chatCmdError (Just user) "TODO: update local" + CTLocal -> pure $ chatCmdError (Just user) "TODO: APIUpdateChatItem.CTLocal" CTContactRequest -> pure $ chatCmdError (Just user) "not supported" CTContactConnection -> pure $ chatCmdError (Just user) "not supported" APIDeleteChatItem (ChatRef cType chatId) itemId mode -> withUser $ \user -> withChatLock "deleteChatItem" $ case cType of @@ -947,7 +947,7 @@ processChatCommand = \case r = ACIReaction SCTGroup SMDSnd (GroupChat g) $ CIReaction CIGroupSnd ci' createdAt reaction pure $ CRChatItemReaction user add r _ -> throwChatError $ CECommandError "reaction not possible - no shared item ID" - CTLocal -> pure $ chatCmdError (Just user) "TODO: note reactions" + CTLocal -> pure $ chatCmdError (Just user) "TODO: APIChatItemReaction.CTLocal" CTContactRequest -> pure $ chatCmdError (Just user) "not supported" CTContactConnection -> pure $ chatCmdError (Just user) "not supported" where @@ -2118,13 +2118,13 @@ processChatCommand = \case getSentChatItemIdByText user@User {userId, localDisplayName} (ChatRef cType cId) msg = case cType of CTDirect -> withStore $ \db -> getDirectChatItemIdByText db userId cId SMDSnd msg CTGroup -> withStore $ \db -> getGroupChatItemIdByText db user cId (Just localDisplayName) msg - CTLocal -> withStore $ \db -> error "TODO: getSentChatItemIdByText.CTLocal" + CTLocal -> withStore $ \db -> getLocalChatItemIdByText db user cId SMDSnd msg _ -> throwChatError $ CECommandError "not supported" getChatItemIdByText :: User -> ChatRef -> Text -> m Int64 getChatItemIdByText user (ChatRef cType cId) msg = case cType of CTDirect -> withStore $ \db -> getDirectChatItemIdByText' db user cId msg CTGroup -> withStore $ \db -> getGroupChatItemIdByText' db user cId msg - CTLocal -> withStore $ \db -> error "TODO: getChatItemIdByText.CTLocal" + CTLocal -> withStore $ \db -> getLocalChatItemIdByText' db user cId msg _ -> throwChatError $ CECommandError "not supported" connectViaContact :: User -> IncognitoEnabled -> ConnectionRequestUri 'CMContact -> m ChatResponse connectViaContact user@User {userId} incognito cReq@(CRContactUri ConnReqUriData {crClientData}) = withChatLock "connectViaContact" $ do diff --git a/src/Simplex/Chat/Store/Messages.hs b/src/Simplex/Chat/Store/Messages.hs index 2004ab2388..6a7c8f16e4 100644 --- a/src/Simplex/Chat/Store/Messages.hs +++ b/src/Simplex/Chat/Store/Messages.hs @@ -84,6 +84,8 @@ module Simplex.Chat.Store.Messages getDirectChatItemIdByText', getGroupChatItemIdByText, getGroupChatItemIdByText', + getLocalChatItemIdByText, + getLocalChatItemIdByText', getChatItemByFileId, getChatItemByGroupId, updateDirectChatItemStatus, @@ -1903,6 +1905,34 @@ getLocalChatItem db User {userId} folderId itemId = ExceptT $ do |] (userId, folderId, itemId) +getLocalChatItemIdByText :: DB.Connection -> User -> NoteFolderId -> SMsgDirection d -> Text -> ExceptT StoreError IO ChatItemId +getLocalChatItemIdByText db User {userId} noteFolderId msgDir quotedMsg = + ExceptT . firstRow fromOnly (SEChatItemNotFoundByText quotedMsg) $ + DB.query + db + [sql| + SELECT chat_item_id + FROM chat_items + WHERE user_id = ? AND note_folder_id = ? AND item_sent = ? AND item_text LIKE ? + ORDER BY chat_item_id DESC + LIMIT 1 + |] + (userId, noteFolderId, msgDir, quotedMsg <> "%") + +getLocalChatItemIdByText' :: DB.Connection -> User -> NoteFolderId -> Text -> ExceptT StoreError IO ChatItemId +getLocalChatItemIdByText' db User {userId} noteFolderId msg = + ExceptT . firstRow fromOnly (SEChatItemNotFoundByText msg) $ + DB.query + db + [sql| + SELECT chat_item_id + FROM chat_items + WHERE user_id = ? AND note_folder_id = ? AND item_text LIKE ? + ORDER BY chat_item_id DESC + LIMIT 1 + |] + (userId, noteFolderId, msg <> "%") + deleteLocalChatItem :: DB.Connection -> User -> NoteFolder -> ChatItem 'CTLocal d -> IO () deleteLocalChatItem db User {userId} NoteFolder {noteFolderId} ci = do let itemId = chatItemId' ci