From fe3087cc86552fdccac5b90d49d998611a493a45 Mon Sep 17 00:00:00 2001 From: joe Date: Sun, 16 Mar 2014 14:04:14 -0400 Subject: Deliver messages to X via notify-send. --- xmppServer.hs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'xmppServer.hs') diff --git a/xmppServer.hs b/xmppServer.hs index ef71380b..a406366a 100644 --- a/xmppServer.hs +++ b/xmppServer.hs @@ -434,16 +434,22 @@ deliverMessage state fail msg = if not mine then fail else do let to' = unsplitJID (n,h,r) cmap <- atomically . readTVar $ clientsByUser state - flip (maybe fail) n $ \n -> do - flip (maybe fail) (Map.lookup n cmap) $ \presence_container -> do - buds <- configText ConfigFiles.getBuddies n - from' <- do - flip (maybe $ return Nothing) (stanzaFrom msg) $ \from -> do - (_,trip) <- rewriteJIDForClient laddr from buds - return . Just $ unsplitJID trip - let ks = Map.keys (networkClients presence_container) - chans = mapMaybe (flip Map.lookup key_to_chan) ks - if null chans then deliverToConsole state fail msg else do + (from',chans,ks) <- do + flip (maybe $ return (Nothing,[],[])) n $ \n -> do + buds <- configText ConfigFiles.getBuddies n + from' <- do + flip (maybe $ return Nothing) (stanzaFrom msg) $ \from -> do + (_,trip) <- rewriteJIDForClient laddr from buds + return . Just $ unsplitJID trip + let nope = return (from',[],[]) + flip (maybe nope) (Map.lookup n cmap) $ \presence_container -> do + let ks = Map.keys (networkClients presence_container) + chans = mapMaybe (flip Map.lookup key_to_chan) ks + return (from',chans,ks) + putStrLn $ "chan count: " ++ show (length chans) + let msg' = msg { stanzaTo=Just to' + , stanzaFrom=from' } + if null chans then deliverToConsole state fail msg' else do forM_ chans $ \Conn { connChan=chan} -> do putStrLn $ "sending "++show (stanzaId msg)++" to clients "++show ks -- TODO: Cloning isn't really neccessary unless there are multiple @@ -452,8 +458,7 @@ deliverMessage state fail msg = -- consumable stanzas and announcables use write-only broadcast -- channels that must be cloned in order to be consumed. -- For now, we are doing redundant cloning. - dup <- cloneStanza (msg { stanzaTo=Just to' - , stanzaFrom=from' }) + dup <- cloneStanza msg' sendModifiedStanzaToClient dup chan -- cgit v1.2.3