mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-23 02:28:37 +00:00
core, ui: chatItemUpdated event has the previous item (#8219)
* core, ui: chatItemUpdated event has the previous item Apps change counters by the difference between the previous and the new item, and insert an updated item only when the update created it. * core, ui: a recreated item is sent as newChatItems An update of a locally deleted message creates it again and sends it as a new item, so chatItemUpdated always has the previous item and the apps never insert on an update. * core, ui: previous item is optional and has no chat info Events from older remote hosts decode without it; the apps then insert the item if it is not loaded and change no counters. * core: catch-up subscriber gets an edited history post as a new item * ui: updates in another profile do not notify, as on iOS * core, ui: one type for the updated item and its previous version AChatItemUpdate has the chat info, the new item and the previous item with the same chat type and direction. Its JSON is the JSON of AChatItem with an optional prevChatItem; the event keeps the key chatItem. * core: tested event key, previous item reactions, cleared mentions One function renames the event field to chatItem for JSON and docs, and the test checks the wire key and compatibility with AChatItem. The previous item of a direct edit has its reactions. An edit that removes all mentions sends the item without them. * core: test that an edit removing mentions sends the item without them * core: event JSON field mapping inline in the TH options, for the Windows build * core: file chat item update checked in one store transaction * core: test that a file reset by unknown relays sends its previous item * core, ui: chatItemUpdated event key chatItemUpdate * core, ui: chatItemUpdated always has the previous item * ci: mcp scope tests the plugin with its published dependencies * core: mention of the user follows edits of a group message * core: previous item of a prohibited file is read before the prohibition * android, desktop: missed call check inline, counter test with core pairs * ios: spec link of the chatItemUpdated event * core: mention edits in support chats update members requiring attention * core: one rule for the mention of the user in received and edited items * core: record item events of updates for app tests * android, desktop: remove the missed call notification of updates, never shown * android, desktop: test item updates on events recorded by the core * ios: test item updates on events recorded by the core * docs: plan of app tests of item updates, recording tests in the CI guide * core: record the response to an update after its item status is final * ios: notification manager replaceable in tests * ios: test notifications of updates and the update response * android, desktop: test the recorded update response * docs: plan with iOS notifications and the update response * core: recorded response to an update of a sent message
This commit is contained in:
1 parent
dabee7dab8
commit
4eeddce11d
50 files changed
+4641
-184
No files matched your search
@@ -994,7 +994,7 @@ data ChatEvent
|
||||
| CEvtChatInfoUpdated {user :: User, chatInfo :: AChatInfo}
|
||||
| CEvtNewChatItems {user :: User, chatItems :: [AChatItem]} -- there is the same command response
|
||||
| CEvtChatItemsStatusesUpdated {user :: User, chatItems :: [AChatItem]}
|
||||
| CEvtChatItemUpdated {user :: User, chatItem :: AChatItem} -- there is the same command response
|
||||
| CEvtChatItemUpdated {user :: User, chatItemUpdate :: AChatItemUpdate} -- there is the same command response
|
||||
| CEvtChatItemNotChanged {user :: User, chatItem :: AChatItem} -- there is the same command response
|
||||
| CEvtChatItemReaction {user :: User, added :: Bool, reaction :: ACIReaction} -- there is the same command response
|
||||
| CEvtGroupChatItemsDeleted {user :: User, groupInfo :: GroupInfo, chatItemIDs :: [ChatItemId], byUser :: Bool, member_ :: Maybe GroupMember} -- there is the same command response
|
||||
|
||||
@@ -3645,7 +3645,7 @@ processChatCommand cxt nm = \case
|
||||
liftIO $ removeFile fsFilePath `catchAll_` pure ()
|
||||
lift . forM_ agentRcvFileId $ \(AgentRcvFileId aFileId) ->
|
||||
withAgent' (`xftpDeleteRcvFile` aFileId)
|
||||
aci_ <- resetRcvCIFileStatus user fileId CIFSRcvInvitation
|
||||
aci_ <- fmap updatedAChatItem <$> resetRcvCIFileStatus user fileId CIFSRcvInvitation
|
||||
pure $ CRRcvFileCancelled user aci_ ftr
|
||||
FileStatus fileId -> withUser $ \user -> do
|
||||
withFastStore (\db -> lookupChatItemByFileId db cxt user fileId) >>= \case
|
||||
@@ -4970,7 +4970,7 @@ processChatCommand cxt nm = \case
|
||||
let content' = CIRcvGroupInvitation (ciGroupInv {status = newStatus} :: CIGroupInvitation) memRole
|
||||
timed_ <- sndGroupCITimed False g Nothing
|
||||
ci' <- withFastStore' $ \db -> updateGroupChatItem db user (groupId' g) ci {meta = meta {itemTimed = timed_}} content' False False Nothing
|
||||
toView $ CEvtChatItemUpdated user (AChatItem SCTGroup SMDRcv cInfo ci')
|
||||
toView $ CEvtChatItemUpdated user (AChatItemUpdate SCTGroup SMDRcv cInfo ci' ci)
|
||||
forM_ (timed_ >>= timedDeleteAt') $
|
||||
startProximateTimedItemThread user (ChatRef CTGroup (groupId' g) Nothing, itemId)
|
||||
_ -> pure () -- prohibited
|
||||
|
||||
@@ -707,8 +707,8 @@ updateCallItemStatus user ct@Contact {contactId} Call {chatItemId} receivedStatu
|
||||
|
||||
updateDirectChatItemView :: User -> Contact -> ChatItemId -> ACIContent -> Bool -> Bool -> Maybe CITimed -> Maybe MessageId -> CM ()
|
||||
updateDirectChatItemView user ct chatItemId (ACIContent msgDir ciContent) edited live timed_ msgId_ = do
|
||||
ci' <- withStore $ \db -> updateDirectChatItem db user ct chatItemId ciContent edited live timed_ msgId_
|
||||
toView $ CEvtChatItemUpdated user (AChatItem SCTDirect msgDir (DirectChat ct) ci')
|
||||
(ci, ci') <- withStore $ \db -> updateDirectChatItem db user ct chatItemId ciContent edited live timed_ msgId_
|
||||
toView $ CEvtChatItemUpdated user (AChatItemUpdate SCTDirect msgDir (DirectChat ct) ci' ci)
|
||||
|
||||
callStatusItemContent :: User -> Contact -> ChatItemId -> WebRTCCallStatus -> CM (Maybe ACIContent)
|
||||
callStatusItemContent user Contact {contactId} chatItemId receivedStatus = do
|
||||
@@ -849,12 +849,11 @@ receiveViaCompleteFD user fileId RcvFileDescr {fileDescrText, fileDescrComplete}
|
||||
-- TODO re-enable redirects with relay checks
|
||||
when (isJust redirect) $ do
|
||||
cxt <- chatStoreCxt
|
||||
aci_ <- withStore $ \db -> do
|
||||
liftIO $ updateFileCancelled db user fileId (CIFSRcvError $ FileErrOther "redirect not allowed")
|
||||
lookupChatItemByFileId db cxt user fileId
|
||||
forM_ aci_ $ \aci -> do
|
||||
cleanupACIFile aci
|
||||
toView $ CEvtChatItemUpdated user aci
|
||||
upd_ <- withStore $ \db ->
|
||||
updateFileChatItem db cxt user fileId $ updateFileCancelled db user fileId (CIFSRcvError $ FileErrOther "redirect not allowed")
|
||||
forM_ upd_ $ \upd -> do
|
||||
cleanupACIFile $ updatedAChatItem upd
|
||||
toView $ CEvtChatItemUpdated user upd
|
||||
throwChatError $ CEInvalidFileDescription "redirect not allowed"
|
||||
when (rcvSize > maxRcvSize) $ throwChatError $ CEFileRcvChunk "declared file size exceeds the file invitation size"
|
||||
if userApprovedRelays
|
||||
@@ -884,10 +883,10 @@ receiveViaCompleteFD user fileId RcvFileDescr {fileDescrText, fileDescrComplete}
|
||||
pure $ all (ipAddressProtected netCfg) srvs
|
||||
relaysNotApproved :: [XFTPServer] -> CM ()
|
||||
relaysNotApproved unknownSrvs = do
|
||||
aci_ <- resetRcvCIFileStatus user fileId CIFSRcvInvitation
|
||||
forM_ aci_ $ \aci -> do
|
||||
cleanupACIFile aci
|
||||
toView $ CEvtChatItemUpdated user aci
|
||||
upd_ <- resetRcvCIFileStatus user fileId CIFSRcvInvitation
|
||||
forM_ upd_ $ \upd -> do
|
||||
cleanupACIFile $ updatedAChatItem upd
|
||||
toView $ CEvtChatItemUpdated user upd
|
||||
throwChatError $ CEFileNotApproved fileId unknownSrvs
|
||||
|
||||
cleanupACIFile :: AChatItem -> CM ()
|
||||
@@ -910,15 +909,16 @@ protoServer' ServerCfg {server} = protoServer server
|
||||
getNetworkConfig :: CM' NetworkConfig
|
||||
getNetworkConfig = withAgent' $ liftIO . getFastNetworkConfig
|
||||
|
||||
resetRcvCIFileStatus :: User -> FileTransferId -> CIFileStatus 'MDRcv -> CM (Maybe AChatItem)
|
||||
resetRcvCIFileStatus :: User -> FileTransferId -> CIFileStatus 'MDRcv -> CM (Maybe AChatItemUpdate)
|
||||
resetRcvCIFileStatus user fileId ciFileStatus = do
|
||||
cxt <- chatStoreCxt
|
||||
withStore $ \db -> do
|
||||
liftIO $ do
|
||||
updateCIFileStatus db user fileId ciFileStatus
|
||||
updateRcvFileStatus db fileId FSNew
|
||||
updateRcvFileAgentId db fileId Nothing
|
||||
lookupChatItemByFileId db cxt user fileId
|
||||
withStore $ \db -> updateFileChatItem db cxt user fileId $ resetRcvFile db user fileId ciFileStatus
|
||||
|
||||
resetRcvFile :: DB.Connection -> User -> FileTransferId -> CIFileStatus 'MDRcv -> IO ()
|
||||
resetRcvFile db user fileId ciFileStatus = do
|
||||
updateCIFileStatus db user fileId ciFileStatus
|
||||
updateRcvFileStatus db fileId FSNew
|
||||
updateRcvFileAgentId db fileId Nothing
|
||||
|
||||
receiveViaURI :: User -> FileDescriptionURI -> CryptoFile -> CM RcvFileTransfer
|
||||
receiveViaURI user@User {userId} FileDescriptionURI {description} cf@CryptoFile {cryptoArgs} = do
|
||||
@@ -3102,11 +3102,10 @@ saveRcvChatItem' user cd msg@RcvMessage {chatMsgEvent, msgSigned, forwardedByMem
|
||||
let senderBlocked = case cd of
|
||||
CDGroupRcv _g _scope m -> memberBlocked m
|
||||
_ -> False
|
||||
userReply = not senderBlocked && case cmToQuotedMsg chatMsgEvent of
|
||||
userReply = case cmToQuotedMsg chatMsgEvent of
|
||||
Just QuotedMsg {msgRef = MsgRef {memberId = Just mId}} -> sameMemberId mId membership
|
||||
_ -> False
|
||||
userMention' = userReply || any (\CIMention {memberId} -> sameMemberId memberId membership) mentions'
|
||||
in pure (mentions', userMention')
|
||||
in pure (mentions', userMentioned membership senderBlocked userReply mentions')
|
||||
memberChatStats :: Bool -> Maybe (Int, MemberAttention, Int)
|
||||
memberChatStats userMention = case cd of
|
||||
CDGroupRcv _g (Just scope) m ->
|
||||
|
||||
@@ -415,10 +415,10 @@ processAgentMsgRcvFile _corrId aFileId msg = do
|
||||
_ -> pure False
|
||||
if badDigest
|
||||
then do
|
||||
aci_ <- resetRcvCIFileStatus user fileId (CIFSRcvError $ FileErrOther "file digest")
|
||||
forM_ aci_ cleanupACIFile
|
||||
upd_ <- resetRcvCIFileStatus user fileId (CIFSRcvError $ FileErrOther "file digest")
|
||||
forM_ upd_ $ cleanupACIFile . updatedAChatItem
|
||||
agentXFTPDeleteRcvFile aFileId fileId
|
||||
forM_ aci_ $ \aci -> toView $ CEvtChatItemUpdated user aci
|
||||
forM_ upd_ $ toView . CEvtChatItemUpdated user
|
||||
else do
|
||||
ci_ <- withStore $ \db -> do
|
||||
liftIO $ do
|
||||
@@ -434,10 +434,10 @@ processAgentMsgRcvFile _corrId aFileId msg = do
|
||||
toView $ CEvtRcvFileWarning user ci e ft
|
||||
RFERR e
|
||||
| e == FILE NOT_APPROVED -> do
|
||||
aci_ <- resetRcvCIFileStatus user fileId CIFSRcvAborted
|
||||
forM_ aci_ cleanupACIFile
|
||||
upd_ <- resetRcvCIFileStatus user fileId CIFSRcvAborted
|
||||
forM_ upd_ $ cleanupACIFile . updatedAChatItem
|
||||
agentXFTPDeleteRcvFile aFileId fileId
|
||||
forM_ aci_ $ \aci -> toView $ CEvtChatItemUpdated user aci
|
||||
forM_ upd_ $ toView . CEvtChatItemUpdated user
|
||||
| otherwise -> do
|
||||
aci_ <- withStore $ \db -> do
|
||||
liftIO $ updateFileCancelled db user fileId (CIFSRcvError $ agentFileError e)
|
||||
@@ -723,10 +723,10 @@ processAgentMessageConn cxt user@User {userId} entity gks_ corrId agentConnId ag
|
||||
ci_ <- withStore $ \db ->
|
||||
getDirectChatItemLast db user contactId
|
||||
>>= liftIO
|
||||
. mapM (\(ci, content') -> updateDirectChatItem' db user contactId ci content' False False Nothing Nothing)
|
||||
. mapM (\(ci, content') -> (ci,) <$> updateDirectChatItem' db user contactId ci content' False False Nothing Nothing)
|
||||
. mdeUpdatedCI e
|
||||
case ci_ of
|
||||
Just ci -> toView $ CEvtChatItemUpdated user (AChatItem SCTDirect SMDRcv (DirectChat ct) ci)
|
||||
Just (ci, ci') -> toView $ CEvtChatItemUpdated user (AChatItemUpdate SCTDirect SMDRcv (DirectChat ct) ci' ci)
|
||||
_ -> do
|
||||
toView $ CEvtContactRatchetSync user ct (RatchetSyncProgress rss cStats)
|
||||
createInternalChatItem user (CDDirectRcv ct) (CIRcvDecryptionError mde n) Nothing
|
||||
@@ -1226,10 +1226,10 @@ processAgentMessageConn cxt user@User {userId} entity gks_ corrId agentConnId ag
|
||||
ci_ <- withStore $ \db ->
|
||||
getGroupMemberChatItemLast db user groupId (groupMemberId' m')
|
||||
>>= liftIO
|
||||
. mapM (\(ci, content') -> updateGroupChatItem db user groupId ci content' False False Nothing)
|
||||
. mapM (\(ci, content') -> (ci,) <$> updateGroupChatItem db user groupId ci content' False False Nothing)
|
||||
. mdeUpdatedCI e
|
||||
case ci_ of
|
||||
Just ci -> toView $ CEvtChatItemUpdated user (AChatItem SCTGroup SMDRcv (GroupChat gInfo' scopeInfo) ci)
|
||||
Just (ci, ci') -> toView $ CEvtChatItemUpdated user (AChatItemUpdate SCTGroup SMDRcv (GroupChat gInfo' scopeInfo) ci' ci)
|
||||
_ -> do
|
||||
toView $ CEvtGroupMemberRatchetSync user gInfo' m' (RatchetSyncProgress rss cStats)
|
||||
createInternalChatItem user (CDGroupRcv gInfo' scopeInfo m') (CIRcvDecryptionError mde n) Nothing
|
||||
@@ -1575,11 +1575,11 @@ processAgentMessageConn cxt user@User {userId} entity gks_ corrId agentConnId ag
|
||||
CChatItem SMDRcv ci@ChatItem {content = CIRcvMsgContent oldMC}
|
||||
| mc /= oldMC -> do
|
||||
currentTs <- liftIO getCurrentTime
|
||||
aci <- withStore' $ \db -> do
|
||||
ci' <- withStore' $ \db -> do
|
||||
addInitialAndNewCIVersions db (chatItemId' ci) (chatItemTs' ci, oldMC) (currentTs, mc)
|
||||
aChatItem <$> updateDirectChatItem' db user contactId ci (CIRcvMsgContent mc) True False Nothing Nothing
|
||||
toView $ CEvtChatItemUpdated user aci
|
||||
pure $ Just aci
|
||||
updateDirectChatItem' db user contactId ci (CIRcvMsgContent mc) True False Nothing Nothing
|
||||
toView $ CEvtChatItemUpdated user (AChatItemUpdate SCTDirect SMDRcv (DirectChat ct) ci' ci)
|
||||
pure $ Just $ aChatItem ci'
|
||||
| otherwise -> pure $ Just $ aChatItem ci
|
||||
_ -> pure Nothing
|
||||
where
|
||||
@@ -1604,11 +1604,11 @@ processAgentMessageConn cxt user@User {userId} entity gks_ corrId agentConnId ag
|
||||
if mc /= oldMC
|
||||
then do
|
||||
currentTs <- liftIO getCurrentTime
|
||||
aci <- withStore' $ \db -> do
|
||||
ci' <- withStore' $ \db -> do
|
||||
addInitialAndNewCIVersions db (chatItemId' ci) (chatItemTs' ci, oldMC) (currentTs, mc)
|
||||
aChatItem <$> updateGroupChatItem db user groupId ci (CIRcvMsgContent mc) True False Nothing
|
||||
toView $ CEvtChatItemUpdated user aci
|
||||
pure $ Just aci
|
||||
updateGroupChatItem db user groupId ci (CIRcvMsgContent mc) True False Nothing
|
||||
toView $ CEvtChatItemUpdated user (AChatItemUpdate SCTGroup SMDRcv (GroupChat gInfo Nothing) ci' ci)
|
||||
pure $ Just $ aChatItem ci'
|
||||
else pure $ Just $ aChatItem ci
|
||||
_ -> pure Nothing
|
||||
where
|
||||
@@ -2049,9 +2049,10 @@ processAgentMessageConn cxt user@User {userId} entity gks_ corrId agentConnId ag
|
||||
_ -> pure ()
|
||||
-- the file may already be accepted, so it is reset to an invitation the apps refuse by its prohibition
|
||||
Just prohibited -> do
|
||||
withStore' $ \db -> setFileProhibited db user fileId prohibited
|
||||
aci_ <- resetRcvCIFileStatus user fileId CIFSRcvInvitation
|
||||
forM_ aci_ $ \aci' -> toView $ CEvtChatItemUpdated user aci'
|
||||
upd_ <- withStore $ \db -> updateFileChatItem db cxt user fileId $ do
|
||||
setFileProhibited db user fileId prohibited
|
||||
resetRcvFile db user fileId CIFSRcvInvitation
|
||||
forM_ upd_ $ toView . CEvtChatItemUpdated user
|
||||
|
||||
descrBadgeStatus :: Maybe ByteString -> Integer -> RcvFileDescr -> Maybe UTCTime -> BadgeProof -> CM BadgeStatus
|
||||
descrBadgeStatus binding_ fileSize RcvFileDescr {fileDescrText} fileExpires badge = do
|
||||
@@ -2101,7 +2102,7 @@ processAgentMessageConn cxt user@User {userId} entity gks_ corrId agentConnId ag
|
||||
then do
|
||||
let ciContent = ciContentNoParse $ CIRcvChatFeatureRejected CFVoice
|
||||
(ci, cInfo) <- saveRcvChatItem' user (CDDirectRcv ct) msg (Just sharedMsgId) brokerTs ciContent Nothing Nothing False M.empty
|
||||
toView $ CEvtChatItemUpdated user (AChatItem SCTDirect SMDRcv cInfo ci)
|
||||
toView $ CEvtNewChatItems user [AChatItem SCTDirect SMDRcv cInfo ci]
|
||||
else do
|
||||
let timed_ = rcvContactCITimed ct ttl
|
||||
ts = ciContentTexts content
|
||||
@@ -2109,7 +2110,7 @@ processAgentMessageConn cxt user@User {userId} entity gks_ corrId agentConnId ag
|
||||
ci' <- withStore' $ \db -> do
|
||||
createChatItemVersion db (chatItemId' ci) brokerTs mc
|
||||
updateDirectChatItem' db user contactId ci content True live Nothing Nothing
|
||||
toView $ CEvtChatItemUpdated user (AChatItem SCTDirect SMDRcv cInfo ci')
|
||||
toView $ CEvtNewChatItems user [AChatItem SCTDirect SMDRcv cInfo ci']
|
||||
where
|
||||
brokerTs = metaBrokerTs msgMeta
|
||||
content = CIRcvMsgContent mc
|
||||
@@ -2122,13 +2123,14 @@ processAgentMessageConn cxt user@User {userId} entity gks_ corrId agentConnId ag
|
||||
let changed = mc /= oldMC
|
||||
if changed || fromMaybe False itemLive
|
||||
then do
|
||||
ci' <- withStore' $ \db -> do
|
||||
(ciR, ci') <- withStore' $ \db -> do
|
||||
when changed $
|
||||
addInitialAndNewCIVersions db (chatItemId' ci) (chatItemTs' ci, oldMC) (brokerTs, mc)
|
||||
reactions <- getDirectCIReactions db ct sharedMsgId
|
||||
let edited = itemLive /= Just True
|
||||
updateDirectChatItem' db user contactId ci {reactions} content edited live Nothing $ Just msgId
|
||||
toView $ CEvtChatItemUpdated user (AChatItem SCTDirect SMDRcv (DirectChat ct) ci')
|
||||
let ciR = (ci :: ChatItem 'CTDirect 'MDRcv) {reactions}
|
||||
edited = itemLive /= Just True
|
||||
(ciR,) <$> updateDirectChatItem' db user contactId ciR content edited live Nothing (Just msgId)
|
||||
toView $ CEvtChatItemUpdated user (AChatItemUpdate SCTDirect SMDRcv (DirectChat ct) ci' ciR)
|
||||
startUpdatedTimedItemThread user (ChatRef CTDirect contactId Nothing) ci ci'
|
||||
else toView $ CEvtChatItemNotChanged user (AChatItem SCTDirect SMDRcv (DirectChat ct) ci)
|
||||
_ -> messageError "x.msg.update: contact attempted invalid message update"
|
||||
@@ -2358,7 +2360,7 @@ processAgentMessageConn cxt user@User {userId} entity gks_ corrId agentConnId ag
|
||||
ci'' <- case chatDir of
|
||||
CDGroupRcv gi' _ m' -> blockedMemberCI gi' m' ci'
|
||||
CDChannelRcv {} -> pure ci'
|
||||
toView $ CEvtChatItemUpdated user (AChatItem SCTGroup SMDRcv cInfo ci'')
|
||||
groupMsgToView cInfo ci''
|
||||
pure $ Just $ infoToDeliveryContext gInfo' scopeInfo showGroupAsSender
|
||||
where
|
||||
content = CIRcvMsgContent mc
|
||||
@@ -2405,8 +2407,8 @@ processAgentMessageConn cxt user@User {userId} entity gks_ corrId agentConnId ag
|
||||
ciMentions <- getRcvCIMentions db user gInfo ft_ mentions
|
||||
ci' <- updateGroupChatItem db user groupId ci {reactions} content edited live $ Just msgId
|
||||
updateChatItemSignedMsg db (chatItemId' ci) signedMsg_ signedByGMId_
|
||||
updateGroupCIMentions db gInfo ci' ciMentions
|
||||
toView $ CEvtChatItemUpdated user (AChatItem SCTGroup SMDRcv (GroupChat gInfo scopeInfo) ci')
|
||||
updateGroupCIMentions db gInfo ci' ciMentions >>= updateGroupCIUserMention db cxt user gInfo scopeInfo
|
||||
toView $ CEvtChatItemUpdated user (AChatItemUpdate SCTGroup SMDRcv (GroupChat gInfo scopeInfo) ci' ci)
|
||||
startUpdatedTimedItemThread user (ChatRef CTGroup groupId $ toChatScope <$> scopeInfo) ci ci'
|
||||
pure $ Just $ infoToDeliveryContext gInfo scopeInfo showGroupAsSender
|
||||
else do
|
||||
|
||||
@@ -291,6 +291,10 @@ isACIUserMention (AChatItem _ _ _ ci) = isUserMention ci
|
||||
isUserMention :: ChatItem c d -> Bool
|
||||
isUserMention ChatItem {meta = CIMeta {userMention}} = userMention
|
||||
|
||||
userMentioned :: GroupMember -> Bool -> Bool -> Map MemberName CIMention -> Bool
|
||||
userMentioned membership senderBlocked userReply mentions =
|
||||
not senderBlocked && (userReply || any (\CIMention {memberId} -> sameMemberId memberId membership) mentions)
|
||||
|
||||
data CIDirection (c :: ChatType) (d :: MsgDirection) where
|
||||
CIDirectSnd :: CIDirection 'CTDirect 'MDSnd
|
||||
CIDirectRcv :: CIDirection 'CTDirect 'MDRcv
|
||||
@@ -481,6 +485,15 @@ deriving instance Show AChatItem
|
||||
|
||||
data JSONAnyChatItem c d = JSONAnyChatItem {chatInfo :: ChatInfo c, chatItem :: ChatItem c d}
|
||||
|
||||
data AChatItemUpdate = forall c d. (ChatTypeI c, MsgDirectionI d) => AChatItemUpdate (SChatType c) (SMsgDirection d) (ChatInfo c) (ChatItem c d) (ChatItem c d)
|
||||
|
||||
deriving instance Show AChatItemUpdate
|
||||
|
||||
data JSONAnyChatItemUpdate c d = JSONAnyChatItemUpdate {chatInfo :: ChatInfo c, chatItem :: ChatItem c d, prevChatItem :: ChatItem c d}
|
||||
|
||||
updatedAChatItem :: AChatItemUpdate -> AChatItem
|
||||
updatedAChatItem (AChatItemUpdate c d chatInfo ci _) = AChatItem c d chatInfo ci
|
||||
|
||||
aChatItems :: AChat -> [AChatItem]
|
||||
aChatItems (AChat ct Chat {chatInfo, chatItems}) = map aChatItem chatItems
|
||||
where
|
||||
@@ -1562,6 +1575,21 @@ instance ChatTypeI c => ToJSON (CChatItem c) where
|
||||
toJSON (CChatItem _ ci) = J.toJSON ci
|
||||
toEncoding (CChatItem _ ci) = J.toEncoding ci
|
||||
|
||||
instance (ChatTypeI c, MsgDirectionI d) => ToJSON (JSONAnyChatItemUpdate c d) where
|
||||
toJSON = $(JQ.mkToJSON defaultJSON ''JSONAnyChatItemUpdate)
|
||||
toEncoding = $(JQ.mkToEncoding defaultJSON ''JSONAnyChatItemUpdate)
|
||||
|
||||
instance FromJSON AChatItemUpdate where
|
||||
parseJSON = J.withObject "AChatItemUpdate" $ \o -> do
|
||||
AChatInfo c chatInfo <- o .: "chatInfo"
|
||||
CChatItem d chatItem <- o .: "chatItem"
|
||||
prev <- o .: "prevChatItem"
|
||||
pure $ AChatItemUpdate c d chatInfo chatItem prev
|
||||
|
||||
instance ToJSON AChatItemUpdate where
|
||||
toJSON (AChatItemUpdate _ _ chat item prev) = J.toJSON $ JSONAnyChatItemUpdate chat item prev
|
||||
toEncoding (AChatItemUpdate _ _ chat item prev) = J.toEncoding $ JSONAnyChatItemUpdate chat item prev
|
||||
|
||||
$(JQ.deriveJSON defaultJSON ''ChatItemInfo)
|
||||
|
||||
$(JQ.deriveJSON defaultJSON ''ChatStats)
|
||||
|
||||
@@ -64,6 +64,7 @@ module Simplex.Chat.Store.Messages
|
||||
updateChatItemSignedMsg,
|
||||
createGroupCIMentions,
|
||||
updateGroupCIMentions,
|
||||
updateGroupCIUserMention,
|
||||
deleteGroupChatItem,
|
||||
updateGroupChatItemModerated,
|
||||
deleteMemberCIs,
|
||||
@@ -118,6 +119,7 @@ module Simplex.Chat.Store.Messages
|
||||
getLocalChatItemIdByText',
|
||||
getChatItemByFileId,
|
||||
lookupChatItemByFileId,
|
||||
updateFileChatItem,
|
||||
getChatItemByGroupId,
|
||||
updateDirectChatItemStatus,
|
||||
setDirectSndChatItemViaProxy,
|
||||
@@ -164,6 +166,7 @@ import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import Data.Time (addUTCTime)
|
||||
import Data.Time.Clock (UTCTime (..), getCurrentTime)
|
||||
import Data.Type.Equality (testEquality, (:~:) (Refl))
|
||||
import Simplex.Chat.Badges (BadgeStatus)
|
||||
import Simplex.Chat.Controller (ChatListQuery (..), ChatPagination (..), PaginationByTime (..))
|
||||
import Simplex.Chat.Markdown
|
||||
@@ -2230,11 +2233,7 @@ updateGroupScopeUnreadStats db cxt user g@GroupInfo {membership} scopeInfo (unre
|
||||
pure g {membership = membership'}
|
||||
Just member -> do
|
||||
member' <- updateGMStats member
|
||||
let didRequire = gmRequiresAttention member
|
||||
nowRequires = gmRequiresAttention member'
|
||||
if (not nowRequires && didRequire)
|
||||
then decreaseGroupMembersRequireAttention db user g
|
||||
else pure g
|
||||
updateGroupMembersRequireAttention db user g member member'
|
||||
where
|
||||
updateGMStats m@GroupMember {groupMemberId} = do
|
||||
currentTs <- getCurrentTime
|
||||
@@ -2556,10 +2555,10 @@ setDirectSndChatItemViaProxy db User {userId} Contact {contactId} ci viaProxy =
|
||||
DB.execute db "UPDATE chat_items SET via_proxy = ? WHERE user_id = ? AND contact_id = ? AND chat_item_id = ?" (BI viaProxy, userId, contactId, chatItemId' ci)
|
||||
pure ci {meta = (meta ci) {sentViaProxy = Just viaProxy}}
|
||||
|
||||
updateDirectChatItem :: MsgDirectionI d => DB.Connection -> User -> Contact -> ChatItemId -> CIContent d -> Bool -> Bool -> Maybe CITimed -> Maybe MessageId -> ExceptT StoreError IO (ChatItem 'CTDirect d)
|
||||
updateDirectChatItem :: MsgDirectionI d => DB.Connection -> User -> Contact -> ChatItemId -> CIContent d -> Bool -> Bool -> Maybe CITimed -> Maybe MessageId -> ExceptT StoreError IO (ChatItem 'CTDirect d, ChatItem 'CTDirect d)
|
||||
updateDirectChatItem db user ct@Contact {contactId} itemId newContent edited live timed_ msgId_ = do
|
||||
ci <- liftEither . correctDir =<< getDirectCIWithReactions db user ct itemId
|
||||
liftIO $ updateDirectChatItem' db user contactId ci newContent edited live timed_ msgId_
|
||||
(ci,) <$> liftIO (updateDirectChatItem' db user contactId ci newContent edited live timed_ msgId_)
|
||||
|
||||
getDirectCIWithReactions :: DB.Connection -> User -> Contact -> ChatItemId -> ExceptT StoreError IO (CChatItem 'CTDirect)
|
||||
getDirectCIWithReactions db user ct@Contact {contactId} itemId =
|
||||
@@ -2824,13 +2823,13 @@ createGroupCIMentions db GroupInfo {groupId} ci mentions = do
|
||||
rows = map (\(name, CIMention {memberId}) -> (ciId, groupId, memberId, name)) $ M.assocs mentions
|
||||
ciId = chatItemId' ci
|
||||
|
||||
updateGroupCIMentions :: DB.Connection -> GroupInfo -> ChatItem 'CTGroup d -> Map MemberName CIMention -> IO (ChatItem 'CTGroup d)
|
||||
updateGroupCIMentions :: forall d. DB.Connection -> GroupInfo -> ChatItem 'CTGroup d -> Map MemberName CIMention -> IO (ChatItem 'CTGroup d)
|
||||
updateGroupCIMentions db g ci@ChatItem {mentions} mentions'
|
||||
| mentions' == mentions = pure ci
|
||||
| otherwise = do
|
||||
unless (null mentions) deleteMentions
|
||||
if null mentions'
|
||||
then pure ci
|
||||
then pure (ci :: ChatItem 'CTGroup d) {mentions = mentions'}
|
||||
else -- This is a fallback for the error that should not happen in practice.
|
||||
-- In theory, it may happen in item mentions in database are different from item record.
|
||||
withSavepoint db "create_mentions" createMentions >>= \case
|
||||
@@ -2840,6 +2839,23 @@ updateGroupCIMentions db g ci@ChatItem {mentions} mentions'
|
||||
deleteMentions = DB.execute db "DELETE FROM chat_item_mentions WHERE chat_item_id = ?" (Only $ chatItemId' ci)
|
||||
createMentions = createGroupCIMentions db g ci mentions'
|
||||
|
||||
updateGroupCIUserMention :: DB.Connection -> StoreCxt -> User -> GroupInfo -> Maybe GroupChatScopeInfo -> ChatItem 'CTGroup 'MDRcv -> IO (ChatItem 'CTGroup 'MDRcv)
|
||||
updateGroupCIUserMention db cxt user@User {userId} g@GroupInfo {membership} scopeInfo_ ci@ChatItem {chatDir, quotedItem, mentions, meta = meta@CIMeta {itemId, itemStatus, userMention}}
|
||||
| userMention' == userMention = pure ci
|
||||
| otherwise = do
|
||||
DB.execute db "UPDATE chat_items SET user_mention = ? WHERE user_id = ? AND chat_item_id = ?" (BI userMention', userId, itemId)
|
||||
when (itemStatus == CISRcvNew) $
|
||||
forM_ scopeInfo_ $ \scopeInfo -> updateGroupScopeUnreadStats db cxt user g scopeInfo (0, 0, fromEnum userMention - fromEnum userMention')
|
||||
pure ci {meta = meta {userMention = userMention'}}
|
||||
where
|
||||
userMention' = userMentioned membership senderBlocked userReply mentions
|
||||
senderBlocked = case chatDir of
|
||||
CIGroupRcv m -> memberBlocked m
|
||||
CIChannelRcv -> False
|
||||
userReply = case quotedItem of
|
||||
Just CIQuote {chatDir = CIQGroupSnd} -> True
|
||||
_ -> False
|
||||
|
||||
deleteGroupChatItem :: DB.Connection -> User -> GroupInfo -> ChatItem 'CTGroup d -> IO ()
|
||||
deleteGroupChatItem db User {userId} g@GroupInfo {groupId} ci = do
|
||||
let itemId = chatItemId' ci
|
||||
@@ -3319,6 +3335,17 @@ lookupChatItemByFileId db cxt user fileId = do
|
||||
SEChatItemNotFoundByFileId {} -> pure Nothing
|
||||
e -> throwError e
|
||||
|
||||
updateFileChatItem :: DB.Connection -> StoreCxt -> User -> Int64 -> IO () -> ExceptT StoreError IO (Maybe AChatItemUpdate)
|
||||
updateFileChatItem db cxt user fileId update = do
|
||||
prevAci_ <- lookupChatItemByFileId db cxt user fileId
|
||||
liftIO update
|
||||
aci_ <- lookupChatItemByFileId db cxt user fileId
|
||||
case (prevAci_, aci_) of
|
||||
(Nothing, Nothing) -> pure Nothing
|
||||
(Just (AChatItem c' d' _ prevCi), Just (AChatItem c d chatInfo ci))
|
||||
| Just Refl <- testEquality c c', Just Refl <- testEquality d d' -> pure $ Just $ AChatItemUpdate c d chatInfo ci prevCi
|
||||
_ -> throwError $ SEInternalError $ "file update changed chat item presence, chat type or direction, file " <> show fileId
|
||||
|
||||
getChatItemByGroupId :: DB.Connection -> StoreCxt -> User -> GroupId -> ExceptT StoreError IO AChatItem
|
||||
getChatItemByGroupId db cxt user@User {userId} groupId = do
|
||||
(chatRef, itemId) <-
|
||||
|
||||
@@ -147,7 +147,7 @@ runTerminalOutput ct cc@ChatController {outputQ, showLiveItems, logFilePath} Cha
|
||||
(outputRH, r_) <- atomically $ readTBQueue outputQ
|
||||
forM_ r_ $ \case
|
||||
CEvtNewChatItems u (ci : _) -> when markRead $ markChatItemRead u ci -- At the moment of writing received items are created one at a time
|
||||
CEvtChatItemUpdated u ci -> when markRead $ markChatItemRead u ci
|
||||
CEvtChatItemUpdated u upd -> when markRead $ markChatItemRead u (updatedAChatItem upd)
|
||||
CEvtRemoteHostConnected {remoteHost = RemoteHostInfo {remoteHostId}} -> getRemoteUser remoteHostId
|
||||
CEvtRemoteHostStopped {remoteHostId_} -> mapM_ removeRemoteUser remoteHostId_
|
||||
_ -> pure ()
|
||||
@@ -185,7 +185,7 @@ chatEventNotification t@ChatTerminal {sendNotification} cc = \case
|
||||
_ -> pure ()
|
||||
where
|
||||
text = msgText mc formattedText
|
||||
CEvtChatItemUpdated u (AChatItem _ SMDRcv cInfo ci@ChatItem {chatDir, content = CIRcvMsgContent _}) ->
|
||||
CEvtChatItemUpdated u (AChatItemUpdate _ SMDRcv cInfo ci@ChatItem {chatDir, content = CIRcvMsgContent _} _) ->
|
||||
whenCurrUser cc u $ when (chatDirNtf u cInfo chatDir $ isUserMention ci) $ setActiveChat t cInfo
|
||||
CEvtContactConnected u ct _ -> when (contactNtf u ct False) $ do
|
||||
whenCurrUser cc u $ setActiveContact t ct
|
||||
|
||||
@@ -454,7 +454,7 @@ chatEventToView hu ChatConfig {logLevel, showReactions, showReceipts, testView}
|
||||
| testView && showReceipts ->
|
||||
ttyUser u [sShow (length chatItems) <> " message statuses updated"]
|
||||
| otherwise -> []
|
||||
CEvtChatItemUpdated u (AChatItem _ _ chat item) -> ttyUser u $ unmuted u chat item $ viewItemUpdate chat item liveItems ts tz
|
||||
CEvtChatItemUpdated u (AChatItemUpdate _ _ chat item _) -> ttyUser u $ unmuted u chat item $ viewItemUpdate chat item liveItems ts tz
|
||||
CEvtChatItemNotChanged u ci -> ttyUser u $ viewItemNotChanged ci
|
||||
CEvtChatItemReaction u added (ACIReaction _ _ chat reaction) -> ttyUser u $ unmutedReaction u chat reaction $ viewItemReaction showReactions chat reaction added ts tz
|
||||
CEvtChatItemsDeleted u deletions byUser timed -> ttyUser u $ viewChatItemsDeleted (unmuted u) deletions byUser timed ts tz testView
|
||||
|
||||
Reference in new issue
Block a user