mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-03-31 16:15:55 +00:00
update connection status in entity used in controller notifications (#252)
* update connection status in entity used in controller notifications * remove unused code
This commit is contained in:
committed by
GitHub
parent
a68b591029
commit
9f6385f763
@@ -487,11 +487,8 @@ subscribeUserConnections = void . runExceptT $ do
|
||||
forM_ conns $ subscribeConnection a . aConnId
|
||||
|
||||
processAgentMessage :: forall m. ChatMonad m => User -> ConnId -> ACommand 'Agent -> m ()
|
||||
processAgentMessage user@User {userId, profile} agentConnId agentMessage = do
|
||||
acEntity <- withStore $ \st -> getConnectionEntity st user agentConnId
|
||||
forM_ (agentMsgConnStatus agentMessage) $ \status ->
|
||||
withStore $ \st -> updateConnectionStatus st (fromConnection acEntity) status
|
||||
case acEntity of
|
||||
processAgentMessage user@User {userId, profile} agentConnId agentMessage =
|
||||
(withStore (\st -> getConnectionEntity st user agentConnId) >>= updateConnStatus) >>= \case
|
||||
RcvDirectMsgConnection conn contact_ ->
|
||||
processDirectMessage agentMessage conn contact_
|
||||
RcvGroupMsgConnection conn gInfo m ->
|
||||
@@ -503,6 +500,14 @@ processAgentMessage user@User {userId, profile} agentConnId agentMessage = do
|
||||
UserContactConnection conn uc ->
|
||||
processUserContactRequest agentMessage conn uc
|
||||
where
|
||||
updateConnStatus :: ConnectionEntity -> m ConnectionEntity
|
||||
updateConnStatus acEntity = case agentMsgConnStatus agentMessage of
|
||||
Just connStatus -> do
|
||||
let conn = (entityConnection acEntity) {connStatus}
|
||||
withStore $ \st -> updateConnectionStatus st conn connStatus
|
||||
pure acEntity {entityConnection = conn}
|
||||
Nothing -> pure acEntity
|
||||
|
||||
isMember :: MemberId -> GroupInfo -> [GroupMember] -> Bool
|
||||
isMember memId GroupInfo {membership} members =
|
||||
sameMemberId memId membership || isJust (find (sameMemberId memId) members)
|
||||
|
||||
@@ -15,10 +15,10 @@ module Simplex.Chat.Protocol where
|
||||
import Control.Monad ((<=<))
|
||||
import Data.Aeson (FromJSON, ToJSON, (.:), (.:?), (.=))
|
||||
import qualified Data.Aeson as J
|
||||
import qualified Data.Aeson.KeyMap as JM
|
||||
import qualified Data.Aeson.Types as JT
|
||||
import qualified Data.Attoparsec.ByteString.Char8 as A
|
||||
import qualified Data.ByteString.Lazy.Char8 as LB
|
||||
import qualified Data.Aeson.KeyMap as JM
|
||||
import Data.Text (Text)
|
||||
import Data.Text.Encoding (decodeLatin1, encodeUtf8)
|
||||
import Database.SQLite.Simple.FromField (FromField (..))
|
||||
@@ -31,21 +31,13 @@ import Simplex.Messaging.Encoding.String
|
||||
import Simplex.Messaging.Util ((<$?>))
|
||||
|
||||
data ConnectionEntity
|
||||
= RcvDirectMsgConnection Connection (Maybe Contact)
|
||||
| RcvGroupMsgConnection Connection GroupInfo GroupMember
|
||||
| SndFileConnection Connection SndFileTransfer
|
||||
| RcvFileConnection Connection RcvFileTransfer
|
||||
| UserContactConnection Connection UserContact
|
||||
= RcvDirectMsgConnection {entityConnection :: Connection, contact :: Maybe Contact}
|
||||
| RcvGroupMsgConnection {entityConnection :: Connection, groupInfo :: GroupInfo, groupMember :: GroupMember}
|
||||
| SndFileConnection {entityConnection :: Connection, sndFileTransfer :: SndFileTransfer}
|
||||
| RcvFileConnection {entityConnection :: Connection, rcvFileTransfer :: RcvFileTransfer}
|
||||
| UserContactConnection {entityConnection :: Connection, userContact :: UserContact}
|
||||
deriving (Eq, Show)
|
||||
|
||||
fromConnection :: ConnectionEntity -> Connection
|
||||
fromConnection = \case
|
||||
RcvDirectMsgConnection conn _ -> conn
|
||||
RcvGroupMsgConnection conn _ _ -> conn
|
||||
SndFileConnection conn _ -> conn
|
||||
RcvFileConnection conn _ -> conn
|
||||
UserContactConnection conn _ -> conn
|
||||
|
||||
-- chat message is sent as JSON with these properties
|
||||
data AppMessage = AppMessage
|
||||
{ event :: Text,
|
||||
|
||||
Reference in New Issue
Block a user