bookmarks: New setting hide_open_bookmarks

This commit is contained in:
JC Brand 2017-05-07 18:58:52 +02:00
parent 0bd0798e34
commit d8963a8a8c
2 changed files with 27 additions and 2 deletions

View File

@ -579,6 +579,22 @@ hide_offline_users
If set to ``true``, then don't show offline users.
hide_open_bookmarks
-------------------
* Default: ``false``
This setting applies to the ``converse-bookmarks`` plugin and specfically the
list of bookmarks shown in the ``Rooms`` tab of the control box.
By default all bookmarks are shown in that list, if this setting is set to
``true``, then only bookmarks for rooms not currently open (i.e. that the
current user hasn't joined), are shown.
Makes sense to set this to ``true`` when also using the non-core
``converse-roomslist`` plugin, which shows a list of currently open (i.e.
"joined") rooms.
include_offline_state
---------------------

View File

@ -194,7 +194,8 @@
// Refer to docs/source/configuration.rst for explanations of these
// configuration settings.
this.updateSettings({
allow_bookmarks: true
allow_bookmarks: true,
hide_open_bookmarks: false
});
_converse.Bookmark = Backbone.Model;
@ -360,6 +361,8 @@
initialize: function () {
this.model.on('add', this.renderBookmarkListElement, this);
this.model.on('remove', this.removeBookmarkListElement, this);
_converse.chatboxes.on('add', this.renderBookmarkListElement, this);
_converse.chatboxes.on('remove', this.renderBookmarkListElement, this);
var cachekey = 'converse.room-bookmarks'+_converse.bare_jid+'-list-model';
this.list_model = new _converse.BookmarksList();
@ -398,6 +401,11 @@
},
renderBookmarkListElement: function (item) {
if (_converse.hide_open_bookmarks &&
_converse.chatboxes.where({'jid': item.get('jid')}).length) {
this.removeBookmarkListElement(item);
return;
}
var div = document.createElement('div');
div.innerHTML = tpl_bookmark({
'bookmarked': true,
@ -430,7 +438,7 @@
if (el) {
list_el.removeChild(el);
}
if (this.model.length === 0) {
if (list_el.childElementCount === 0) {
this.hide();
}
},
@ -460,6 +468,7 @@
{'model': _converse.bookmarks}
);
});
_converse.emit('bookmarksInitialized');
};
_converse.on('chatBoxesFetched', initBookmarks);