mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-22 22:08:21 +00:00
fix, add option to include feed in list of chats (off)
This commit is contained in:
1 parent
b7ab1340ee
commit
d4a88000bb
9 files changed
+52
-10
No files matched your search
@@ -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
|
||||
|
||||
@@ -121,6 +121,7 @@ defaultChatConfig =
|
||||
deliveryWorkerDelay = 0,
|
||||
deliveryBucketSize = 10000,
|
||||
feedBucketSize = 1000,
|
||||
showFeedChat = False,
|
||||
webPreviewConfig = Nothing,
|
||||
channelSubscriberRole = GRObserver,
|
||||
relayChecksInterval = 15 * 60, -- 15 minutes
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -224,6 +224,7 @@ testCfg =
|
||||
testView = True,
|
||||
tbqSize = 16,
|
||||
channelSubscriberRole = GRObserver,
|
||||
showFeedChat = True,
|
||||
confirmMigrations = MCYesUp
|
||||
}
|
||||
|
||||
|
||||
@@ -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 </)
|
||||
chatItems bob "@2" 1 `shouldReturn` [(0, "Audio/video calls: enabled")]
|
||||
|
||||
testFeedDroppedAfterReceiving :: HasCallStack => 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 </)
|
||||
(cath </)
|
||||
|
||||
biz ##> "! % (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 $
|
||||
|
||||
Reference in new issue
Block a user