From 96742a6684213f8480882d0358d0f1bdbba622e5 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Fri, 5 Jan 2018 12:33:28 +0000 Subject: [PATCH] Also make the open rooms list an OrderedListView --- dev.html | 1 + spec/bookmarks.js | 1 + spec/chatroom.js | 2 +- src/converse-bookmarks.js | 25 +++++--- src/converse-muc.js | 13 ++-- src/converse-roomslist.js | 121 +++++++++++++++++++++++++++++++++----- 6 files changed, 132 insertions(+), 31 deletions(-) diff --git a/dev.html b/dev.html index 90522d981..a3611ee93 100644 --- a/dev.html +++ b/dev.html @@ -60,6 +60,7 @@ // 'prosody@conference.prosody.im', // 'jdev@conference.jabber.org' // ], + hide_open_bookmarks: true, notify_all_room_messages: [ 'discuss@conference.conversejs.org' ], diff --git a/spec/bookmarks.js b/spec/bookmarks.js index 9fbbce87f..69f550a9e 100644 --- a/spec/bookmarks.js +++ b/spec/bookmarks.js @@ -477,6 +477,7 @@ return true; } }).length).toBe(1); + var stanza = $iq({'to': _converse.connection.jid, 'type':'result', 'id':IQ_id}) .c('pubsub', {'xmlns': Strophe.NS.PUBSUB}) .c('items', {'node': 'storage:bookmarks'}) diff --git a/spec/chatroom.js b/spec/chatroom.js index 983ff3775..4d6ce6d55 100644 --- a/spec/chatroom.js +++ b/spec/chatroom.js @@ -3146,7 +3146,7 @@ panel.onRoomsFound(iq); expect($(panel.el.querySelector('#available-chatrooms')).children('dt').length).toBe(1); - expect($(panel.el.querySelector('#available-chatrooms')).children('dt').first().text()).toBe("Rooms on muc.localhost"); + expect($(panel.el.querySelector('#available-chatrooms')).children('dt').first().text()).toBe("Rooms found"); expect($(panel.el.querySelector('#available-chatrooms')).children('dd').length).toBe(4); done(); })); diff --git a/src/converse-bookmarks.js b/src/converse-bookmarks.js index 35f53b0b9..8898dcf30 100644 --- a/src/converse-bookmarks.js +++ b/src/converse-bookmarks.js @@ -417,9 +417,9 @@ initialize () { Backbone.OrderedListView.prototype.initialize.apply(this, arguments); - this.toggleBookmarksList = _.debounce(this._toggleBookmarksList, 600, {'leading': true}); + this.model.on('add', this.showOrHide, this); + this.model.on('remove', this.showOrHide, this); - this.model.on('remove', this.hideListIfEmpty, this); _converse.chatboxes.on('add', this.renderBookmarkListElement, this); _converse.chatboxes.on('remove', this.renderBookmarkListElement, this); @@ -441,7 +441,7 @@ 'label_bookmarks': __('Bookmarks'), '_converse': _converse }); - this.hideListIfEmpty(); + this.showOrHide(); this.insertIntoControlBox(); return this; }, @@ -465,17 +465,24 @@ return; } bookmarkview.render(); - this.hideListIfEmpty(); + this.showOrHide(); }, - hideListIfEmpty (item) { - const bookmarks = sizzle('.available-chatroom:not(.hidden)', this.el); - if (!this.model.models.length || !bookmarks.length) { - u.hideElement(this.el); + showOrHide (item) { + if (_converse.hide_open_bookmarks) { + const bookmarks = this.model.filter((bookmark) => + !_converse.chatboxes.get(bookmark.get('jid'))); + if (!bookmarks.length) { + u.hideElement(this.el); + return; + } + } + if (this.model.models.length) { + u.showElement(this.el); } }, - _toggleBookmarksList (ev) { + toggleBookmarksList (ev) { if (ev && ev.preventDefault) { ev.preventDefault(); } if (u.hasClass('icon-opened', ev.target)) { u.slideIn(this.el.querySelector('.bookmarks')); diff --git a/src/converse-muc.js b/src/converse-muc.js index f6a1d15c5..69a356435 100644 --- a/src/converse-muc.js +++ b/src/converse-muc.js @@ -28,11 +28,11 @@ "tpl!chatroom_toolbar", "tpl!chatrooms_tab", "tpl!info", - "tpl!no_rooms", "tpl!occupant", "tpl!room_description", "tpl!room_item", "tpl!room_panel", + "tpl!rooms_results", "tpl!spinner", "awesomplete", "converse-chatview", @@ -59,11 +59,11 @@ tpl_chatroom_toolbar, tpl_chatrooms_tab, tpl_info, - tpl_no_rooms, tpl_occupant, tpl_room_description, tpl_room_item, tpl_room_panel, + tpl_rooms_results, tpl_spinner, Awesomplete ) { @@ -2634,8 +2634,8 @@ informNoRoomsFound () { const chatrooms_el = this.el.querySelector('#available-chatrooms'); - chatrooms_el.innerHTML = tpl_no_rooms({ - 'no_rooms_text': __('No rooms found') + chatrooms_el.innerHTML = tpl_rooms_results({ + 'feedback_text': __('No rooms found') }); const input_el = this.el.querySelector('input#show-rooms'); input_el.classList.remove('hidden') @@ -2651,8 +2651,9 @@ if (this.rooms.length) { // For translators: %1$s is a variable and will be // replaced with the XMPP server name - available_chatrooms.innerHTML = - `
${__('Rooms on %1$s',this.model.get('muc_domain'))}
`; + available_chatrooms.innerHTML = tpl_rooms_results({ + 'feedback_text': __('Rooms found') + }); const div = document.createElement('div'); const fragment = document.createDocumentFragment(); for (let i=0; i