diff --git a/src/Simplex/Chat/Library/Commands.hs b/src/Simplex/Chat/Library/Commands.hs index 3fb67efe83..4f09da675f 100644 --- a/src/Simplex/Chat/Library/Commands.hs +++ b/src/Simplex/Chat/Library/Commands.hs @@ -1746,7 +1746,7 @@ processChatCommand' vr = \case groupProfile = businessGroupProfile profile groupPreferences (gInfo, hostMember) <- withStore $ \db -> createPreparedGroup db vr user groupProfile True ccLink welcomeSharedMsgId let cd = CDGroupRcv gInfo Nothing hostMember - createItem sharedMsgId content = createInternalItemForChat user cd True content sharedMsgId Nothing + createItem sharedMsgId content = createChatItem user cd True content sharedMsgId Nothing cInfo = GroupChat gInfo Nothing void $ createGroupFeatureItems_ user cd True CIRcvGroupFeature gInfo aci <- mapM (createItem welcomeSharedMsgId . CIRcvMsgContent . MCText) message @@ -1756,7 +1756,7 @@ processChatCommand' vr = \case pure $ CRNewPreparedChat user $ AChat SCTGroup chat ACCL _ (CCLink cReq _) -> do ct <- withStore $ \db -> createPreparedContact db user profile accLink welcomeSharedMsgId - let createItem sharedMsgId content = createInternalItemForChat user (CDDirectRcv ct) False content sharedMsgId Nothing + let createItem sharedMsgId content = createChatItem user (CDDirectRcv ct) False content sharedMsgId Nothing cInfo = DirectChat ct void $ createItem Nothing $ CIRcvDirectE2EEInfo $ E2EInfo $ connRequestPQEncryption cReq void $ createFeatureEnabledItems_ user ct @@ -1769,7 +1769,7 @@ processChatCommand' vr = \case let GroupShortLinkData {groupProfile = gp@GroupProfile {description}} = groupSLinkData (gInfo, hostMember) <- withStore $ \db -> createPreparedGroup db vr user gp False ccLink Nothing let cd = CDGroupRcv gInfo Nothing hostMember - createItem content = createInternalItemForChat user cd True content Nothing Nothing + createItem content = createChatItem user cd True content Nothing Nothing cInfo = GroupChat gInfo Nothing void $ createGroupFeatureItems_ user cd True CIRcvGroupFeature gInfo aci <- mapM (createItem . CIRcvMsgContent . MCText) description @@ -1813,8 +1813,9 @@ processChatCommand' vr = \case CRSentInvitation {customUserProfile} -> do -- get updated contact with connection ct' <- withFastStore $ \db -> getContact db vr user contactId - forM_ msg_ $ \(sharedMsgId, mc) -> - createInternalItemForChat user (CDDirectSnd ct') False (CISndMsgContent mc) (Just sharedMsgId) Nothing + forM_ msg_ $ \(sharedMsgId, mc) -> do + ci <- createChatItem user (CDDirectSnd ct') False (CISndMsgContent mc) (Just sharedMsgId) Nothing + toView $ CEvtNewChatItems user [ci] pure $ CRStartedConnectionToContact user ct' customUserProfile cr -> pure cr APIConnectPreparedGroup groupId incognito msgContent_ -> withUser $ \user -> do diff --git a/src/Simplex/Chat/Library/Internal.hs b/src/Simplex/Chat/Library/Internal.hs index 7e9ee4866a..1df08c6171 100644 --- a/src/Simplex/Chat/Library/Internal.hs +++ b/src/Simplex/Chat/Library/Internal.hs @@ -2289,7 +2289,7 @@ createFeatureEnabledItems_ :: User -> Contact -> CM [AChatItem] createFeatureEnabledItems_ user ct@Contact {mergedPreferences} = forM allChatFeatures $ \(ACF f) -> do let state = featureState $ getContactUserPreference f mergedPreferences - createInternalItemForChat user (CDDirectRcv ct) False (uncurry (CIRcvChatFeature $ chatFeature f) state) Nothing Nothing + createChatItem user (CDDirectRcv ct) False (uncurry (CIRcvChatFeature $ chatFeature f) state) Nothing Nothing createFeatureItems :: MsgDirectionI d => @@ -2315,7 +2315,7 @@ createContactsFeatureItems :: CM' () createContactsFeatureItems user cts chatDir ciFeature ciOffer getPref = do let dirsCIContents = map contactChangedFeatures cts - (errs, acis) <- partitionEithers <$> createInternalItemsForChats user Nothing dirsCIContents + (errs, acis) <- partitionEithers <$> createChatItems user Nothing dirsCIContents unless (null errs) $ toView' $ CEvtChatErrors errs toView' $ CEvtNewChatItems user acis where @@ -2360,30 +2360,30 @@ createGroupFeatureItems_ user cd showGroupAsSender ciContent GroupInfo {fullGrou forM allGroupFeatures $ \(AGF f) -> do let p = getGroupPreference f fullGroupPreferences (_, param, role) = groupFeatureState p - createInternalItemForChat user cd showGroupAsSender (ciContent (toGroupFeature f) (toGroupPreference p) param role) Nothing Nothing + createChatItem user cd showGroupAsSender (ciContent (toGroupFeature f) (toGroupPreference p) param role) Nothing Nothing createInternalChatItem :: (ChatTypeI c, MsgDirectionI d) => User -> ChatDirection c d -> CIContent d -> Maybe UTCTime -> CM () createInternalChatItem user cd content itemTs_ = do - ci <- createInternalItemForChat user cd False content Nothing itemTs_ + ci <- createChatItem user cd False content Nothing itemTs_ toView $ CEvtNewChatItems user [ci] -createInternalItemForChat :: (ChatTypeI c, MsgDirectionI d) => User -> ChatDirection c d -> ShowGroupAsSender -> CIContent d -> Maybe SharedMsgId -> Maybe UTCTime -> CM AChatItem -createInternalItemForChat user cd showGroupAsSender content sharedMsgId itemTs_ = - lift (createInternalItemsForChats user itemTs_ [(cd, showGroupAsSender, [(content, sharedMsgId)])]) >>= \case +createChatItem :: (ChatTypeI c, MsgDirectionI d) => User -> ChatDirection c d -> ShowGroupAsSender -> CIContent d -> Maybe SharedMsgId -> Maybe UTCTime -> CM AChatItem +createChatItem user cd showGroupAsSender content sharedMsgId itemTs_ = + lift (createChatItems user itemTs_ [(cd, showGroupAsSender, [(content, sharedMsgId)])]) >>= \case [Right ci] -> pure ci [Left e] -> throwError e rs -> throwChatError $ CEInternalError $ "createInternalChatItem: expected 1 result, got " <> show (length rs) -- Supports items with shared msg ID that are created for all conversation parties, but were not communicated via the usual messages. -- This includes address welcome message and contact request message. -createInternalItemsForChats :: +createChatItems :: forall c d. (ChatTypeI c, MsgDirectionI d) => User -> Maybe UTCTime -> [(ChatDirection c d, ShowGroupAsSender, [(CIContent d, Maybe SharedMsgId)])] -> CM' [Either ChatError AChatItem] -createInternalItemsForChats user itemTs_ dirsCIContents = do +createChatItems user itemTs_ dirsCIContents = do createdAt <- liftIO getCurrentTime let itemTs = fromMaybe createdAt itemTs_ vr <- chatVersionRange' diff --git a/src/Simplex/Chat/Library/Subscriber.hs b/src/Simplex/Chat/Library/Subscriber.hs index b0ed8fea44..8b399c81ab 100644 --- a/src/Simplex/Chat/Library/Subscriber.hs +++ b/src/Simplex/Chat/Library/Subscriber.hs @@ -1253,7 +1253,7 @@ processAgentMessageConn vr user@User {userId} corrId agentConnId agentMessage = if newRequest then do -- TODO [short links] save sharedMsgId instead of the last Nothing - let createItem content = createInternalItemForChat user (CDDirectRcv ct) False content Nothing Nothing + let createItem content = createChatItem user (CDDirectRcv ct) False content Nothing Nothing void $ createItem $ CIRcvDirectE2EEInfo $ E2EInfo $ Just $ CR.pqSupportToEnc $ reqPQSup void $ createFeatureEnabledItems_ user ct -- TODO [short links] save sharedMsgId