From c3cd61aa467d7ea0fdf87fe936e2d46fce0a1935 Mon Sep 17 00:00:00 2001 From: IC Rainbow Date: Fri, 22 Dec 2023 18:19:35 +0200 Subject: [PATCH] remove interaction with messages --- src/Simplex/Chat.hs | 13 ++++++++----- src/Simplex/Chat/Messages.hs | 2 +- .../Chat/Migrations/M20231219_note_folders.hs | 2 -- src/Simplex/Chat/Store/Messages.hs | 14 ++++++-------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index e6bf7b9890..4a7756400e 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -764,10 +764,9 @@ processChatCommand = \case quoteData ChatItem {chatDir = CIGroupRcv m, content = CIRcvMsgContent qmc} _ = pure (qmc, CIQGroupRcv $ Just m, False, m) quoteData _ _ = throwChatError CEInvalidQuote CTLocal -> do - nf@NoteFolder {noteFolderId} <- withStore $ \db -> getNoteFolder db user chatId + nf <- withStore $ \db -> getNoteFolder db user chatId -- TODO: files, voice, etc. - msg <- createSndMessage (XMsgNew . MCSimple $ extMsgContent mc Nothing) (NoteFolderId noteFolderId) - ci <- saveSndChatItem user (CDLocalSnd nf) msg (CISndMsgContent mc) + ci <- createInternalChatItem_ user (CDLocalSnd nf) (CISndMsgContent mc) Nothing pure $ CRNewChatItem user (AChatItem SCTLocal SMDSnd (LocalChat nf) ci) CTContactRequest -> pure $ chatCmdError (Just user) "not supported" CTContactConnection -> pure $ chatCmdError (Just user) "not supported" @@ -5865,13 +5864,17 @@ sameGroupProfileInfo p p' = p {groupPreferences = Nothing} == p' {groupPreferenc createInternalChatItem :: forall c d m. (ChatTypeI c, MsgDirectionI d, ChatMonad m) => User -> ChatDirection c d -> CIContent d -> Maybe UTCTime -> m () createInternalChatItem user cd content itemTs_ = do + ci <- createInternalChatItem_ user cd content itemTs_ + toView $ CRNewChatItem user (AChatItem (chatTypeI @c) (msgDirection @d) (toChatInfo cd) ci) + +createInternalChatItem_ :: (MsgDirectionI d, ChatMonad m) => User -> ChatDirection c d -> CIContent d -> Maybe UTCTime -> m (ChatItem c d) +createInternalChatItem_ user cd content itemTs_ = do createdAt <- liftIO getCurrentTime let itemTs = fromMaybe createdAt itemTs_ ciId <- withStore' $ \db -> do when (ciRequiresAttention content) $ updateChatTs db user cd createdAt createNewChatItemNoMsg db user cd content itemTs createdAt - ci <- liftIO $ mkChatItem cd ciId content Nothing Nothing Nothing Nothing False itemTs Nothing createdAt - toView $ CRNewChatItem user (AChatItem (chatTypeI @c) (msgDirection @d) (toChatInfo cd) ci) + liftIO $ mkChatItem cd ciId content Nothing Nothing Nothing Nothing False itemTs Nothing createdAt getCreateActiveUser :: SQLiteStore -> Bool -> IO User getCreateActiveUser st testView = do diff --git a/src/Simplex/Chat/Messages.hs b/src/Simplex/Chat/Messages.hs index 284333fdd8..334d482c49 100644 --- a/src/Simplex/Chat/Messages.hs +++ b/src/Simplex/Chat/Messages.hs @@ -831,7 +831,7 @@ data PendingGroupMessage = PendingGroupMessage type MessageId = Int64 -data ConnOrGroupId = ConnectionId Int64 | GroupId Int64 | NoteFolderId Int64 +data ConnOrGroupId = ConnectionId Int64 | GroupId Int64 data SndMsgDelivery = SndMsgDelivery { connId :: Int64, diff --git a/src/Simplex/Chat/Migrations/M20231219_note_folders.hs b/src/Simplex/Chat/Migrations/M20231219_note_folders.hs index 3baf074bb3..c98a106c7d 100644 --- a/src/Simplex/Chat/Migrations/M20231219_note_folders.hs +++ b/src/Simplex/Chat/Migrations/M20231219_note_folders.hs @@ -30,7 +30,6 @@ m20231219_note_folders = ); ALTER TABLE chat_items ADD COLUMN note_folder_id INTEGER DEFAULT NULL REFERENCES note_folders ON DELETE CASCADE; - ALTER TABLE messages ADD COLUMN note_folder_id INTEGER DEFAULT NULL REFERENCES note_folders ON DELETE CASCADE; ALTER TABLE chat_item_reactions ADD COLUMN note_folder_id INTEGER DEFAULT NULL REFERENCES note_folders ON DELETE CASCADE; |] @@ -40,6 +39,5 @@ down_m20231219_note_folders = DROP INDEX idx_note_folders_user_id_local_display_name; DROP TABLE note_folders; ALTER TABLE chat_items DROP COLUMN note_folder_id; -ALTER TABLE messages DROP COLUMN note_folder_id; ALTER TABLE chat_item_reactions DROP COLUMN note_folder_id; |] diff --git a/src/Simplex/Chat/Store/Messages.hs b/src/Simplex/Chat/Store/Messages.hs index f6a6f62355..7dd541150b 100644 --- a/src/Simplex/Chat/Store/Messages.hs +++ b/src/Simplex/Chat/Store/Messages.hs @@ -170,18 +170,17 @@ createNewSndMessage db gVar connOrGroupId mkMessage = db [sql| INSERT INTO messages ( - msg_sent, chat_msg_event, msg_body, connection_id, group_id, note_folder_id, + msg_sent, chat_msg_event, msg_body, connection_id, group_id, shared_msg_id, shared_msg_id_user, created_at, updated_at - ) VALUES (?,?,?,?,?,?,?,?,?,?) + ) VALUES (?,?,?,?,?,?,?,?,?) |] - (MDSnd, toCMEventTag chatMsgEvent, msgBody, connId_, groupId_, folderId_, sharedMsgId, Just True, createdAt, createdAt) + (MDSnd, toCMEventTag chatMsgEvent, msgBody, connId_, groupId_, sharedMsgId, Just True, createdAt, createdAt) msgId <- insertedRowId db pure SndMessage {msgId, sharedMsgId = SharedMsgId sharedMsgId, msgBody} where - (connId_, groupId_, folderId_) = case connOrGroupId of - ConnectionId connId -> (Just connId, Nothing, Nothing) - GroupId groupId -> (Nothing, Just groupId, Nothing) - NoteFolderId folderId -> (Nothing, Nothing, Just folderId) + (connId_, groupId_) = case connOrGroupId of + ConnectionId connId -> (Just connId, Nothing) + GroupId groupId -> (Nothing, Just groupId) createSndMsgDelivery :: DB.Connection -> SndMsgDelivery -> MessageId -> IO Int64 createSndMsgDelivery db sndMsgDelivery messageId = do @@ -214,7 +213,6 @@ createNewRcvMessage db connOrGroupId NewMessage {chatMsgEvent, msgBody} sharedMs throwError $ SEDuplicateGroupMessage groupId sharedMsgId duplAuthorId duplFwdMemberId Nothing -> liftIO $ insertRcvMsg Nothing $ Just groupId Nothing -> liftIO $ insertRcvMsg Nothing $ Just groupId - NoteFolderId _folderId -> error "TODO: createNewRcvMessage.NoteFolderId" where duplicateGroupMsgMemberIds :: Int64 -> SharedMsgId -> IO (Maybe (Maybe GroupMemberId, Maybe GroupMemberId)) duplicateGroupMsgMemberIds groupId sharedMsgId =