From d8963a8a8c4edd9d159f9f995357ebb34523222e Mon Sep 17 00:00:00 2001 From: JC Brand Date: Sun, 7 May 2017 18:58:52 +0200 Subject: [PATCH] bookmarks: New setting `hide_open_bookmarks` --- docs/source/configuration.rst | 16 ++++++++++++++++ src/converse-bookmarks.js | 13 +++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index a12f8c247..a4cf38da9 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -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 --------------------- diff --git a/src/converse-bookmarks.js b/src/converse-bookmarks.js index 7b773d603..37d50fc03 100644 --- a/src/converse-bookmarks.js +++ b/src/converse-bookmarks.js @@ -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);