Initial work on adding support for sending <paused> and <gone> chat states.
This commit is contained in:
parent
f738698525
commit
3175bddc46
42
converse.js
42
converse.js
@ -1191,9 +1191,29 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
keyPressed: function (ev) {
|
keyPressed: function (ev) {
|
||||||
|
var sendChatState = function () {
|
||||||
|
if (this.model.get('chat_state', 'composing')) {
|
||||||
|
this.model.set('chat_state', 'paused');
|
||||||
|
converse.connection.send(
|
||||||
|
$msg({'to':this.model.get('jid'), 'type': 'chat'})
|
||||||
|
.c('paused', {'xmlns':'http://jabber.org/protocol/chatstates'})
|
||||||
|
);
|
||||||
|
// TODO: Set a new timeout here to send a chat_state of <gone>
|
||||||
|
}
|
||||||
|
};
|
||||||
var $textarea = $(ev.target),
|
var $textarea = $(ev.target),
|
||||||
message, notify, composing;
|
args = arguments,
|
||||||
if(ev.keyCode == KEY.ENTER) {
|
context = this,
|
||||||
|
message;
|
||||||
|
var later = function() {
|
||||||
|
delete this.chat_state_timeout;
|
||||||
|
sendChatState.apply(context, args);
|
||||||
|
};
|
||||||
|
if (typeof this.chat_state_timeout !== 'undefined') {
|
||||||
|
clearTimeout(this.chat_state_timeout);
|
||||||
|
delete this.chat_state_timeout; // XXX: Necessary?
|
||||||
|
}
|
||||||
|
if (ev.keyCode == KEY.ENTER) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
message = $textarea.val();
|
message = $textarea.val();
|
||||||
$textarea.val('').focus();
|
$textarea.val('').focus();
|
||||||
@ -1205,19 +1225,21 @@
|
|||||||
}
|
}
|
||||||
converse.emit('messageSend', message);
|
converse.emit('messageSend', message);
|
||||||
}
|
}
|
||||||
this.$el.data('composing', false);
|
this.model.set('chat_state', null);
|
||||||
|
// TODO: need to put timeout for <gone> state here?
|
||||||
} else if (!this.model.get('chatroom')) {
|
} else if (!this.model.get('chatroom')) {
|
||||||
// composing data is only for single user chat
|
// chat state data is only for single user chat
|
||||||
composing = this.$el.data('composing');
|
this.chat_state_timeout = setTimeout(later, 10000);
|
||||||
if (!composing) {
|
if (this.model.get('chat_state') != "composing") {
|
||||||
if (ev.keyCode != 47) {
|
if (ev.keyCode != 47) {
|
||||||
// We don't send composing messages if the message
|
// We don't send composing messages if the message
|
||||||
// starts with forward-slash.
|
// starts with forward-slash.
|
||||||
notify = $msg({'to':this.model.get('jid'), 'type': 'chat'})
|
converse.connection.send(
|
||||||
.c('composing', {'xmlns':'http://jabber.org/protocol/chatstates'});
|
$msg({'to':this.model.get('jid'), 'type': 'chat'})
|
||||||
converse.connection.send(notify);
|
.c('composing', {'xmlns':'http://jabber.org/protocol/chatstates'})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
this.$el.data('composing', true);
|
this.model.set('chat_state', 'composing');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user