~singpolyma/cheogram-muc-bridge

3b77e21c249749ffa584a7ec079b50a2a9510601 — Stephen Paul Weber 5 months ago f0c1282
Allow no subscript
3 files changed, 6 insertions(+), 6 deletions(-)

M ConfigFile.hs
M Session.hs
M gateway.hs
M ConfigFile.hs => ConfigFile.hs +1 -1
@@ 18,7 18,7 @@ data ServerConfig = ServerConfig {

data MUC = MUC {
	jid :: XMPP.JID,
	tag :: Text,
	tag :: Maybe Text,
	nickChars :: Maybe String,
	nickLength :: Maybe Dhall.Natural
} deriving (Dhall.Generic, Dhall.FromDhall, Show)

M Session.hs => Session.hs +4 -4
@@ 63,7 63,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 Nothing) (s"XMPP")
		(Config.MUC targetMuc Nothing Nothing Nothing) Nothing

isGhost :: (MonadIO m) => Config.Config -> XMPP.JID -> m Bool
isGhost config from = do


@@ 74,7 74,7 @@ isGhost config from = do
	where
	nick = fromMaybe mempty $ XMPP.strResource <$> XMPP.jidResource from

sendPresenceToMUC :: Config.Config -> XMPP.Presence -> Config.MUC -> Text -> XMPP.XMPP ()
sendPresenceToMUC :: Config.Config -> XMPP.Presence -> Config.MUC -> Maybe Text -> XMPP.XMPP ()
sendPresenceToMUC config presence@XMPP.Presence {
	XMPP.presenceFrom = Just from@XMPP.JID {
		XMPP.jidResource = Just fromResource


@@ 103,8 103,8 @@ sendPresenceToMUC config presence@XMPP.Presence {
	nickReplacement = maybe id replaceNotInClass (Config.nickChars targetMuc)
	target = maybeAddNick (Config.jid targetMuc) $ nickReplacement $
		maybeTruncate nickLength fromNick ++ subscript
	subscript = s"[" ++ tag ++ s"]"
	nickLength = fmap (subtract 2 . subtract (T.length tag) . fromIntegral) $
	subscript = maybe mempty (\t -> s"[" ++ t ++ s"]") tag
	nickLength = fmap (subtract (T.length subscript) . fromIntegral) $
		Config.nickLength targetMuc
	fromNick = XMPP.strResource fromResource
sendPresenceToMUC _ _ _ _ = return ()

M gateway.hs => gateway.hs +1 -1
@@ 26,7 26,7 @@ hasMucCode code XMPP.Presence { XMPP.presencePayloads = p } =
	=<< XML.elementChildren
	=<< XML.isNamed (s"{http://jabber.org/protocol/muc#user}x") =<< p

fullTargets :: Config.Config -> XMPP.JID -> [(Config.MUC, Text)]
fullTargets :: Config.Config -> XMPP.JID -> [(Config.MUC, Maybe Text)]
fullTargets config from = concatMap (\bridge ->
		case find ((bareTxt from ==) . bareTxt . Config.jid) bridge of
			Just sourceMuc ->