core: process ERRS event (#4896)

* core: process ERRS event

* refactor

* update

---------

Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
This commit is contained in:
spaced4ndy
2024-09-20 21:13:27 +04:00
committed by GitHub
co-authored by Evgeny Poberezkin
parent efb7fc6c3b
commit 8a70bad9af
3 changed files with 13 additions and 2 deletions
+11
View File
@@ -4093,6 +4093,7 @@ processAgentMessageNoConn = \case
UP srv conns -> serverEvent srv conns NSConnected CRContactsSubscribed
SUSPENDED -> toView CRChatSuspended
DEL_USER agentUserId -> toView $ CRAgentUserDeleted agentUserId
ERRS cErrs -> errsEvent cErrs
where
hostEvent :: ChatResponse -> CM ()
hostEvent = whenM (asks $ hostEvents . config) . toView
@@ -4105,6 +4106,16 @@ processAgentMessageNoConn = \case
notifyCLI = do
cs <- withStore' (`getConnectionsContacts` conns)
toView $ event srv cs
errsEvent :: [(ConnId, AgentErrorType)] -> CM ()
errsEvent cErrs = do
vr <- chatVersionRange
errs <- lift $ rights <$> withStoreBatch' (\db -> map (getChatErr vr db) cErrs)
toView $ CRChatErrors Nothing errs
where
getChatErr :: VersionRangeChat -> DB.Connection -> (ConnId, AgentErrorType) -> IO ChatError
getChatErr vr db (connId, err) =
let acId = AgentConnId connId
in ChatErrorAgent err <$> (getUserByAConnId db acId $>>= \user -> eitherToMaybe <$> runExceptT (getConnectionEntity db vr user acId))
processAgentMsgSndFile :: ACorrId -> SndFileId -> AEvent 'AESndFile -> CM ()
processAgentMsgSndFile _corrId aFileId msg = do