From a9a4935ed99da3abdf239cdc1bf3aa35db907a16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Cargo=C3=ABt?= Date: Fri, 3 Apr 2015 09:47:31 +0200 Subject: [PATCH 1/2] Fix a timeout bug in chat state notifications --- converse.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/converse.js b/converse.js index 4169a77c6..5cd4a0808 100644 --- a/converse.js +++ b/converse.js @@ -1243,12 +1243,11 @@ * (string) state - The chat state (consts ACTIVE, COMPOSING, PAUSED, INACTIVE, GONE) * (no_save) no_save - Just do the cleanup or setup but don't actually save the state. */ - if (_.contains([ACTIVE, INACTIVE, GONE], state)) { - if (typeof this.chat_state_timeout !== 'undefined') { - clearTimeout(this.chat_state_timeout); - delete this.chat_state_timeout; - } - } else if (state === COMPOSING) { + if (typeof this.chat_state_timeout !== 'undefined') { + clearTimeout(this.chat_state_timeout); + delete this.chat_state_timeout; + } + if (state === COMPOSING) { this.chat_state_timeout = setTimeout( $.proxy(this.setChatState, this), converse.TIMEOUTS.PAUSED, PAUSED); } else if (state === PAUSED) { From 5a488333ec96762a6b1dd8650714fbf085816472 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Sat, 4 Apr 2015 11:25:50 +0200 Subject: [PATCH 2/2] Add a test and changelog entry for #359 updates #359 --- docs/CHANGES.rst | 1 + spec/chatbox.js | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/docs/CHANGES.rst b/docs/CHANGES.rst index a778c0838..bc7e45abe 100644 --- a/docs/CHANGES.rst +++ b/docs/CHANGES.rst @@ -10,6 +10,7 @@ Changelog * #356 Fix the plugin extend function. [floriancargoet] * #357 Fix the known bug where a state notification reopens a chat box. [floriancargoet] * #358 Bugfix. Chat rooms show the same occupants bug. [floriancargoet] +* #359 Fix a timeout bug in chat state notifications. [floriancargoet] 0.9.1 (2015-03-26) ------------------ diff --git a/spec/chatbox.js b/spec/chatbox.js index 091cf4eb3..3b2405949 100644 --- a/spec/chatbox.js +++ b/spec/chatbox.js @@ -781,6 +781,8 @@ var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; test_utils.openChatBoxFor(contact_jid); var view = this.chatboxviews.get(contact_jid); + spyOn(converse.connection, 'send'); + spyOn(view, 'setChatState').andCallThrough(); runs(function () { expect(view.model.get('chat_state')).toBe('active'); view.keyPressed({ @@ -788,16 +790,39 @@ keyCode: 1 }); expect(view.model.get('chat_state')).toBe('composing'); - spyOn(converse.connection, 'send'); + expect(converse.connection.send).toHaveBeenCalled(); + var $stanza = $(converse.connection.send.argsForCall[0][0].tree()); + expect($stanza.children().prop('tagName')).toBe('composing'); }); waits(250); runs(function () { expect(view.model.get('chat_state')).toBe('paused'); expect(converse.connection.send).toHaveBeenCalled(); - var $stanza = $(converse.connection.send.argsForCall[0][0].tree()); + var $stanza = $(converse.connection.send.argsForCall[1][0].tree()); expect($stanza.attr('to')).toBe(contact_jid); expect($stanza.children().length).toBe(1); expect($stanza.children().prop('tagName')).toBe('paused'); + // Test #359. A paused notification should not be sent + // out if the user simply types longer than the + // timeout. + view.keyPressed({ + target: view.$el.find('textarea.chat-textarea'), + keyCode: 1 + }); + expect(view.setChatState).toHaveBeenCalled(); + expect(view.model.get('chat_state')).toBe('composing'); + }); + waits(100); + runs(function () { + view.keyPressed({ + target: view.$el.find('textarea.chat-textarea'), + keyCode: 1 + }); + expect(view.model.get('chat_state')).toBe('composing'); + }); + waits(150); + runs(function () { + expect(view.model.get('chat_state')).toBe('composing'); }); }, converse));