Refactor MUC message sending
To make it more similar to how messages are sent in private chats and to reuse methods as far as possible. Removed `sendChatRoomMessage` and `clearChatRoomMessages`
This commit is contained in:
parent
8a862e27c5
commit
59a72efe1b
@ -2052,7 +2052,7 @@
|
|||||||
var sent_stanza;
|
var sent_stanza;
|
||||||
var view = _converse.chatboxviews.get('lounge@localhost');
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
||||||
spyOn(view, 'onMessageSubmitted').and.callThrough();
|
spyOn(view, 'onMessageSubmitted').and.callThrough();
|
||||||
spyOn(view, 'clearChatRoomMessages');
|
spyOn(view, 'clearMessages');
|
||||||
spyOn(_converse.connection, 'send').and.callFake(function (stanza) {
|
spyOn(_converse.connection, 'send').and.callFake(function (stanza) {
|
||||||
sent_stanza = stanza;
|
sent_stanza = stanza;
|
||||||
});
|
});
|
||||||
@ -2106,7 +2106,7 @@
|
|||||||
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
|
||||||
var view = _converse.chatboxviews.get('lounge@localhost');
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
||||||
spyOn(view, 'onMessageSubmitted').and.callThrough();
|
spyOn(view, 'onMessageSubmitted').and.callThrough();
|
||||||
spyOn(view, 'clearChatRoomMessages');
|
spyOn(view, 'clearMessages');
|
||||||
var textarea = view.el.querySelector('.chat-textarea')
|
var textarea = view.el.querySelector('.chat-textarea')
|
||||||
textarea.value = '/clear';
|
textarea.value = '/clear';
|
||||||
view.keyPressed({
|
view.keyPressed({
|
||||||
@ -2116,7 +2116,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(view.onMessageSubmitted).toHaveBeenCalled();
|
expect(view.onMessageSubmitted).toHaveBeenCalled();
|
||||||
expect(view.clearChatRoomMessages).toHaveBeenCalled();
|
expect(view.clearMessages).toHaveBeenCalled();
|
||||||
done();
|
done();
|
||||||
}).catch(_.partial(console.error, _));
|
}).catch(_.partial(console.error, _));
|
||||||
}));
|
}));
|
||||||
|
@ -155,11 +155,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
xhr.upload.addEventListener("progress", (evt) => {
|
xhr.upload.addEventListener("progress", (evt) => {
|
||||||
if (evt.lengthComputable) {
|
if (evt.lengthComputable) {
|
||||||
this.set('progress', evt.loaded / evt.total);
|
this.set('progress', evt.loaded / evt.total);
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
xhr.onerror = () => {
|
xhr.onerror = () => {
|
||||||
let message = __('Sorry, could not succesfully upload your file.');
|
let message = __('Sorry, could not succesfully upload your file.');
|
||||||
if (xhr.responseText) {
|
if (xhr.responseText) {
|
||||||
|
@ -829,7 +829,7 @@
|
|||||||
|
|
||||||
clearMessages (ev) {
|
clearMessages (ev) {
|
||||||
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
||||||
const result = confirm(__("Are you sure you want to clear the messages from this chat box?"));
|
const result = confirm(__("Are you sure you want to clear the messages from this conversation?"));
|
||||||
if (result === true) {
|
if (result === true) {
|
||||||
this.content.innerHTML = '';
|
this.content.innerHTML = '';
|
||||||
this.model.messages.reset();
|
this.model.messages.reset();
|
||||||
|
@ -1,18 +1,13 @@
|
|||||||
// Converse.js (A browser based XMPP chat client)
|
// Converse.js
|
||||||
// http://conversejs.org
|
// http://conversejs.org
|
||||||
//
|
//
|
||||||
// Copyright (c) 2012-2018, Jan-Carel Brand <jc@opkode.com>
|
// Copyright (c) 2012-2018, the Converse.js developers
|
||||||
// Licensed under the Mozilla Public License (MPLv2)
|
// Licensed under the Mozilla Public License (MPLv2)
|
||||||
//
|
|
||||||
|
|
||||||
/* This is a Converse.js plugin which add support for multi-user chat rooms, as
|
|
||||||
* specified in XEP-0045 Multi-user chat.
|
|
||||||
*/
|
|
||||||
(function (root, factory) {
|
(function (root, factory) {
|
||||||
define([
|
define([
|
||||||
"converse-core",
|
"converse-core",
|
||||||
"muc-utils",
|
"muc-utils",
|
||||||
"emojione",
|
|
||||||
"tpl!add_chatroom_modal",
|
"tpl!add_chatroom_modal",
|
||||||
"tpl!chatarea",
|
"tpl!chatarea",
|
||||||
"tpl!chatroom",
|
"tpl!chatroom",
|
||||||
@ -39,7 +34,6 @@
|
|||||||
}(this, function (
|
}(this, function (
|
||||||
converse,
|
converse,
|
||||||
muc_utils,
|
muc_utils,
|
||||||
emojione,
|
|
||||||
tpl_add_chatroom_modal,
|
tpl_add_chatroom_modal,
|
||||||
tpl_chatarea,
|
tpl_chatarea,
|
||||||
tpl_chatroom,
|
tpl_chatroom,
|
||||||
@ -504,7 +498,6 @@
|
|||||||
'click .occupant': 'onOccupantClicked',
|
'click .occupant': 'onOccupantClicked',
|
||||||
'click .send-button': 'onFormSubmitted',
|
'click .send-button': 'onFormSubmitted',
|
||||||
'click .toggle-call': 'toggleCall',
|
'click .toggle-call': 'toggleCall',
|
||||||
'click .toggle-clear': 'clearChatRoomMessages',
|
|
||||||
'click .toggle-occupants': 'toggleOccupants',
|
'click .toggle-occupants': 'toggleOccupants',
|
||||||
'click .toggle-smiley ul.emoji-picker li': 'insertEmoji',
|
'click .toggle-smiley ul.emoji-picker li': 'insertEmoji',
|
||||||
'click .toggle-smiley': 'toggleEmojiMenu',
|
'click .toggle-smiley': 'toggleEmojiMenu',
|
||||||
@ -738,32 +731,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
sendChatRoomMessage (text) {
|
|
||||||
/* Constuct a message stanza to be sent to this chat room,
|
|
||||||
* and send it to the server.
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* (String) text: The message text to be sent.
|
|
||||||
*/
|
|
||||||
text = u.httpToGeoUri(emojione.shortnameToUnicode(text), _converse)
|
|
||||||
const msgid = _converse.connection.getUniqueId();
|
|
||||||
const msg = $msg({
|
|
||||||
to: this.model.get('jid'),
|
|
||||||
from: _converse.connection.jid,
|
|
||||||
type: 'groupchat',
|
|
||||||
id: msgid
|
|
||||||
}).c("body").t(text).up()
|
|
||||||
.c("x", {xmlns: "jabber:x:event"}).c(_converse.COMPOSING);
|
|
||||||
_converse.connection.send(msg);
|
|
||||||
this.model.messages.create({
|
|
||||||
'fullname': this.model.get('nick'),
|
|
||||||
'sender': 'me',
|
|
||||||
'time': moment().format(),
|
|
||||||
'message': text,
|
|
||||||
msgid
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
modifyRole(room, nick, role, reason, onSuccess, onError) {
|
modifyRole(room, nick, role, reason, onSuccess, onError) {
|
||||||
const item = $build("item", {nick, role});
|
const item = $build("item", {nick, role});
|
||||||
const iq = $iq({to: room, type: "set"}).c("query", {xmlns: Strophe.NS.MUC_ADMIN}).cnode(item.node);
|
const iq = $iq({to: room, type: "set"}).c("query", {xmlns: Strophe.NS.MUC_ADMIN}).cnode(item.node);
|
||||||
@ -787,30 +754,17 @@
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
clearChatRoomMessages (ev) {
|
|
||||||
/* Remove all messages from the chat room UI.
|
|
||||||
*/
|
|
||||||
if (!_.isUndefined(ev)) { ev.stopPropagation(); }
|
|
||||||
const result = confirm(__("Are you sure you want to clear the messages from this room?"));
|
|
||||||
if (result === true) {
|
|
||||||
this.content.innerHTML = '';
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
|
|
||||||
onCommandError () {
|
onCommandError () {
|
||||||
this.showErrorMessage(__("Error: could not execute the command"), true);
|
this.showErrorMessage(__("Error: could not execute the command"), true);
|
||||||
},
|
},
|
||||||
|
|
||||||
onMessageSubmitted (text, spoiler_hint) {
|
parseMessageForCommands (text) {
|
||||||
/* Gets called when the user presses enter to send off a
|
const _super_ = _converse.ChatBoxView.prototype;
|
||||||
* message in a chat room.
|
if (_super_.parseMessageForCommands.apply(this, arguments)) {
|
||||||
*
|
return true;
|
||||||
* Parameters:
|
}
|
||||||
* (String) text - The message text.
|
|
||||||
*/
|
|
||||||
if (_converse.muc_disable_moderator_commands) {
|
if (_converse.muc_disable_moderator_commands) {
|
||||||
return this.sendChatRoomMessage(text);
|
return false;
|
||||||
}
|
}
|
||||||
const match = text.replace(/^\s*/, "").match(/^\/(.*?)(?: (.*))?$/) || [false, '', ''],
|
const match = text.replace(/^\s*/, "").match(/^\/(.*?)(?: (.*))?$/) || [false, '', ''],
|
||||||
args = match[2] && match[2].splitOnce(' ') || [],
|
args = match[2] && match[2].splitOnce(' ') || [],
|
||||||
@ -830,9 +784,6 @@
|
|||||||
'reason': args[1]
|
'reason': args[1]
|
||||||
}]).then(null, this.onCommandError.bind(this));
|
}]).then(null, this.onCommandError.bind(this));
|
||||||
break;
|
break;
|
||||||
case 'clear':
|
|
||||||
this.clearChatRoomMessages();
|
|
||||||
break;
|
|
||||||
case 'deop':
|
case 'deop':
|
||||||
if (!this.validateRoleChangeCommand(command, args)) { break; }
|
if (!this.validateRoleChangeCommand(command, args)) { break; }
|
||||||
this.modifyRole(
|
this.modifyRole(
|
||||||
@ -922,9 +873,9 @@
|
|||||||
undefined, this.onCommandError.bind(this));
|
undefined, this.onCommandError.bind(this));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.sendChatRoomMessage(text);
|
return false;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
registerHandlers () {
|
registerHandlers () {
|
||||||
|
@ -1,18 +1,14 @@
|
|||||||
// Converse.js (A browser based XMPP chat client)
|
// Converse.js
|
||||||
// http://conversejs.org
|
// http://conversejs.org
|
||||||
//
|
//
|
||||||
// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com>
|
// Copyright (c) 2012-2018, the Converse.js developers
|
||||||
// Licensed under the Mozilla Public License (MPLv2)
|
// Licensed under the Mozilla Public License (MPLv2)
|
||||||
//
|
|
||||||
/*global define */
|
|
||||||
|
|
||||||
/* This is a Converse.js plugin which add support for multi-user chat rooms, as
|
|
||||||
* specified in XEP-0045 Multi-user chat.
|
|
||||||
*/
|
|
||||||
(function (root, factory) {
|
(function (root, factory) {
|
||||||
define([
|
define([
|
||||||
"form-utils",
|
"form-utils",
|
||||||
"converse-core",
|
"converse-core",
|
||||||
|
"emojione",
|
||||||
"converse-chatview",
|
"converse-chatview",
|
||||||
"converse-disco",
|
"converse-disco",
|
||||||
"backbone.overview",
|
"backbone.overview",
|
||||||
@ -20,7 +16,7 @@
|
|||||||
"backbone.vdomview",
|
"backbone.vdomview",
|
||||||
"muc-utils"
|
"muc-utils"
|
||||||
], factory);
|
], factory);
|
||||||
}(this, function (u, converse) {
|
}(this, function (u, converse, emojione) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const MUC_ROLE_WEIGHTS = {
|
const MUC_ROLE_WEIGHTS = {
|
||||||
@ -40,7 +36,6 @@
|
|||||||
Strophe.addNamespace('MUC_USER', Strophe.NS.MUC + "#user");
|
Strophe.addNamespace('MUC_USER', Strophe.NS.MUC + "#user");
|
||||||
|
|
||||||
converse.MUC_NICK_CHANGED_CODE = "303";
|
converse.MUC_NICK_CHANGED_CODE = "303";
|
||||||
|
|
||||||
converse.CHATROOMS_TYPE = 'chatroom';
|
converse.CHATROOMS_TYPE = 'chatroom';
|
||||||
|
|
||||||
converse.ROOM_FEATURES = [
|
converse.ROOM_FEATURES = [
|
||||||
@ -306,6 +301,22 @@
|
|||||||
_converse.connection.sendPresence(presence);
|
_converse.connection.sendPresence(presence);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getOutgoingMessageAttributes (text, spoiler_hint) {
|
||||||
|
const is_spoiler = this.get('composing_spoiler');
|
||||||
|
return {
|
||||||
|
'from': _converse.connection.jid,
|
||||||
|
'fullname': this.get('nick'),
|
||||||
|
'is_spoiler': is_spoiler,
|
||||||
|
'message': text ? u.httpToGeoUri(emojione.shortnameToUnicode(text), _converse) : undefined,
|
||||||
|
'msgid': _converse.connection.getUniqueId(),
|
||||||
|
'sender': 'me',
|
||||||
|
'spoiler_hint': is_spoiler ? spoiler_hint : undefined,
|
||||||
|
'time': moment().format(),
|
||||||
|
'to': this.get('jid'),
|
||||||
|
'type': 'groupchat',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
getRoomFeatures () {
|
getRoomFeatures () {
|
||||||
/* Fetch the room disco info, parse it and then save it.
|
/* Fetch the room disco info, parse it and then save it.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user