feat(operators): warn when no server resolves names

Mirror USWNoChatRelays: validateUserServers emits USWNoNamesServers
when no enabled server of an enabled operator carries the SMP names
role. noNamesServersWarns is self-contained with local predicates,
matching the sibling noChatRelaysWarns; noServersErrs is untouched.
This commit is contained in:
shum
2026-06-13 09:29:26 +00:00
parent ebc7af3250
commit 93d62c2aee
+13 -3
View File
@@ -511,7 +511,9 @@ data UserServersError
| USEDuplicateChatRelayAddress {duplicateChatRelay :: Text, duplicateAddress :: ShortLinkContact}
deriving (Show)
data UserServersWarning = USWNoChatRelays {user :: Maybe User}
data UserServersWarning
= USWNoChatRelays {user :: Maybe User}
| USWNoNamesServers {user :: Maybe User}
deriving (Show)
validateUserServers :: UserServersClass u' => [u'] -> [(User, [UserOperatorServers])] -> ([UserServersError], [UserServersWarning])
@@ -552,8 +554,8 @@ validateUserServers curr others = (currUserErrs <> concatMap otherUserErrs other
addAddress (xs, dups) x
| any (sameShortLinkContact x) xs = (xs, x : dups)
| otherwise = (x : xs, dups)
currUserWarns = noChatRelaysWarns Nothing curr
otherUserWarns (user, uss) = noChatRelaysWarns (Just user) uss
currUserWarns = noChatRelaysWarns Nothing curr <> noNamesServersWarns Nothing curr
otherUserWarns (user, uss) = noChatRelaysWarns (Just user) uss <> noNamesServersWarns (Just user) uss
noChatRelaysWarns :: UserServersClass u => Maybe User -> [u] -> [UserServersWarning]
noChatRelaysWarns user uss
| noChatRelays opEnabled = [USWNoChatRelays user]
@@ -561,6 +563,14 @@ validateUserServers curr others = (currUserErrs <> concatMap otherUserErrs other
where
noChatRelays cond = not $ any relayEnabled $ userChatRelays $ filter cond uss
relayEnabled (AUCR _ UserChatRelay {deleted, enabled}) = enabled && not deleted
noNamesServersWarns :: UserServersClass u => Maybe User -> [u] -> [UserServersWarning]
noNamesServersWarns user uss
| noNamesServers = [USWNoNamesServers user]
| otherwise = []
where
noNamesServers = not $ any srvEnabled $ userServers SPSMP $ filter namesEnabled uss
srvEnabled (AUS _ UserServer {deleted, enabled}) = enabled && not deleted
namesEnabled = maybe True (\op@ServerOperator {enabled} -> enabled && names (operatorRoles SPSMP op)) . operator'
userChatRelays :: UserServersClass u => [u] -> [AUserChatRelay]
userChatRelays = map aUserChatRelay' . concatMap chatRelays'
opEnabled :: UserServersClass u => u -> Bool