[telepathy-gabble/master] Correctly update peer's full JID on incoming IMs.
Will Thompson
will.thompson at collabora.co.uk
Fri Jun 19 09:49:02 PDT 2009
I inverted the sense of a conditional while Messages-ifying Gabble,
breaking the code that sends IMs to the resource that most recently
replied. Fixes fd.o#22369, and adds a regression test.
---
src/im-channel.c | 2 +-
tests/twisted/Makefile.am | 1 +
tests/twisted/text/send-to-correct-resource.py | 60 ++++++++++++++++++++++++
3 files changed, 62 insertions(+), 1 deletions(-)
create mode 100644 tests/twisted/text/send-to-correct-resource.py
diff --git a/src/im-channel.c b/src/im-channel.c
index 1354183..206f2de 100644
--- a/src/im-channel.c
+++ b/src/im-channel.c
@@ -535,7 +535,7 @@ _gabble_im_channel_receive (GabbleIMChannel *chan,
base_conn = (TpBaseConnection *) priv->conn;
/* update peer's full JID if it's changed */
- if (send_error != GABBLE_TEXT_CHANNEL_SEND_NO_ERROR &&
+ if (send_error == GABBLE_TEXT_CHANNEL_SEND_NO_ERROR &&
0 != strcmp (from, priv->peer_jid))
{
g_free (priv->peer_jid);
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index b041ea8..3686cfb 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -41,6 +41,7 @@ TWISTED_TESTS = \
text/ensure.py \
text/respawn.py \
text/send-error.py \
+ text/send-to-correct-resource.py \
text/test-chat-state.py \
text/test-text-delayed.py \
text/test-text-no-body.py \
diff --git a/tests/twisted/text/send-to-correct-resource.py b/tests/twisted/text/send-to-correct-resource.py
new file mode 100644
index 0000000..d386665
--- /dev/null
+++ b/tests/twisted/text/send-to-correct-resource.py
@@ -0,0 +1,60 @@
+"""
+Regression test for https://bugs.freedesktop.org/show_bug.cgi?id=22369.
+"""
+
+from twisted.words.xish import domish
+
+from servicetest import wrap_channel
+from gabbletest import exec_test
+import constants as cs
+
+def test(q, bus, conn, stream):
+ conn.Connect()
+ q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
+
+ # <wjt> I need a random name generator
+ # <fledermaus> Macro-Variable Spin Gel
+ contact = 'macro-variable.spin.gel at example.com'
+ contact_a = '%s/n810' % contact
+ contact_b = '%s/laptop' % contact
+
+ path, _ = conn.Requests.CreateChannel({
+ cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT,
+ cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
+ cs.TARGET_ID: contact,
+ })
+ chan = wrap_channel(bus.get_object(conn.bus_name, path), 'Text')
+
+ # When we start a conversation, Gabble should send to the bare JID.
+ chan.Text.Send(0, 'hey, you around?')
+ q.expect('stream-message', to=contact)
+
+ # A particular resource replies.
+ m = domish.Element((None, 'message'))
+ m['from'] = contact_a
+ m['type'] = 'chat'
+ m.addElement('body', content="i'm on a beach at Gran Canaria!")
+ stream.send(m)
+
+ q.expect('dbus-signal', signal='Received')
+
+ # Now that we got a reply from a particular resource, Gabble should reply
+ # there.
+ chan.Text.Send(0, 'nice')
+ q.expect('stream-message', to=contact_a)
+
+ # Now another resource messages us
+ m = domish.Element((None, 'message'))
+ m['from'] = contact_b
+ m['type'] = 'chat'
+ m.addElement('body', content="I brought my laptop to the Empathy hackfest")
+ stream.send(m)
+
+ q.expect('dbus-signal', signal='Received')
+
+ # 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)
+
+if __name__ == '__main__':
+ exec_test(test)
--
1.5.6.5
More information about the telepathy-commits
mailing list