[telepathy-gabble/master] Strip off peer resource on send error.
Will Thompson
will.thompson at collabora.co.uk
Fri Jun 19 10:16:23 PDT 2009
If we try to send an IM to a particular resource and get a send error,
Gabble should send future messages to the bare JID until we get a reply
from some other resource.
---
src/im-channel.c | 20 +++++++++++++++-----
tests/twisted/text/send-to-correct-resource.py | 20 +++++++++++++++++++-
2 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/src/im-channel.c b/src/im-channel.c
index 206f2de..f8d1df5 100644
--- a/src/im-channel.c
+++ b/src/im-channel.c
@@ -534,12 +534,22 @@ _gabble_im_channel_receive (GabbleIMChannel *chan,
priv = chan->priv;
base_conn = (TpBaseConnection *) priv->conn;
- /* update peer's full JID if it's changed */
- if (send_error == GABBLE_TEXT_CHANNEL_SEND_NO_ERROR &&
- 0 != strcmp (from, priv->peer_jid))
+ if (send_error == GABBLE_TEXT_CHANNEL_SEND_NO_ERROR)
{
- g_free (priv->peer_jid);
- priv->peer_jid = g_strdup (from);
+ /* update peer's full JID if it's changed */
+ if (tp_strdiff (from, priv->peer_jid))
+ {
+ g_free (priv->peer_jid);
+ priv->peer_jid = g_strdup (from);
+ }
+ }
+ else
+ {
+ /* strip off the resource (if any), since we just failed to send to it */
+ char *slash = strchr (priv->peer_jid, '/');
+
+ if (slash != NULL)
+ *slash = '\0';
}
msg = tp_message_new (base_conn, 2, 2);
diff --git a/tests/twisted/text/send-to-correct-resource.py b/tests/twisted/text/send-to-correct-resource.py
index d386665..52c5c95 100644
--- a/tests/twisted/text/send-to-correct-resource.py
+++ b/tests/twisted/text/send-to-correct-resource.py
@@ -7,6 +7,7 @@ from twisted.words.xish import domish
from servicetest import wrap_channel
from gabbletest import exec_test
import constants as cs
+import ns
def test(q, bus, conn, stream):
conn.Connect()
@@ -54,7 +55,24 @@ def test(q, bus, conn, stream):
# Gabble should have updated the resource it's sending to.
chan.Text.Send(0, "don't get sand in the keyboard")
- q.expect('stream-message', to=contact_b)
+ e = q.expect('stream-message', to=contact_b)
+
+ # But actually that resource has gone offline:
+ m = e.stanza
+ m['from'] = contact_b
+ m['type'] = 'error'
+ del m['to']
+
+ err = m.addElement((None, 'error'))
+ err['type'] = 'cancel'
+ err.addElement((ns.STANZA, 'item-not-found'))
+
+ stream.send(m)
+ q.expect('dbus-signal', signal='SendError')
+
+ # So as a result, Gabble should send the next message to the bare JID.
+ chan.Text.Send(0, "... i guess my warning was too late")
+ q.expect('stream-message', to=contact)
if __name__ == '__main__':
exec_test(test)
--
1.5.6.5
More information about the telepathy-commits
mailing list