Browse Source

Fixes #1214

Hide "add contact" button and requesting/pending contacts when
allow_contact_requests is false.
JC Brand 6 years ago
parent
commit
7a330600d4
5 changed files with 35 additions and 12 deletions
  1. 1 0
      CHANGES.md
  2. 17 5
      dist/converse.js
  3. 9 0
      src/converse-rosterview.js
  4. 2 5
      src/templates/pending_contact.html
  5. 6 2
      src/templates/roster.html

+ 1 - 0
CHANGES.md

@@ -4,6 +4,7 @@
 
 - Bugfix. Handler not triggered when submitting MUC password form 2nd time
 - Bugfix. MUC features weren't being refreshed when saving the config form
+- #1214 Setting `allow_contact_requests` to `false` has no effect
 - #1222 Adding a bookmark should prefill the room name
 
 ## 4.0.2 (2018-10-02)

+ 17 - 5
dist/converse.js

@@ -77129,6 +77129,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
 
         render() {
           this.el.innerHTML = tpl_roster({
+            'allow_contact_requests': _converse.allow_contact_requests,
             'heading_contacts': __('Contacts'),
             'title_add_contact': __('Add a contact')
           });
@@ -77305,6 +77306,12 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
           if (contact.get('subscription') === 'both' || contact.get('subscription') === 'to') {
             this.addExistingContact(contact, options);
           } else {
+            if (!_converse.allow_contact_requests) {
+              _converse.log(`Not adding requesting or pending contact ${contact.get('jid')} ` + `because allow_contact_requests is false`, Strophe.LogLevel.DEBUG);
+
+              return;
+            }
+
             if (contact.get('ask') === 'subscribe' || contact.get('subscription') === 'from') {
               this.addContactToGroup(contact, HEADER_PENDING_CONTACTS, options);
             } else if (contact.get('requesting') === true) {
@@ -80065,7 +80072,7 @@ var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
 function print() { __p += __j.call(arguments, '') }
 __p += '<!-- src/templates/pending_contact.html -->\n';
  if (o.allow_chat_pending_contacts)  { ;
-__p += '\n<a class="open-chat w-100" href="#">\n';
+__p += '<a class="open-chat w-100" href="#">';
  } ;
 __p += '\n<span class="pending-contact-name w-100" title="JID: ' +
 __e(o.jid) +
@@ -80073,7 +80080,7 @@ __e(o.jid) +
 __e(o.display_name) +
 '</span> \n';
  if (o.allow_chat_pending_contacts)  { ;
-__p += '</a>\n';
+__p += '</a>';
  } ;
 __p += '\n<a class="remove-xmpp-contact far fa-trash-alt" title="' +
 __e(o.desc_remove) +
@@ -80694,12 +80701,17 @@ return __p
 
 var _ = {escape:__webpack_require__(/*! ./node_modules/lodash/escape.js */ "./node_modules/lodash/escape.js")};
 module.exports = function(o) {
-var __t, __p = '', __e = _.escape;
+var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
+function print() { __p += __j.call(arguments, '') }
 __p += '<!-- src/templates/roster.html -->\n<div class="d-flex controlbox-padded">\n    <span class="w-100 controlbox-heading">' +
 __e(o.heading_contacts) +
-'</span>\n    <a class="chatbox-btn add-contact fa fa-user-plus" title="' +
+'</span>\n    ';
+ if (o.allow_contact_requests) { ;
+__p += '\n        <a class="chatbox-btn add-contact fa fa-user-plus"\n           title="' +
 __e(o.title_add_contact) +
-'"\n       data-toggle="modal" data-target="#add-contact-modal"></a>\n</div>\n\n<form class="roster-filter-form"></form>\n\n<div class="roster-contacts"></div>\n';
+'"\n           data-toggle="modal"\n           data-target="#add-contact-modal"></a>\n    ';
+ } ;
+__p += '\n</div>\n\n<form class="roster-filter-form"></form>\n\n<div class="roster-contacts"></div>\n';
 return __p
 };
 

+ 9 - 0
src/converse-rosterview.js

@@ -800,6 +800,7 @@
 
                 render () {
                     this.el.innerHTML = tpl_roster({
+                        'allow_contact_requests': _converse.allow_contact_requests,
                         'heading_contacts': __('Contacts'),
                         'title_add_contact': __('Add a contact')
                     });
@@ -952,6 +953,14 @@
                     if (contact.get('subscription') === 'both' || contact.get('subscription') === 'to') {
                         this.addExistingContact(contact, options);
                     } else {
+                        if (!_converse.allow_contact_requests) {
+                            _converse.log(
+                                `Not adding requesting or pending contact ${contact.get('jid')} `+
+                                `because allow_contact_requests is false`,
+                                Strophe.LogLevel.DEBUG
+                            );
+                            return;
+                        }
                         if ((contact.get('ask') === 'subscribe') || (contact.get('subscription') === 'from')) {
                             this.addContactToGroup(contact, HEADER_PENDING_CONTACTS, options);
                         } else if (contact.get('requesting') === true) {

+ 2 - 5
src/templates/pending_contact.html

@@ -1,7 +1,4 @@
-{[ if (o.allow_chat_pending_contacts)  { ]}
-<a class="open-chat w-100" href="#">
-{[ } ]}
+{[ if (o.allow_chat_pending_contacts)  { ]}<a class="open-chat w-100" href="#">{[ } ]}
 <span class="pending-contact-name w-100" title="JID: {{{o.jid}}}">{{{o.display_name}}}</span> 
-{[ if (o.allow_chat_pending_contacts)  { ]}</a>
-{[ } ]}
+{[ if (o.allow_chat_pending_contacts)  { ]}</a>{[ } ]}
 <a class="remove-xmpp-contact far fa-trash-alt" title="{{{o.desc_remove}}}" href="#"></a>

+ 6 - 2
src/templates/roster.html

@@ -1,7 +1,11 @@
 <div class="d-flex controlbox-padded">
     <span class="w-100 controlbox-heading">{{{o.heading_contacts}}}</span>
-    <a class="chatbox-btn add-contact fa fa-user-plus" title="{{{o.title_add_contact}}}"
-       data-toggle="modal" data-target="#add-contact-modal"></a>
+    {[ if (o.allow_contact_requests) { ]}
+        <a class="chatbox-btn add-contact fa fa-user-plus"
+           title="{{{o.title_add_contact}}}"
+           data-toggle="modal"
+           data-target="#add-contact-modal"></a>
+    {[ } ]}
 </div>
 
 <form class="roster-filter-form"></form>