Commit 59a72efe authored by JC Brand's avatar JC Brand

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`
parent 8a862e27
......@@ -2052,7 +2052,7 @@
var sent_stanza;
var view = _converse.chatboxviews.get('lounge@localhost');
spyOn(view, 'onMessageSubmitted').and.callThrough();
spyOn(view, 'clearChatRoomMessages');
spyOn(view, 'clearMessages');
spyOn(_converse.connection, 'send').and.callFake(function (stanza) {
sent_stanza = stanza;
});
......@@ -2106,7 +2106,7 @@
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
var view = _converse.chatboxviews.get('lounge@localhost');
spyOn(view, 'onMessageSubmitted').and.callThrough();
spyOn(view, 'clearChatRoomMessages');
spyOn(view, 'clearMessages');
var textarea = view.el.querySelector('.chat-textarea')
textarea.value = '/clear';
view.keyPressed({
......@@ -2116,7 +2116,7 @@
});
expect(view.onMessageSubmitted).toHaveBeenCalled();
expect(view.clearChatRoomMessages).toHaveBeenCalled();
expect(view.clearMessages).toHaveBeenCalled();
done();
}).catch(_.partial(console.error, _));
}));
......
......@@ -155,11 +155,13 @@
}
}
};
xhr.upload.addEventListener("progress", (evt) => {
if (evt.lengthComputable) {
this.set('progress', evt.loaded / evt.total);
}
}, false);
xhr.onerror = () => {
let message = __('Sorry, could not succesfully upload your file.');
if (xhr.responseText) {
......
......@@ -829,7 +829,7 @@
clearMessages (ev) {
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) {
this.content.innerHTML = '';
this.model.messages.reset();
......
// Converse.js (A browser based XMPP chat client)
// Converse.js
// 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)
//
/* 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) {
define([
"converse-core",
"muc-utils",
"emojione",
"tpl!add_chatroom_modal",
"tpl!chatarea",
"tpl!chatroom",
......@@ -39,7 +34,6 @@
}(this, function (
converse,
muc_utils,
emojione,
tpl_add_chatroom_modal,
tpl_chatarea,
tpl_chatroom,
......@@ -504,7 +498,6 @@
'click .occupant': 'onOccupantClicked',
'click .send-button': 'onFormSubmitted',
'click .toggle-call': 'toggleCall',
'click .toggle-clear': 'clearChatRoomMessages',
'click .toggle-occupants': 'toggleOccupants',
'click .toggle-smiley ul.emoji-picker li': 'insertEmoji',
'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) {
const item = $build("item", {nick, role});
const iq = $iq({to: room, type: "set"}).c("query", {xmlns: Strophe.NS.MUC_ADMIN}).cnode(item.node);
......@@ -787,30 +754,17 @@
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 () {
this.showErrorMessage(__("Error: could not execute the command"), true);
},
onMessageSubmitted (text, spoiler_hint) {
/* Gets called when the user presses enter to send off a
* message in a chat room.
*
* Parameters:
* (String) text - The message text.
*/
parseMessageForCommands (text) {
const _super_ = _converse.ChatBoxView.prototype;
if (_super_.parseMessageForCommands.apply(this, arguments)) {
return true;
}
if (_converse.muc_disable_moderator_commands) {
return this.sendChatRoomMessage(text);
return false;
}
const match = text.replace(/^\s*/, "").match(/^\/(.*?)(?: (.*))?$/) || [false, '', ''],
args = match[2] && match[2].splitOnce(' ') || [],
......@@ -830,9 +784,6 @@
'reason': args[1]
}]).then(null, this.onCommandError.bind(this));
break;
case 'clear':
this.clearChatRoomMessages();
break;
case 'deop':
if (!this.validateRoleChangeCommand(command, args)) { break; }
this.modifyRole(
......@@ -922,9 +873,9 @@
undefined, this.onCommandError.bind(this));
break;
default:
this.sendChatRoomMessage(text);
break;
return false;
}
return true;
},
registerHandlers () {
......
// Converse.js (A browser based XMPP chat client)
// Converse.js
// 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)
//
/*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) {
define([
"form-utils",
"converse-core",
"emojione",
"converse-chatview",
"converse-disco",
"backbone.overview",
......@@ -20,7 +16,7 @@
"backbone.vdomview",
"muc-utils"
], factory);
}(this, function (u, converse) {
}(this, function (u, converse, emojione) {
"use strict";
const MUC_ROLE_WEIGHTS = {
......@@ -40,7 +36,6 @@
Strophe.addNamespace('MUC_USER', Strophe.NS.MUC + "#user");
converse.MUC_NICK_CHANGED_CODE = "303";
converse.CHATROOMS_TYPE = 'chatroom';
converse.ROOM_FEATURES = [
......@@ -306,6 +301,22 @@
_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 () {
/* Fetch the room disco info, parse it and then save it.
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment