mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-06-04 16:52:01 +00:00
core, ui: errors for blocked files and contact addresses (#5510)
* core, ui: errors for blocked files and contact addresses * android * iOS: How it works, stub for blog post * android: blocked errors WIP * android: alert with button * update * fix encoding * nix * simplexmq
This commit is contained in:
@@ -284,6 +284,7 @@ processAgentMsgSndFile _corrId aFileId msg = do
|
||||
agentFileError :: AgentErrorType -> FileError
|
||||
agentFileError = \case
|
||||
XFTP _ XFTP.AUTH -> FileErrAuth
|
||||
XFTP srv (XFTP.BLOCKED info) -> FileErrBlocked srv info
|
||||
FILE NO_FILE -> FileErrNoFile
|
||||
BROKER _ e -> brokerError FileErrRelay e
|
||||
e -> FileErrOther $ tshow e
|
||||
|
||||
@@ -52,7 +52,7 @@ import Simplex.Messaging.Crypto.File (CryptoFile (..))
|
||||
import qualified Simplex.Messaging.Crypto.File as CF
|
||||
import Simplex.Messaging.Encoding.String
|
||||
import Simplex.Messaging.Parsers (defaultJSON, dropPrefix, enumJSON, fromTextField_, parseAll, sumTypeJSON)
|
||||
import Simplex.Messaging.Protocol (MsgBody)
|
||||
import Simplex.Messaging.Protocol (BlockingInfo, MsgBody)
|
||||
import Simplex.Messaging.Util (eitherToMaybe, safeDecodeUtf8, (<$?>))
|
||||
#if defined(dbPostgres)
|
||||
import Database.PostgreSQL.Simple.FromField (FromField (..))
|
||||
@@ -741,6 +741,7 @@ aciFileStatusJSON = \case
|
||||
|
||||
data FileError
|
||||
= FileErrAuth
|
||||
| FileErrBlocked {server :: String, blockInfo :: BlockingInfo}
|
||||
| FileErrNoFile
|
||||
| FileErrRelay {srvError :: SrvError}
|
||||
| FileErrOther {fileError :: Text}
|
||||
@@ -749,14 +750,16 @@ data FileError
|
||||
instance StrEncoding FileError where
|
||||
strEncode = \case
|
||||
FileErrAuth -> "auth"
|
||||
FileErrBlocked srv info -> "blocked " <> strEncode (srv, info)
|
||||
FileErrNoFile -> "no_file"
|
||||
FileErrRelay srvErr -> "relay " <> strEncode srvErr
|
||||
FileErrOther e -> "other " <> encodeUtf8 e
|
||||
strP =
|
||||
A.takeWhile1 (/= ' ') >>= \case
|
||||
"auth" -> pure FileErrAuth
|
||||
"blocked" -> FileErrBlocked <$> _strP <*> _strP
|
||||
"no_file" -> pure FileErrNoFile
|
||||
"relay" -> FileErrRelay <$> (A.space *> strP)
|
||||
"relay" -> FileErrRelay <$> _strP
|
||||
"other" -> FileErrOther . safeDecodeUtf8 <$> (A.space *> A.takeByteString)
|
||||
s -> FileErrOther . safeDecodeUtf8 . (s <>) <$> A.takeByteString
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ import qualified Simplex.Messaging.Crypto.Ratchet as CR
|
||||
import Simplex.Messaging.Encoding
|
||||
import Simplex.Messaging.Encoding.String
|
||||
import Simplex.Messaging.Parsers (dropPrefix, taggedObjectJSON)
|
||||
import Simplex.Messaging.Protocol (AProtoServerWithAuth (..), AProtocolType, ProtocolServer (..), ProtocolTypeI, SProtocolType (..), UserProtocol)
|
||||
import Simplex.Messaging.Protocol (AProtoServerWithAuth (..), AProtocolType, BlockingInfo (..), BlockingReason (..), ProtocolServer (..), ProtocolTypeI, SProtocolType (..), UserProtocol)
|
||||
import qualified Simplex.Messaging.Protocol as SMP
|
||||
import Simplex.Messaging.Transport.Client (TransportHost (..))
|
||||
import Simplex.Messaging.Util (safeDecodeUtf8, tshow)
|
||||
@@ -2223,6 +2223,12 @@ viewChatError isCmd logLevel testView = \case
|
||||
[ withConnEntity
|
||||
<> "error: connection authorization failed - this could happen if connection was deleted, secured with different credentials, or due to a bug - please re-create the connection"
|
||||
]
|
||||
SMP _ (SMP.BLOCKED BlockingInfo {reason}) ->
|
||||
[withConnEntity <> "error: connection blocked by server operator: " <> reasonStr]
|
||||
where
|
||||
reasonStr = case reason of
|
||||
BRSpam -> "spam"
|
||||
BRContent -> "content violates conditions of use"
|
||||
BROKER _ NETWORK | not isCmd -> []
|
||||
BROKER _ TIMEOUT | not isCmd -> []
|
||||
AGENT A_DUPLICATE -> [withConnEntity <> "error: AGENT A_DUPLICATE" | logLevel == CLLDebug || isCmd]
|
||||
|
||||
Reference in New Issue
Block a user