From 697b1398be2937fcb34b3209c2b1f074de4be473 Mon Sep 17 00:00:00 2001
From: Philipp Balzarek
Date: Mon, 11 Jun 2012 20:04:21 +0200
Subject: [PATCH] make bind save the received JID
---
source/Network/Xmpp.hs | 4 ++--
source/Network/Xmpp/Bind.hs | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/source/Network/Xmpp.hs b/source/Network/Xmpp.hs
index b673831..dc0cb0d 100644
--- a/source/Network/Xmpp.hs
+++ b/source/Network/Xmpp.hs
@@ -180,6 +180,6 @@ auth :: Text.Text -- ^ The username
-> XmppConMonad (Either AuthError Jid)
auth username passwd resource = runErrorT $ do
ErrorT $ xmppSasl [scramSha1 username Nothing passwd]
- res <- lift $ xmppBind resource
+ jid <- lift $ xmppBind resource
lift $ xmppStartSession
- return res
+ return jid
diff --git a/source/Network/Xmpp/Bind.hs b/source/Network/Xmpp/Bind.hs
index d09d82d..cf00495 100644
--- a/source/Network/Xmpp/Bind.hs
+++ b/source/Network/Xmpp/Bind.hs
@@ -13,6 +13,8 @@ import Network.Xmpp.Types
import Network.Xmpp.Pickle
import Network.Xmpp.Monad
+import Control.Monad.State(modify)
+
-- Produces a `bind' element, optionally wrapping a resource.
bindBody :: Maybe Text -> Element
bindBody = pickleElem $
@@ -29,6 +31,7 @@ xmppBind rsrc = do
answer <- xmppSendIQ' "bind" Nothing Set Nothing (bindBody rsrc)
let Right IQResult{iqResultPayload = Just b} = answer -- TODO: Error handling
let Right jid = unpickleElem jidP b
+ modify (\s -> s{sJid = Just jid})
return jid
where
-- Extracts the character data in the `jid' element.