Chat state notifications are now also sent out from chat rooms.

This commit is contained in:
JC Brand 2016-08-12 12:52:33 +00:00
parent 9d28145724
commit fe46f2ee77
4 changed files with 24 additions and 15 deletions

View File

@ -2,6 +2,9 @@
## 1.0.6 (Unreleased) ## 1.0.6 (Unreleased)
- #674 Polish translation updated to the current master. [ser] - #674 Polish translation updated to the current master. [ser]
- Typing (i.e. chat state) notifications are now also sent out from MUC rooms. [jcbrand]
- `ChatRoomView.onChatRoomMessageSubmitted` has been renamed to
`onMessageSubmitted`, to make it the same as the method on `ChatBoxView`. [jcbrand]
- New config option [muc_nickname_from_jid](https://conversejs.org/docs/html/configuration.html#muc_nickname_from_jid) [jcbrand] - New config option [muc_nickname_from_jid](https://conversejs.org/docs/html/configuration.html#muc_nickname_from_jid) [jcbrand]
- New config option [muc_instant_rooms](https://conversejs.org/docs/html/configuration.html#muc_instant_rooms) [jcbrand] - New config option [muc_instant_rooms](https://conversejs.org/docs/html/configuration.html#muc_instant_rooms) [jcbrand]

View File

@ -728,11 +728,11 @@
it("to clear messages", function () { it("to clear messages", function () {
test_utils.openChatRoom('lounge', 'localhost', 'dummy'); test_utils.openChatRoom('lounge', 'localhost', 'dummy');
var view = converse.chatboxviews.get('lounge@localhost'); var view = converse.chatboxviews.get('lounge@localhost');
spyOn(view, 'onChatRoomMessageSubmitted').andCallThrough(); spyOn(view, 'onMessageSubmitted').andCallThrough();
spyOn(view, 'clearChatRoomMessages'); spyOn(view, 'clearChatRoomMessages');
view.$el.find('.chat-textarea').text('/clear'); view.$el.find('.chat-textarea').text('/clear');
view.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13})); view.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13}));
expect(view.onChatRoomMessageSubmitted).toHaveBeenCalled(); expect(view.onMessageSubmitted).toHaveBeenCalled();
expect(view.clearChatRoomMessages).toHaveBeenCalled(); expect(view.clearChatRoomMessages).toHaveBeenCalled();
}); });
@ -740,13 +740,13 @@
it("to ban a user", function () { it("to ban a user", function () {
test_utils.openChatRoom('lounge', 'localhost', 'dummy'); test_utils.openChatRoom('lounge', 'localhost', 'dummy');
var view = converse.chatboxviews.get('lounge@localhost'); var view = converse.chatboxviews.get('lounge@localhost');
spyOn(view, 'onChatRoomMessageSubmitted').andCallThrough(); spyOn(view, 'onMessageSubmitted').andCallThrough();
spyOn(view, 'setAffiliation').andCallThrough(); spyOn(view, 'setAffiliation').andCallThrough();
spyOn(view, 'showStatusNotification').andCallThrough(); spyOn(view, 'showStatusNotification').andCallThrough();
spyOn(view, 'validateRoleChangeCommand').andCallThrough(); spyOn(view, 'validateRoleChangeCommand').andCallThrough();
view.$el.find('.chat-textarea').text('/ban'); view.$el.find('.chat-textarea').text('/ban');
view.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13})); view.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13}));
expect(view.onChatRoomMessageSubmitted).toHaveBeenCalled(); expect(view.onMessageSubmitted).toHaveBeenCalled();
expect(view.validateRoleChangeCommand).toHaveBeenCalled(); expect(view.validateRoleChangeCommand).toHaveBeenCalled();
expect(view.showStatusNotification).toHaveBeenCalledWith( expect(view.showStatusNotification).toHaveBeenCalledWith(
"Error: the \"ban\" command takes two arguments, the user's nickname and optionally a reason.", "Error: the \"ban\" command takes two arguments, the user's nickname and optionally a reason.",
@ -755,10 +755,10 @@
expect(view.setAffiliation).not.toHaveBeenCalled(); expect(view.setAffiliation).not.toHaveBeenCalled();
// Call now with the correct amount of arguments. // Call now with the correct amount of arguments.
// XXX: Calling onChatRoomMessageSubmitted directly, trying // XXX: Calling onMessageSubmitted directly, trying
// again via triggering Event doesn't work for some weird // again via triggering Event doesn't work for some weird
// reason. // reason.
view.onChatRoomMessageSubmitted('/ban jid This is the reason'); view.onMessageSubmitted('/ban jid This is the reason');
expect(view.validateRoleChangeCommand.callCount).toBe(2); expect(view.validateRoleChangeCommand.callCount).toBe(2);
expect(view.showStatusNotification.callCount).toBe(1); expect(view.showStatusNotification.callCount).toBe(1);
expect(view.setAffiliation).toHaveBeenCalled(); expect(view.setAffiliation).toHaveBeenCalled();

View File

@ -523,17 +523,11 @@
message = $textarea.val(); message = $textarea.val();
$textarea.val('').focus(); $textarea.val('').focus();
if (message !== '') { if (message !== '') {
// XXX: leaky abstraction from MUC this.onMessageSubmitted(message);
if (this.model.get('type') === 'chatroom') {
this.onChatRoomMessageSubmitted(message);
} else {
this.onMessageSubmitted(message);
}
converse.emit('messageSend', message); converse.emit('messageSend', message);
} }
this.setChatState(converse.ACTIVE); this.setChatState(converse.ACTIVE);
// XXX: leaky abstraction from MUC } else {
} else if (this.model.get('type') !== 'chatroom') { // chat state data is currently only for single user chat
// Set chat state to composing if keyCode is not a forward-slash // Set chat state to composing if keyCode is not a forward-slash
// (which would imply an internal command and not a message). // (which would imply an internal command and not a message).
this.setChatState(converse.COMPOSING, ev.keyCode === KEY.FORWARD_SLASH); this.setChatState(converse.COMPOSING, ev.keyCode === KEY.FORWARD_SLASH);

View File

@ -321,6 +321,18 @@
this.showStatusNotification(__("Error: could not execute the command"), true); this.showStatusNotification(__("Error: could not execute the command"), true);
}, },
handleChatStateMessage: function (message) {
/* Override the method on the ChatBoxView base class to
* ignore <gone/> notifications in groupchats.
*
* As laid out in the business rules in XEP-0085
* http://xmpp.org/extensions/xep-0085.html#bizrules-groupchat
*/
if (message.get('chat_state') !== converse.GONE) {
converse.ChatBoxView.prototype.handleChatStateMessage.apply(this, arguments);
}
},
sendChatRoomMessage: function (text) { sendChatRoomMessage: function (text) {
var msgid = converse.connection.getUniqueId(); var msgid = converse.connection.getUniqueId();
var msg = $msg({ var msg = $msg({
@ -391,7 +403,7 @@
return this; return this;
}, },
onChatRoomMessageSubmitted: function (text) { onMessageSubmitted: function (text) {
/* Gets called when the user presses enter to send off a /* Gets called when the user presses enter to send off a
* message in a chat room. * message in a chat room.
* *