Save the MUC domain to session storage.

Fixes #237
Fixes #238
This commit is contained in:
JC Brand 2014-11-15 13:15:02 +01:00
parent 6cdd793758
commit fdb80e3d2c
2 changed files with 56 additions and 33 deletions

View File

@ -1704,11 +1704,19 @@
'submit form.add-chatroom': 'createChatRoom', 'submit form.add-chatroom': 'createChatRoom',
'click input#show-rooms': 'showRooms', 'click input#show-rooms': 'showRooms',
'click a.open-room': 'createChatRoom', 'click a.open-room': 'createChatRoom',
'click a.room-info': 'showRoomInfo' 'click a.room-info': 'showRoomInfo',
'change input[name=server]': 'setDomain',
'change input[name=nick]': 'setNick'
}, },
initialize: function (cfg) { initialize: function (cfg) {
cfg.$parent.append( this.$parent = cfg.$parent;
this.model.on('change:muc_domain', this.onDomainChange, this);
this.model.on('change:nick', this.onNickChange, this);
},
render: function () {
this.$parent.append(
this.$el.html( this.$el.html(
converse.templates.room_panel({ converse.templates.room_panel({
'server_input_type': converse.hide_muc_server && 'hidden' || 'text', 'server_input_type': converse.hide_muc_server && 'hidden' || 'text',
@ -1719,37 +1727,34 @@
'label_show_rooms': __('Show rooms') 'label_show_rooms': __('Show rooms')
}) })
).hide()); ).hide());
this.$tabs = cfg.$parent.parent().find('#controlbox-tabs'); this.$tabs = this.$parent.parent().find('#controlbox-tabs');
this.on('update-rooms-list', function (ev) {
this.updateRoomsList();
});
converse.xmppstatus.on("change", $.proxy(function (model) {
if (!(_.has(model.changed, 'fullname'))) {
return;
}
var $nick = this.$el.find('input.new-chatroom-nick');
if (! $nick.is(':focus')) {
$nick.val(model.get('fullname'));
}
}, this));
},
render: function () {
this.$tabs.append(converse.templates.chatrooms_tab({label_rooms: __('Rooms')})); this.$tabs.append(converse.templates.chatrooms_tab({label_rooms: __('Rooms')}));
return this; return this;
}, },
onDomainChange: function (model) {
var $server = this.$el.find('input.new-chatroom-server');
$server.val(model.get('muc_domain'));
if (converse.auto_list_rooms) {
this.updateRoomsList();
}
},
onNickChange: function (model) {
var $nick = this.$el.find('input.new-chatroom-nick');
$nick.val(model.get('nick'));
},
informNoRoomsFound: function () { informNoRoomsFound: function () {
var $available_chatrooms = this.$el.find('#available-chatrooms'); var $available_chatrooms = this.$el.find('#available-chatrooms');
// # For translators: %1$s is a variable and will be replaced with the XMPP server name // # For translators: %1$s is a variable and will be replaced with the XMPP server name
$available_chatrooms.html('<dt>'+__('No rooms on %1$s',this.muc_domain)+'</dt>'); $available_chatrooms.html('<dt>'+__('No rooms on %1$s',this.model.get('muc_domain'))+'</dt>');
$('input#show-rooms').show().siblings('span.spinner').remove(); $('input#show-rooms').show().siblings('span.spinner').remove();
}, },
updateRoomsList: function (domain) { updateRoomsList: function () {
converse.connection.muc.listRooms( converse.connection.muc.listRooms(
this.muc_domain, this.model.get('muc_domain'),
$.proxy(function (iq) { // Success $.proxy(function (iq) { // Success
var name, jid, i, fragment, var name, jid, i, fragment,
that = this, that = this,
@ -1758,7 +1763,7 @@
if (this.rooms.length) { if (this.rooms.length) {
// # For translators: %1$s is a variable and will be // # For translators: %1$s is a variable and will be
// # replaced with the XMPP server name // # replaced with the XMPP server name
$available_chatrooms.html('<dt>'+__('Rooms on %1$s',this.muc_domain)+'</dt>'); $available_chatrooms.html('<dt>'+__('Rooms on %1$s',this.model.get('muc_domain'))+'</dt>');
fragment = document.createDocumentFragment(); fragment = document.createDocumentFragment();
for (i=0; i<this.rooms.length; i++) { for (i=0; i<this.rooms.length; i++) {
name = Strophe.unescapeNode($(this.rooms[i]).attr('name')||$(this.rooms[i]).attr('jid')); name = Strophe.unescapeNode($(this.rooms[i]).attr('name')||$(this.rooms[i]).attr('jid'));
@ -1796,7 +1801,7 @@
$server.removeClass('error'); $server.removeClass('error');
$available_chatrooms.empty(); $available_chatrooms.empty();
$('input#show-rooms').hide().after('<span class="spinner"/>'); $('input#show-rooms').hide().after('<span class="spinner"/>');
this.muc_domain = server; this.model.save({muc_domain: server});
this.updateRoomsList(); this.updateRoomsList();
}, },
@ -1873,7 +1878,7 @@
jid = Strophe.escapeNode(name) + '@' + server; jid = Strophe.escapeNode(name) + '@' + server;
$name.removeClass('error'); $name.removeClass('error');
$server.removeClass('error'); $server.removeClass('error');
this.muc_domain = server; this.model.save({muc_domain: server});
} else { } else {
if (!name) { $name.addClass('error'); } if (!name) { $name.addClass('error'); }
if (!server) { $server.addClass('error'); } if (!server) { $server.addClass('error'); }
@ -1889,6 +1894,14 @@
'chatroom': true, 'chatroom': true,
'box_id' : b64_sha1(jid) 'box_id' : b64_sha1(jid)
}); });
},
setDomain: function (ev) {
this.model.save({muc_domain: ev.target.value});
},
setNick: function (ev) {
this.model.save({nick: ev.target.value});
} }
}); });
@ -1982,14 +1995,25 @@
}, },
renderContactsPanel: function () { renderContactsPanel: function () {
var model;
this.$el.html(converse.templates.controlbox(this.model.toJSON())); this.$el.html(converse.templates.controlbox(this.model.toJSON()));
this.contactspanel = new converse.ContactsPanel({'$parent': this.$el.find('.controlbox-panes')}); this.contactspanel = new converse.ContactsPanel({'$parent': this.$el.find('.controlbox-panes')});
this.contactspanel.render(); this.contactspanel.render();
converse.xmppstatusview = new converse.XMPPStatusView({'model': converse.xmppstatus}); converse.xmppstatusview = new converse.XMPPStatusView({'model': converse.xmppstatus});
converse.xmppstatusview.render(); converse.xmppstatusview.render();
if (converse.allow_muc) { if (converse.allow_muc) {
this.roomspanel = new converse.RoomsPanel({'$parent': this.$el.find('.controlbox-panes')}); this.roomspanel = new converse.RoomsPanel({
this.roomspanel.render(); '$parent': this.$el.find('.controlbox-panes'),
'model': new (Backbone.Model.extend({
id: b64_sha1('converse.roomspanel'+converse.bare_jid), // Required by sessionStorage
browserStorage: new Backbone.BrowserStorage[converse.storage](
b64_sha1('converse.roomspanel'+converse.bare_jid))
}))()
});
this.roomspanel.render().model.fetch();
if (!this.roomspanel.model.get('nick')) {
this.roomspanel.model.save({nick: Strophe.getNodeFromJid(converse.bare_jid)});
}
} }
this.initDragResize(); this.initDragResize();
}, },
@ -2041,13 +2065,10 @@
featureAdded: function (feature) { featureAdded: function (feature) {
if ((feature.get('var') == 'http://jabber.org/protocol/muc') && (converse.allow_muc)) { if ((feature.get('var') == 'http://jabber.org/protocol/muc') && (converse.allow_muc)) {
this.roomspanel.muc_domain = feature.get('from'); this.roomspanel.model.save({muc_domain: feature.get('from')});
var $server= this.$el.find('input.new-chatroom-server'); var $server= this.$el.find('input.new-chatroom-server');
if (! $server.is(':focus')) { if (! $server.is(':focus')) {
$server.val(this.roomspanel.muc_domain); $server.val(this.roomspanel.model.get('muc_domain'));
}
if (converse.auto_list_rooms) {
this.roomspanel.trigger('update-rooms-list');
} }
} }
}, },

View File

@ -14,6 +14,8 @@ Changelog
any prebind session tokens. [jcbrand] any prebind session tokens. [jcbrand]
* #46 Refactor the API and add new methods. [jcbrand] * #46 Refactor the API and add new methods. [jcbrand]
* #151 Browser locks/freezes with many roster users. [jcbrand] * #151 Browser locks/freezes with many roster users. [jcbrand]
* #237 Unable to create room when ``hide_muc_server`` is ``true``. [jcbrand]
* #238 Rooms are not shown when ``hide_offline_users`` is ``true``. [jcbrand]
* #251 Non-minified builds for debugging. [jcbrand] * #251 Non-minified builds for debugging. [jcbrand]
* #264 Remove unnecessary commas for ie8 compatibility. [Deuteu] * #264 Remove unnecessary commas for ie8 compatibility. [Deuteu]
* #267 Unread messages counter wrongly gets incremented by chat state notifications. [Deuteu] * #267 Unread messages counter wrongly gets incremented by chat state notifications. [Deuteu]