Commit 910e9bdd authored by JC Brand's avatar JC Brand

Refactoring in MUC

What started as an attempt to fix a bug in parseXUserElement, turned into
another large refactoring of MUC code, and it's not clear how to break this up
into multiple atomic commits. So I'm just pushing it all.

At least there are two new tests added to the suite.
parent 8bbd88ba
......@@ -135,7 +135,9 @@ require.config({
"chatbox_minimize": "src/templates/chatbox_minimize",
"chatroom": "src/templates/chatroom",
"chatroom_bookmark_form": "src/templates/chatroom_bookmark_form",
"chatroom_bookmark_toggle": "src/templates/chatroom_bookmark_toggle",
"chatroom_form": "src/templates/chatroom_form",
"chatroom_head": "src/templates/chatroom_head",
"chatroom_nickname_form": "src/templates/chatroom_nickname_form",
"chatroom_password_form": "src/templates/chatroom_password_form",
"chatroom_sidebar": "src/templates/chatroom_sidebar",
......@@ -147,6 +149,7 @@ require.config({
"contacts_tab": "src/templates/contacts_tab",
"controlbox": "src/templates/controlbox",
"controlbox_toggle": "src/templates/controlbox_toggle",
"dragresize": "src/templates/dragresize",
"field": "src/templates/field",
"form_captcha": "src/templates/form_captcha",
"form_checkbox": "src/templates/form_checkbox",
......
......@@ -155,6 +155,36 @@
expect(view instanceof converse.ChatRoomView).toBe(true);
}));
it("can be configured if you're its owner", mock.initConverse(function (converse) {
converse_api.rooms.open('room@conference.example.org', {'nick': 'some1'});
var view = converse.chatboxviews.get('room@conference.example.org');
spyOn(view, 'showConfigureButtonIfRoomOwner').andCallThrough();
/* <presence to="dummy@localhost/converse.js-29092160"
* from="room@conference.example.org/some1">
* <x xmlns="http://jabber.org/protocol/muc#user">
* <item affiliation="owner" jid="dummy@localhost/converse.js-29092160" role="moderator"/>
* <status code="110"/>
* </x>
* </presence></body>
*/
var presence = $pres({
to: 'dummy@localhost/converse.js-29092160',
from: 'room@conference.example.org/some1'
}).c('x', {xmlns: Strophe.NS.MUC_USER})
.c('item', {
'affiliation': 'owner',
'jid': 'dummy@localhost/converse.js-29092160',
'role': 'moderator'
}).up()
.c('status', {code: '110'});
converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.showConfigureButtonIfRoomOwner).toHaveBeenCalled();
expect(view.$('.configure-chatroom-button').is(':visible')).toBeTruthy();
expect(view.$('.toggle-chatbox-button').is(':visible')).toBeTruthy();
expect(view.$('.toggle-bookmark').is(':visible')).toBeTruthy();
}));
it("shows users currently present in the room", mock.initConverse(function (converse) {
test_utils.openAndEnterChatRoom(converse, 'lounge', 'localhost', 'dummy');
var name;
......@@ -575,6 +605,43 @@
expect($occupants.children().first(0).text()).toBe("newnick");
}));
it("indicates when a room is no longer anonymous", mock.initConverse(function (converse) {
converse_api.rooms.open('room@conference.example.org', {
'nick': 'some1',
'roomconfig': {
'changesubject': false,
'membersonly': true,
'persistentroom': true,
'publicroom': true,
'roomdesc': 'Welcome to this room',
'whois': 'anyone'
}
});
/* <message xmlns="jabber:client"
* type="groupchat"
* to="dummy@localhost/converse.js-27854181"
* from="room@conference.example.org">
* <x xmlns="http://jabber.org/protocol/muc#user">
* <status code="104"/>
* <status code="172"/>
* </x>
* </message>
*/
var message = $msg({
type:'groupchat',
to: 'dummy@localhost/converse.js-27854181',
from: 'room@conference.example.org'
}).c('x', {xmlns: Strophe.NS.MUC_USER})
.c('status', {code: '104'}).up()
.c('status', {code: '172'});
converse.connection._dataRecv(test_utils.createRequest(message));
var view = converse.chatboxviews.get('room@conference.example.org');
var $chat_body = view.$('.chatroom-body');
expect($chat_body.html().trim().indexOf(
'<div class="chat-info">This room is now no longer anonymous</div>'
)).not.toBe(-1);
}));
it("informs users if they have been kicked out of the chat room", mock.initConverse(function (converse) {
/* <presence
* from='harfleur@chat.shakespeare.lit/pistol'
......
......@@ -20,6 +20,7 @@
"converse-api",
"converse-muc",
"tpl!chatroom_bookmark_form",
"tpl!chatroom_bookmark_toggle",
"tpl!bookmark",
"tpl!bookmarks_list"
],
......@@ -28,6 +29,7 @@
$, _, moment, strophe, utils,
converse, converse_api, muc,
tpl_chatroom_bookmark_form,
tpl_chatroom_bookmark_toggle,
tpl_bookmark,
tpl_bookmarks_list
) {
......@@ -40,6 +42,7 @@
// Add new HTML templates.
converse.templates.chatroom_bookmark_form = tpl_chatroom_bookmark_form;
converse.templates.chatroom_bookmark_toggle = tpl_chatroom_bookmark_toggle;
converse.templates.bookmark = tpl_bookmark;
converse.templates.bookmarks_list = tpl_bookmarks_list;
......@@ -69,16 +72,24 @@
this.setBookmarkState();
},
render: function (options) {
this.__super__.render.apply(this, arguments);
generateHeadingHTML: function () {
var html = this.__super__.generateHeadingHTML.apply(this, arguments);
if (converse.allow_bookmarks) {
var label_bookmark = _('Bookmark this room');
var button = '<a class="chatbox-btn toggle-bookmark icon-pushpin '+
(this.model.get('bookmarked') ? 'button-on"' : '"') +
'title="'+label_bookmark+'"></a>';
this.$el.find('.chat-head-chatroom .icon-wrench').before(button);
var div = document.createElement('div');
div.innerHTML = html;
var bookmark_button = converse.templates.chatroom_bookmark_toggle(
_.extend(
this.model.toJSON(),
{
info_toggle_bookmark: __('Bookmark this room'),
bookmarked: this.model.get('bookmarked')
}
return this;
));
var close_button = div.querySelector('.close-chatbox-button');
close_button.insertAdjacentHTML('afterend', bookmark_button);
return div.innerHTML;
}
return html;
},
checkForReservedNick: function () {
......
......@@ -10,14 +10,16 @@
define("converse-dragresize", [
"converse-core",
"converse-api",
"tpl!dragresize",
"converse-chatview",
"converse-muc", // XXX: would like to remove this
"converse-controlbox"
], factory);
}(this, function (converse, converse_api) {
}(this, function (converse, converse_api, tpl_dragresize) {
"use strict";
var $ = converse_api.env.jQuery,
_ = converse_api.env._;
converse.templates.dragresize = tpl_dragresize;
converse_api.plugins.add('converse-dragresize', {
......@@ -260,13 +262,23 @@
render: function () {
var result = this.__super__.render.apply(this, arguments);
this.renderDragResizeHandles();
this.setWidth();
return result;
},
renderDragResizeHandles: function () {
var flyout = this.el.querySelector('.box-flyout');
var div = document.createElement('div');
div.innerHTML = converse.templates.dragresize();
flyout.insertBefore(
div.firstChild,
flyout.firstChild
);
}
}
},
initialize: function () {
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
......
......@@ -98,7 +98,6 @@
title: this.model.get('fullname'),
unread_msgs: __('You have unread messages'),
info_close: __('Close this box'),
info_minimize: __('Minimize this box'),
label_personal_message: ''
}
)
......
......@@ -181,6 +181,18 @@
this.hide();
}
return result;
},
generateHeadingHTML: function () {
var html = this.__super__.generateHeadingHTML.apply(this, arguments);
var div = document.createElement('div');
div.innerHTML = html;
var el = converse.templates.chatbox_minimize(
{info_minimize: __('Minimize this chat box')}
);
var button = div.querySelector('.close-chatbox-button');
button.insertAdjacentHTML('afterend', el);
return div.innerHTML;
}
},
......@@ -497,7 +509,7 @@
// Inserts a "minimize" button in the chatview's header
var $el = view.$el.find('.toggle-chatbox-button');
var $new_el = converse.templates.chatbox_minimize(
_.extend({info_minimize: __('Minimize this chat box')})
{info_minimize: __('Minimize this chat box')}
);
if ($el.length) {
$el.replaceWith($new_el);
......@@ -506,7 +518,6 @@
}
};
converse.on('chatBoxOpened', renderMinimizeButton);
converse.on('chatRoomOpened', renderMinimizeButton);
converse.on('controlBoxOpened', function (evt, chatbox) {
// Wrapped in anon method because at scan time, chatboxviews
......
This diff is collapsed.
<div class="flyout box-flyout">
<div class="dragresize dragresize-top"></div>
<div class="dragresize dragresize-topleft"></div>
<div class="dragresize dragresize-left"></div>
<div class="chat-head chat-head-chatroom">
<a class="chatbox-btn close-chatbox-button icon-close" title="{{info_close}}"></a>
<a class="chatbox-btn configure-chatroom-button icon-wrench" title="{{info_configure}} "style="display:none"></a>
<div class="chat-title">
{{ _.escape(name) }}
<p class="chatroom-topic"><p/>
</div>
</div>
<div class="chat-head chat-head-chatroom"></div>
<div class="chat-body chatroom-body"><span class="spinner centered"/></div>
</div>
<a class="chatbox-btn toggle-bookmark icon-pushpin
{[ if (bookmarked) {]}
button-on
{[ } ]}" title="{{info_toggle_bookmark}}"></a>
<div class="dragresize dragresize-top"></div>
<div class="dragresize dragresize-topleft"></div>
<div class="dragresize dragresize-left"></div>
<a class="chatbox-btn close-chatbox-button icon-close" title="{{info_close}}"></a>
{[ if (affiliation == 'owner') { ]}
<a class="chatbox-btn configure-chatroom-button icon-wrench" title="{{info_configure}} "></a>
{[ } ]}
<div class="chat-title">
{{ _.escape(name) }}
<p class="chatroom-topic"><p/>
</div>
<div class="dragresize dragresize-top"></div>
<div class="dragresize dragresize-topleft"></div>
<div class="dragresize dragresize-left"></div>
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