From d4a88000bbb3e5f983c6d6dc91ec3db6289e1e48 Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Sat, 12 Sep 2026 12:02:59 +0000 Subject: [PATCH] fix, add option to include feed in list of chats (off) --- plans/2026-09-04-feed-broadcast-chat.md | 2 ++ src/Simplex/Chat.hs | 1 + src/Simplex/Chat/Controller.hs | 1 + src/Simplex/Chat/Library/Commands.hs | 6 +++-- src/Simplex/Chat/Library/Internal.hs | 2 +- src/Simplex/Chat/Library/Subscriber.hs | 10 +++++--- src/Simplex/Chat/Store/Messages.hs | 6 ++--- tests/ChatClient.hs | 1 + tests/ChatTests/Feed.hs | 33 +++++++++++++++++++++++++ 9 files changed, 52 insertions(+), 10 deletions(-) diff --git a/plans/2026-09-04-feed-broadcast-chat.md b/plans/2026-09-04-feed-broadcast-chat.md index 2e5918277b..84c1cbcf7a 100644 --- a/plans/2026-09-04-feed-broadcast-chat.md +++ b/plans/2026-09-04-feed-broadcast-chat.md @@ -27,6 +27,8 @@ implementing: `SELECT` inside the fields fragment as `groupInfoQueryFields` does. - Tests create the feed with `createCCFeed` (as `createCCNoteFolder`), since test users are created by `createUserRecordAt` directly. +- `APIGetChats` includes the feed chat only under `ChatConfig {showFeedChat = True}`, + off by default until the apps render it; the feed tests turn it on. Written of the Tests section: `tests/ChatTests/Feed.hs` — a broadcast with `feedBucketSize = 1` to two contacts and two customer business groups, so diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index a225471eaf..d820359c25 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -121,6 +121,7 @@ defaultChatConfig = deliveryWorkerDelay = 0, deliveryBucketSize = 10000, feedBucketSize = 1000, + showFeedChat = False, webPreviewConfig = Nothing, channelSubscriberRole = GRObserver, relayChecksInterval = 15 * 60, -- 15 minutes diff --git a/src/Simplex/Chat/Controller.hs b/src/Simplex/Chat/Controller.hs index 1d8a8f9cbf..80b1d0b423 100644 --- a/src/Simplex/Chat/Controller.hs +++ b/src/Simplex/Chat/Controller.hs @@ -166,6 +166,7 @@ data ChatConfig = ChatConfig deliveryWorkerDelay :: Int64, -- microseconds deliveryBucketSize :: Int, feedBucketSize :: Int, + showFeedChat :: Bool, webPreviewConfig :: Maybe WebPreviewConfig, channelSubscriberRole :: GroupMemberRole, -- TODO [relays] starting role should be communicated in protocol from owner to relays relayChecksInterval :: NominalDiffTime, diff --git a/src/Simplex/Chat/Library/Commands.hs b/src/Simplex/Chat/Library/Commands.hs index ece864ae14..d961ebf16b 100644 --- a/src/Simplex/Chat/Library/Commands.hs +++ b/src/Simplex/Chat/Library/Commands.hs @@ -654,7 +654,8 @@ processChatCommand cxt nm = \case tags <- withFastStore' (`getUserChatTags` user) pure $ CRChatTags user tags APIGetChats {userId, pendingConnections, pagination, query} -> withUserId' userId $ \user -> do - (errs, previews) <- partitionEithers <$> withFastStore' (\db -> getChatPreviews db cxt user pendingConnections pagination query) + withFeed <- asks $ showFeedChat . config + (errs, previews) <- partitionEithers <$> withFastStore' (\db -> getChatPreviews db cxt user pendingConnections withFeed pagination query) unless (null errs) $ toView $ CEvtChatErrors (map ChatErrorStore errs) pure $ CRApiChats user previews APIGetChat (ChatRef cType cId scope_) contentFilter pagination search -> withUser $ \user -> case cType of @@ -3509,7 +3510,8 @@ processChatCommand cxt nm = \case processChatCommand cxt nm $ APIClearChat (ChatRef CTLocal folderId Nothing) LastChats count_ -> withUser' $ \user -> do let count = fromMaybe 5000 count_ - (errs, previews) <- partitionEithers <$> withFastStore' (\db -> getChatPreviews db cxt user False (PTLast count) clqNoFilters) + withFeed <- asks $ showFeedChat . config + (errs, previews) <- partitionEithers <$> withFastStore' (\db -> getChatPreviews db cxt user False withFeed (PTLast count) clqNoFilters) unless (null errs) $ toView $ CEvtChatErrors (map ChatErrorStore errs) pure $ CRChats previews LastMessages (Just chatName) count search -> withUser $ \user -> do diff --git a/src/Simplex/Chat/Library/Internal.hs b/src/Simplex/Chat/Library/Internal.hs index 1d37305551..b1de1acdb0 100644 --- a/src/Simplex/Chat/Library/Internal.hs +++ b/src/Simplex/Chat/Library/Internal.hs @@ -57,6 +57,7 @@ import Simplex.Chat.Badges (BadgeCredential (..), ProofPresHeader (..), BadgePro import Simplex.Chat.Names (SimplexDomainClaim (..), claimDomain) import Simplex.Chat.Call import Simplex.Chat.Controller +import Simplex.Chat.Delivery (FeedJobAction (..)) import Simplex.Chat.Files import Simplex.Chat.Markdown import Simplex.Chat.Messages @@ -66,7 +67,6 @@ import Simplex.Chat.Messages.CIContent.Events import Simplex.Chat.Operators import Simplex.Chat.ProfileGenerator (generateRandomProfile) import Simplex.Chat.Protocol -import Simplex.Chat.Delivery (FeedJobAction (..)) import Simplex.Chat.Store import Simplex.Chat.Store.ContactRequest import Simplex.Chat.Store.Direct diff --git a/src/Simplex/Chat/Library/Subscriber.hs b/src/Simplex/Chat/Library/Subscriber.hs index c1bfb3d33f..d6d52b1283 100644 --- a/src/Simplex/Chat/Library/Subscriber.hs +++ b/src/Simplex/Chat/Library/Subscriber.hs @@ -2244,7 +2244,6 @@ processAgentMessageConn cxt user@User {userId} corrId agentConnId agentMessage = groupMessageUpdate gInfo@GroupInfo {groupId, chatSettings} m_ sharedMsgId mc mentions msgScope_ msg@RcvMessage {msgId, msgSigned, signedMsg_, signedByGMId_} brokerTs ttl_ live_ asGroup_ feed_ | Just m <- m_, prohibitedSimplexLinks gInfo m mc ft_ = messageWarning ("x.msg.update ignored: feature not allowed " <> groupFeatureNameText GFSimplexLinks) $> Nothing - | dropsFeed chatSettings feed_ = pure Nothing | otherwise = do updateRcvChatItem `catchCINotFound` \_ -> do -- This patches initial sharedMsgId into chat item when locally deleted chat item @@ -2253,9 +2252,11 @@ processAgentMessageConn cxt user@User {userId} corrId agentConnId agentMessage = let itemTTL' = if feed_ == Just True then join (groupTimedTTL gInfo) else ttl_ timed_ = rcvGroupCITimed gInfo itemTTL' showGroupAsSender = fromMaybe (isNothing m_) asGroup_ - if showGroupAsSender && maybe False (\m -> memberRole' m < GROwner) m_ - then messageError "x.msg.update: member attempted to update as group" $> Nothing - else do + if + | dropsFeed chatSettings feed_ -> pure Nothing + | showGroupAsSender && maybe False (\m -> memberRole' m < GROwner) m_ -> + messageError "x.msg.update: member attempted to update as group" $> Nothing + | otherwise -> do (gInfo', chatDir, mentions', scopeInfo) <- if showGroupAsSender then pure (gInfo, CDChannelRcv gInfo Nothing, mentions, Nothing) @@ -4388,6 +4389,7 @@ runDeliveryJobWorker a deliveryKey Worker {doWork} = do Nothing -> VRValue Nothing msgBody -- sending to one member, do not reference body Just 1 -> VRValue (Just 1) msgBody Just _ -> VRRef 1 + runFeedJobWorker :: AgentClient -> FeedJobKey -> Worker -> CM () runFeedJobWorker a feedKey@(feedId, scope) Worker {doWork} = do delay <- asks $ deliveryWorkerDelay . config diff --git a/src/Simplex/Chat/Store/Messages.hs b/src/Simplex/Chat/Store/Messages.hs index 22b46079e4..6969eb3da6 100644 --- a/src/Simplex/Chat/Store/Messages.hs +++ b/src/Simplex/Chat/Store/Messages.hs @@ -773,12 +773,12 @@ getChatItemQuote_ db User {userId, userContactId} chatDirection QuotedMsg {msgRe ciQuoteGroup [] = ciQuote Nothing $ CIQGroupRcv Nothing ciQuoteGroup ((Only itemId :. memberRow) : _) = ciQuote itemId . CIQGroupRcv . Just $ toGroupMember currentTs userContactId memberRow -getChatPreviews :: DB.Connection -> StoreCxt -> User -> Bool -> PaginationByTime -> ChatListQuery -> IO [Either StoreError AChat] -getChatPreviews db cxt user withPCC pagination query = do +getChatPreviews :: DB.Connection -> StoreCxt -> User -> Bool -> Bool -> PaginationByTime -> ChatListQuery -> IO [Either StoreError AChat] +getChatPreviews db cxt user withPCC withFeed pagination query = do directChats <- findDirectChatPreviews_ db user pagination query groupChats <- findGroupChatPreviews_ db user pagination query localChats <- findLocalChatPreviews_ db user pagination query - feedChats <- findFeedChatPreviews_ db user pagination query + feedChats <- if withFeed then findFeedChatPreviews_ db user pagination query else pure [] cReqChats <- getContactRequestChatPreviews_ db user pagination query connChats <- if withPCC then getContactConnectionChatPreviews_ db user pagination query else pure [] let refs = sortTake $ concat [directChats, groupChats, localChats, feedChats, cReqChats, connChats] diff --git a/tests/ChatClient.hs b/tests/ChatClient.hs index 4f322c82d9..734393fc40 100644 --- a/tests/ChatClient.hs +++ b/tests/ChatClient.hs @@ -224,6 +224,7 @@ testCfg = testView = True, tbqSize = 16, channelSubscriberRole = GRObserver, + showFeedChat = True, confirmMigrations = MCYesUp } diff --git a/tests/ChatTests/Feed.hs b/tests/ChatTests/Feed.hs index 6ab33872c5..17e99de7ad 100644 --- a/tests/ChatTests/Feed.hs +++ b/tests/ChatTests/Feed.hs @@ -16,6 +16,7 @@ chatFeedTests = do it "broadcast to contacts and customer groups in several buckets" testFeedBuckets it "edit and delete the broadcast in every chat" testFeedEditDelete it "recipient with dropped feed receives nothing" testFeedDropped + it "dropped feed keeps applying edits to earlier items" testFeedDroppedAfterReceiving it "instance edited in its chat is detached from the feed" testFeedDetached it "broadcast a file to all contacts" testFeedFile it "incognito contact is excluded from the broadcast" testFeedSkipsIncognito @@ -46,6 +47,7 @@ testFeedBuckets = chatItems biz "@3" 1 `shouldReturn` [(1, "hello everyone")] chatItems biz "#1" 1 `shouldReturn` [(1, "hello everyone")] chatItems biz "#2" 1 `shouldReturn` [(1, "hello everyone")] + biz @@@ [("%", "hello everyone"), ("@alice", "hello everyone"), ("@bob", "hello everyone"), ("#cath", "hello everyone"), ("#dan", "hello everyone")] testFeedEditDelete :: HasCallStack => TestParams -> IO () testFeedEditDelete = @@ -110,6 +112,37 @@ testFeedDropped = (bob TestParams -> IO () +testFeedDroppedAfterReceiving = + testChatCfg3 feedTestCfg businessProfile aliceProfile cathProfile $ + \biz alice cath -> do + createCCFeed biz + connectUsers biz alice + cLink <- businessAddress biz + connectToBusiness biz cath cLink "cath" "Catherine" + + biz `send` "/feed hello everyone" + biz <# "% hello everyone" + alice <# "biz> hello everyone" + cath <# "#biz biz_1> hello everyone" + + alice ##> "/feed drop @biz on" + alice <## "ok" + cath ##> "/feed drop #biz on" + cath <## "ok" + + biz `send` "/feed second" + biz <# "% second" + (alice "! % (hello everyone) hello again" + biz <# "% [edited] hello again" + alice <# "biz> [edited] hello again" + cath <# "#biz biz_1> [edited] hello again" + chatItems alice "@2" 100 >>= (`shouldContain` [(0, "hello again")]) + chatItems cath "#1" 100 >>= (`shouldContain` [(0, "hello again")]) + testFeedDetached :: HasCallStack => TestParams -> IO () testFeedDetached = testChatCfg3 feedTestCfg businessProfile aliceProfile bobProfile $