Skip to content

Commit

Permalink
Fixed typing status for typing from different devices (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
smitbose authored and jcbrand committed Mar 16, 2017
1 parent 24b39b3 commit c976f3f
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

- #585 Duplicate contact created due to JID case sensivity [saganshul]
- #628 Fixes the bug in displaying chat status during private chat. [saganshul]
- #797 Time format made configurable. [smitbose]
- #628 Changes the message displayed while typing from a different resource of the same user. [smitbose]
- #675 Time format made configurable. [smitbose]
- #806 The `_converse.listen` API event listeners aren't triggered. [jcbrand]
- #807 Error: Plugin "converse-dragresize" tried to override HeadlinesBoxView but it's not found. [jcbrand]

Expand Down
74 changes: 74 additions & 0 deletions spec/chatbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,43 @@
var $events = chatboxview.$el.find('.chat-event');
expect($events.text()).toEqual(mock.cur_names[1] + ' is typing');
}));

it("can be a composing carbon message that this user sent from a different client", mock.initConverse(function (_converse) {
test_utils.createContacts(_converse, 'current');

// Send a message from a different resource
spyOn(_converse, 'log');
var recipient_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(_converse, recipient_jid);
var msg = $msg({
'from': _converse.bare_jid,
'id': (new Date()).getTime(),
'to': _converse.connection.jid,
'type': 'chat',
'xmlns': 'jabber:client'
}).c('sent', {'xmlns': 'urn:xmpp:carbons:2'})
.c('forwarded', {'xmlns': 'urn:xmpp:forward:0'})
.c('message', {
'xmlns': 'jabber:client',
'from': _converse.bare_jid+'/another-resource',
'to': recipient_jid,
'type': 'chat'
}).c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
_converse.chatboxes.onMessage(msg);

// Check that the chatbox and its view now exist
var chatbox = _converse.chatboxes.get(recipient_jid);
var chatboxview = _converse.chatboxviews.get(recipient_jid);
// Check that the message was received and check the message parameters
expect(chatbox.messages.length).toEqual(1);
var msg_obj = chatbox.messages.models[0];
expect(msg_obj.get('fullname')).toEqual(_converse.xmppstatus.get('fullname'));
expect(msg_obj.get('sender')).toEqual('me');
expect(msg_obj.get('delayed')).toEqual(false);
var $chat_content = chatboxview.$el.find('.chat-content');
var status_text = $chat_content.find('.chat-info.chat-event').text();
expect(status_text).toBe('Typing from another device');
}));
});

describe("A paused notification", function () {
Expand Down Expand Up @@ -1477,6 +1514,43 @@
var $events = chatboxview.$el.find('.chat-event');
expect($events.text()).toEqual(mock.cur_names[1] + ' has stopped typing');
}));

it("can be a paused carbon message that this user sent from a different client", mock.initConverse(function (_converse) {
test_utils.createContacts(_converse, 'current');

// Send a message from a different resource
spyOn(_converse, 'log');
var recipient_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(_converse, recipient_jid);
var msg = $msg({
'from': _converse.bare_jid,
'id': (new Date()).getTime(),
'to': _converse.connection.jid,
'type': 'chat',
'xmlns': 'jabber:client'
}).c('sent', {'xmlns': 'urn:xmpp:carbons:2'})
.c('forwarded', {'xmlns': 'urn:xmpp:forward:0'})
.c('message', {
'xmlns': 'jabber:client',
'from': _converse.bare_jid+'/another-resource',
'to': recipient_jid,
'type': 'chat'
}).c('paused', {'xmlns': Strophe.NS.CHATSTATES}).tree();
_converse.chatboxes.onMessage(msg);

// Check that the chatbox and its view now exist
var chatbox = _converse.chatboxes.get(recipient_jid);
var chatboxview = _converse.chatboxviews.get(recipient_jid);
// Check that the message was received and check the message parameters
expect(chatbox.messages.length).toEqual(1);
var msg_obj = chatbox.messages.models[0];
expect(msg_obj.get('fullname')).toEqual(_converse.xmppstatus.get('fullname'));
expect(msg_obj.get('sender')).toEqual('me');
expect(msg_obj.get('delayed')).toEqual(false);
var $chat_content = chatboxview.$el.find('.chat-content');
var status_text = $chat_content.find('.chat-info.chat-event').text();
expect(status_text).toBe('Stopped typing on the other device');
}));
});

describe("An inactive notifciation", function () {
Expand Down
14 changes: 12 additions & 2 deletions src/converse-chatview.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,20 @@

handleChatStateMessage: function (message) {
if (message.get('chat_state') === _converse.COMPOSING) {
this.showStatusNotification(message.get('fullname')+' '+__('is typing'));
if(message.get('sender') === 'me') {
this.showStatusNotification(__('Typing from another device'));
}
else {
this.showStatusNotification(message.get('fullname')+' '+__('is typing'));
}
this.clear_status_timeout = window.setTimeout(this.clearStatusNotification.bind(this), 30000);
} else if (message.get('chat_state') === _converse.PAUSED) {
this.showStatusNotification(message.get('fullname')+' '+__('has stopped typing'));
if(message.get('sender') === 'me') {
this.showStatusNotification(__('Stopped typing on the other device'));
}
else {
this.showStatusNotification(message.get('fullname')+' '+__('has stopped typing'));
}
} else if (_.includes([_converse.INACTIVE, _converse.ACTIVE], message.get('chat_state'))) {
this.$content.find('div.chat-event').remove();
} else if (message.get('chat_state') === _converse.GONE) {
Expand Down

0 comments on commit c976f3f

Please sign in to comment.