M ConfigFile.hs => ConfigFile.hs +2 -1
@@ 19,7 19,8 @@ data ServerConfig = ServerConfig {
data MUC = MUC {
jid :: XMPP.JID,
tag :: Text,
- nickChars :: Maybe String
+ nickChars :: Maybe String,
+ nickLength :: Maybe Dhall.Natural
} deriving (Dhall.Generic, Dhall.FromDhall, Show)
data Config = Config {
M Session.hs => Session.hs +10 -3
@@ 57,7 57,7 @@ maybeAddNick muc nick = jid
sendPresence :: Config.Config -> XMPP.Presence -> XMPP.JID -> XMPP.XMPP ()
sendPresence config presence targetMuc =
sendPresenceToMUC config presence
- (Config.MUC targetMuc (s"XMPP") Nothing) (s"XMPP")
+ (Config.MUC targetMuc (s"XMPP") Nothing Nothing) (s"XMPP")
sendPresenceToMUC :: Config.Config -> XMPP.Presence -> Config.MUC -> Text -> XMPP.XMPP ()
sendPresenceToMUC config presence@XMPP.Presence {
@@ 84,8 84,11 @@ sendPresenceToMUC config presence@XMPP.Presence {
}
where
nickReplacement = maybe id replaceNotInClass (Config.nickChars targetMuc)
- target = maybeAddNick (Config.jid targetMuc) $
- nickReplacement $ fromNick ++ s"[" ++ tag ++ s"]"
+ target = maybeAddNick (Config.jid targetMuc) $ nickReplacement $
+ (maybeTruncate nickLength fromNick) ++ subscript
+ subscript = s"[" ++ tag ++ s"]"
+ nickLength = fmap (subtract 2 . subtract (T.length tag) . fromIntegral) $
+ Config.nickLength targetMuc
fromNick = XMPP.strResource fromResource
sendPresenceToMUC _ _ _ _ = return ()
@@ 96,6 99,10 @@ startOfInput = Atto.Parser $ \t pos more lose suc ->
else
lose t pos more [] "startOfInput"
+maybeTruncate :: Maybe Int -> Text -> Text
+maybeTruncate Nothing t = t
+maybeTruncate (Just l) t = T.take l t
+
replaceNotInClass :: String -> Text -> Text
replaceNotInClass klass txt = mconcat result
where
M config.dhall.example => config.dhall.example +2 -2
@@ 8,8 8,8 @@
},
mucs = [
[
- { jid = "first@muc", tag = "first", nickChars = Some "a-z" },
- { jid = "second@muc", tag = "second", nickChars = None Text }
+ { jid = "first@muc", tag = "first", nickChars = Some "a-z", nickLength = Some 15 },
+ { jid = "second@muc", tag = "second", nickChars = None Text, nickLength = None Natural }
]
]
}=
\ No newline at end of file