Commit df7f1ccf authored by JC Brand's avatar JC Brand

Use feature discovery on chatrooms

parent 5a3ed27f
......@@ -689,9 +689,9 @@
room_template: _.template(
'<dd class="available-chatroom">' +
'<a class="open-room" data-room-jid="{{jid}}"' +
' title="Click to open this chatroom"' +
' title="{{desc}}"' +
' href="#">' +
'{{name}}</a></dd>'),
'({{occ}}) {{name}}</a></dd>'),
tab_template: _.template('<li><a class="s" href="#chatrooms">Rooms</a></li>'),
......@@ -720,19 +720,34 @@
converse.connection.muc.listRooms(
this.muc_domain,
$.proxy(function (iq) { // Success
var name, jid, i,
rooms = $(iq).find('query').find('item'),
rooms_length = rooms.length,
$available_chatrooms = this.$el.find('#available-chatrooms'),
fragment = document.createDocumentFragment();
if (rooms.length) {
var name, jid, i, that = this, $available_chatrooms = this.$el.find('#available-chatrooms');
this.rdict = {};
this.rooms = $(iq).find('query').find('item');
this.rooms.each(function (i) { that.rdict[$(this).attr('jid')] = this; });
this.fragment = document.createDocumentFragment();
if (this.rooms.length) {
$available_chatrooms.html('<dt>Rooms on '+this.muc_domain+'</dt>');
for (i=0; i<rooms_length; i++) {
name = Strophe.unescapeNode($(rooms[i]).attr('name')||$(rooms[i]).attr('jid'));
jid = $(rooms[i]).attr('jid');
fragment.appendChild($(this.room_template({'name':name, 'jid':jid}))[0]);
_.each(this.rooms, $.proxy(function (room, idx) {
converse.connection.disco.info(
$(room).attr('jid'),
null,
$.proxy(function (stanza) {
var name = $(stanza).find('identity').attr('name');
var desc = $(stanza).find('field[var="muc#roominfo_description"] value').text();
var occ = $(stanza).find('field[var="muc#roominfo_occupants"] value').text();
var jid = $(stanza).attr('from');
delete this.rdict[jid];
this.$el.find('#available-chatrooms').append(
this.room_template({'name':name,
'desc':desc,
'occ':occ,
'jid':jid
}));
if (_.keys(this.rdict).length === 0) {
$('input#show-rooms').show().siblings('img.spinner').remove();
}
$available_chatrooms.append(fragment);
}, this));
}, this));
} else {
$available_chatrooms.html('<dt>No rooms on '+this.muc_domain+'</dt>');
}
......@@ -755,7 +770,7 @@
this.$el.find('input.new-chatroom-name').removeClass('error');
$server.removeClass('error');
$available_chatrooms.empty();
$('#available-chatrooms').html('<img style="width: auto; margin-left: 40%; margin-top: 10%" src="images/spinner.gif"/>');
$('input#show-rooms').hide().after('<img class="spinner" style="width: auto" src="images/spinner.gif"/>');
this.muc_domain = server;
this.updateRoomsList();
},
......@@ -838,8 +853,10 @@
if (! $server.is(':focus')) {
$server.val(this.roomspanel.muc_domain);
}
if (converse.auto_list_rooms) {
this.roomspanel.trigger('update-rooms-list');
}
}
},
template: _.template(
......@@ -2010,7 +2027,7 @@
if (errors) { return; }
var $button = $form.find('input[type=submit]');
$button.hide().after('<img style="width: auto" src="images/spinner.gif"/>');
$button.hide().after('<img class="spinner" src="images/spinner.gif"/>');
var connection = new Strophe.Connection(this.bosh_service_url);
connection.connect(jid, password, $.proxy(function (status) {
......
......@@ -72,6 +72,18 @@ auto_subscribe
If true, the user will automatically subscribe back to any contact requests.
auto_list_rooms
===============
If true, and the XMPP server on which the current user is logged in supports
multi-user chat, then a list of rooms on that server will be fetched.
Not recommended for servers with lots of chat rooms.
For each room on the server a query is made to fetch further details (e.g.
features, number of occupants etc.), so on servers with many rooms this
option will create lots of extra connection traffic.
animate
=======
......
......@@ -4,6 +4,7 @@ require(["jquery", "converse"], function($, converse) {
bosh_service_url: 'https://bind.opkode.im', // Please use this connection manager only for testing purposes
prebind: false,
xhr_user_search: false,
auto_subscribe: false
auto_subscribe: false,
auto_list_rooms: false
});
});
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