summaryrefslogtreecommitdiff
path: root/Presence
diff options
context:
space:
mode:
Diffstat (limited to 'Presence')
-rw-r--r--Presence/XMPP.hs50
1 files changed, 44 insertions, 6 deletions
diff --git a/Presence/XMPP.hs b/Presence/XMPP.hs
index fb53c2fb..f25d3261 100644
--- a/Presence/XMPP.hs
+++ b/Presence/XMPP.hs
@@ -83,7 +83,7 @@ import Data.Conduit.Blaze
83import Data.List (find) 83import Data.List (find)
84import qualified Text.Show.ByteString as L 84import qualified Text.Show.ByteString as L
85import NestingXML 85import NestingXML
86import Data.Set as Set (Set) 86import Data.Set as Set (Set,(\\))
87import qualified Data.Set as Set 87import qualified Data.Set as Set
88import qualified Data.Map as Map 88import qualified Data.Map as Map
89import Data.Map as Map (Map) 89import Data.Map as Map (Map)
@@ -331,10 +331,48 @@ iq_service_unavailable host iq_id mjid req =
331 , EventEndElement "{jabber:client}iq" 331 , EventEndElement "{jabber:client}iq"
332 ] 332 ]
333 333
334getRoster session = do 334attr name value = (name,[ContentText value])
335 budies <- getMyBuddies session 335
336 subscribers <- getMySubscribers session 336getRoster session iqid = do
337 return ([]::[Event]) -- TODO 337 let getlist f = do
338 bs <- f session
339 -- js <- mapM parseHostNameJID bs
340 return (Set.fromList bs) -- js)
341 buddies <- getlist getMyBuddies
342 subscribers <- getlist getMySubscribers
343 subnone <- getlist getMyOthers
344 solicited <- getlist getMySolicited
345 let subto = buddies \\ subscribers
346 let subfrom = subscribers \\ buddies
347 let subboth = Set.intersection buddies subscribers
348 -- solicited -> ask='subscribe'
349 jid <- getJID session
350 let dest = toStrict . L.decodeUtf8 . bshow $ jid
351 let items= (xmlify solicited "to" subto)
352 ++(xmlify solicited "from" subfrom)
353 ++(xmlify solicited "both" subboth)
354 ++(xmlify solicited "none" subnone)
355 openiq = [EventBeginElement "{jabber:client}iq"
356 [ attr "id" iqid
357 , attr "to" dest
358 , attr "type" "result" ]
359 ,EventBeginElement "{jabber:iq:roster}query"
360 [] -- todo: ver?
361 ]
362 closeiq = [EventEndElement "{jabber:iq:roster}query"
363 ,EventEndElement "{jabber:client}iq"]
364 return $ openiq ++ items ++ closeiq
365 where
366 xmlify solicited stype set = flip concatMap (Set.toList set)
367 $ \jid ->
368 [ EventBeginElement "item"
369 ([("jid",[ContentText (toStrict . L.decodeUtf8 $ jid)])
370 ,("subscription",[ContentText stype])
371 ]++if Set.member jid solicited
372 then [("ask",[ContentText "subscribe"])]
373 else [] )
374 , EventEndElement "item"
375 ]
338 376
339handleIQGet session cmdChan tag = do 377handleIQGet session cmdChan tag = do
340 withJust (lookupAttrib "id" (tagAttrs tag)) $ \stanza_id -> do 378 withJust (lookupAttrib "id" (tagAttrs tag)) $ \stanza_id -> do
@@ -371,7 +409,7 @@ handleIQGet session cmdChan tag = do
371 -- [ContentText "32a337c2-7b22-45b6-9d21-15ded0d079ec"]) 409 -- [ContentText "32a337c2-7b22-45b6-9d21-15ded0d079ec"])
372 -- ,(Name {nameLocalName = "type", nameNamespace = Nothing, namePrefix = Nothing}, 410 -- ,(Name {nameLocalName = "type", nameNamespace = Nothing, namePrefix = Nothing},
373 -- [ContentText "get"])] 411 -- [ContentText "get"])]
374 roster <- getRoster session 412 roster <- getRoster session stanza_id
375 atomically . writeTChan cmdChan . Send $ roster 413 atomically . writeTChan cmdChan . Send $ roster
376 req -> unhandledGet req 414 req -> unhandledGet req
377 415