core, ui: carry updated support member in internal items, merge only support stats, handle failed member loads

This commit is contained in:
Narasimha-sc
2026-09-26 17:18:54 +00:00
parent b8102803a6
commit 1c5b15e7ef
10 changed files with 50 additions and 27 deletions
+1 -1
View File
@@ -4876,7 +4876,7 @@ processChatCommand cxt nm = \case
startProximateTimedItemThread user (ChatRef CTGroup groupId scope, chatItemId' ci) deleteAt
chatScopeInfo' <- case chatScopeInfo of
Just GCSIMemberSupport {groupMember_ = Just sentScopeMem} ->
Just . GCSIMemberSupport . Just <$> withFastStore (\db -> getGroupMemberById db cxt user (groupMemberId' sentScopeMem))
Just . GCSIMemberSupport . Just . fromRight sentScopeMem <$> withFastStore' (\db -> runExceptT $ getGroupMemberById db cxt user (groupMemberId' sentScopeMem))
_ -> pure chatScopeInfo
pure $ CRNewChatItems user (map (AChatItem SCTGroup SMDSnd (GroupChat gInfo chatScopeInfo')) cis)
where
+9 -9
View File
@@ -34,7 +34,7 @@ import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Char8 as LB
import Data.Char (isDigit)
import Data.Containers.ListUtils (nubOrd)
import Data.Either (partitionEithers, rights)
import Data.Either (fromRight, partitionEithers, rights)
import Data.Fixed (div')
import Data.Foldable (foldr')
import Data.Functor (($>))
@@ -3292,13 +3292,13 @@ createChatItems user itemTs_ dirsCIContents = do
createdAt <- liftIO getCurrentTime
let itemTs = fromMaybe createdAt itemTs_
cxt <- asks storeCxt
void . withStoreBatch' $ \db -> map (updateChat db cxt createdAt) dirsCIContents
withStoreBatch' $ \db -> concatMap (createACIs db itemTs createdAt) dirsCIContents
cInfos <- withStoreBatch' $ \db -> map (updateChat db cxt createdAt) dirsCIContents
withStoreBatch' $ \db -> concat $ zipWith (createACIs db itemTs createdAt) cInfos dirsCIContents
where
updateChat :: DB.Connection -> StoreCxt -> UTCTime -> (ChatDirection c d, ShowGroupAsSender, [(CIContent d, Maybe SharedMsgId, Maybe MsgSigStatus)]) -> IO ()
updateChat :: DB.Connection -> StoreCxt -> UTCTime -> (ChatDirection c d, ShowGroupAsSender, [(CIContent d, Maybe SharedMsgId, Maybe MsgSigStatus)]) -> IO (ChatInfo c)
updateChat db cxt createdAt (cd, _, contents)
| any (\(content, _, _) -> ciRequiresAttention content) contents || contactChatDeleted cd = void $ updateChatTsStats db cxt user cd createdAt memberChatStats
| otherwise = pure ()
| any (\(content, _, _) -> ciRequiresAttention content) contents || contactChatDeleted cd = updateChatTsStats db cxt user cd createdAt memberChatStats
| otherwise = pure $ toChatInfo cd
where
memberChatStats :: Maybe (Int, MemberAttention, Int)
memberChatStats = case cd of
@@ -3306,15 +3306,15 @@ createChatItems user itemTs_ dirsCIContents = do
let unread = length $ filter (\(content, _, _) -> ciRequiresAttention content) contents
in Just (unread, memberAttentionChange unread itemTs_ (Just m) scope, 0)
_ -> Nothing
createACIs :: DB.Connection -> UTCTime -> UTCTime -> (ChatDirection c d, ShowGroupAsSender, [(CIContent d, Maybe SharedMsgId, Maybe MsgSigStatus)]) -> [IO AChatItem]
createACIs db itemTs createdAt (cd, showGroupAsSender, contents) = map createACI contents
createACIs :: DB.Connection -> UTCTime -> UTCTime -> Either ChatError (ChatInfo c) -> (ChatDirection c d, ShowGroupAsSender, [(CIContent d, Maybe SharedMsgId, Maybe MsgSigStatus)]) -> [IO AChatItem]
createACIs db itemTs createdAt cInfo_ (cd, showGroupAsSender, contents) = map createACI contents
where
createACI (content, sharedMsgId, msgSigned) = do
let hasLink_ = ciContentHasLink content Nothing
msgVerified = toMsgVerified False msgSigned
ciId <- createNewChatItemNoMsg db user cd showGroupAsSender content sharedMsgId hasLink_ msgVerified itemTs createdAt
let ci = mkChatItem cd showGroupAsSender ciId content Nothing Nothing Nothing Nothing Nothing False False itemTs Nothing msgVerified createdAt
pure $ AChatItem (chatTypeI @c) (msgDirection @d) (toChatInfo cd) ci
pure $ AChatItem (chatTypeI @c) (msgDirection @d) (fromRight (toChatInfo cd) cInfo_) ci
-- rcvMem_ Nothing means message from channel - treated same as message from moderator,
-- e.g. it can reset unanswered counter if newer than last unanswered message.
+8 -4
View File
@@ -1481,10 +1481,14 @@ getCreateGroupChatScopeInfo db cxt user GroupInfo {membership} = \case
pure $ GCSIMemberSupport {groupMember_ = Nothing}
GCSMemberSupport (Just gmId) -> do
m <- getGroupMemberById db cxt user gmId
when (isNothing $ supportChat m) $ do
ts <- liftIO getCurrentTime
liftIO $ setSupportChatTs db gmId ts
pure GCSIMemberSupport {groupMember_ = Just m}
m' <-
if isNothing (supportChat m)
then do
ts <- liftIO getCurrentTime
liftIO $ setSupportChatTs db gmId ts
getGroupMemberById db cxt user gmId
else pure m
pure GCSIMemberSupport {groupMember_ = Just m'}
getGroupChatScopeInfoForItem :: DB.Connection -> StoreCxt -> User -> GroupInfo -> ChatItemId -> ExceptT StoreError IO (Maybe GroupChatScopeInfo)
getGroupChatScopeInfoForItem db cxt user g itemId =