Browse Source

Add button for resyncing roster contacts

JC Brand 6 years ago
parent
commit
2179255d0a
3 changed files with 20 additions and 4 deletions
  1. 12 1
      src/converse-rosterview.js
  2. 7 3
      src/headless/converse-roster.js
  3. 1 0
      src/templates/roster.html

+ 12 - 1
src/converse-rosterview.js

@@ -751,6 +751,7 @@ converse.plugins.add('converse-rosterview', {
 
             events: {
                 'click a.controlbox-heading__btn.add-contact': 'showAddContactModal',
+                'click a.controlbox-heading__btn.sync-contacts': 'syncContacts'
             },
 
             initialize () {
@@ -787,7 +788,8 @@ converse.plugins.add('converse-rosterview', {
                 this.el.innerHTML = tpl_roster({
                     'allow_contact_requests': _converse.allow_contact_requests,
                     'heading_contacts': __('Contacts'),
-                    'title_add_contact': __('Add a contact')
+                    'title_add_contact': __('Add a contact'),
+                    'title_sync_contacts': __('Re-sync your contacts')
                 });
                 const form = this.el.querySelector('.roster-filter-form');
                 this.el.replaceChild(this.filter_view.render().el, form);
@@ -861,6 +863,15 @@ converse.plugins.add('converse-rosterview', {
                 }
             },
 
+            async syncContacts (ev) {
+                ev.preventDefault();
+                u.addClass('fa-spin', ev.target);
+                _converse.roster.data.save('version', null);
+                await _converse.roster.fetchFromServer();
+                _converse.xmppstatus.sendPresence();
+                u.removeClass('fa-spin', ev.target);
+            },
+
             reset () {
                 _converse.roster.reset();
                 this.removeAll();

+ 7 - 3
src/headless/converse-roster.js

@@ -401,8 +401,12 @@ converse.plugins.add('converse-roster', {
                 let collection;
                 try {
                     collection = await new Promise((resolve, reject) => {
-                        const config = {'add': true, 'silent': true, 'success': resolve, 'error': reject};
-                        this.fetch(config);
+                        this.fetch({
+                            'add': true,
+                            'silent': true,
+                            'success': resolve,
+                            'error': reject
+                        });
                     });
                 } catch (e) {
                     return _converse.log(e, Strophe.LogLevel.ERROR);
@@ -562,7 +566,7 @@ converse.plugins.add('converse-roster', {
             },
 
             rosterVersioningSupported () {
-                return _converse.api.disco.stream.getFeature('ver', 'urn:xmpp:features:rosterver') && this.data.get('version');
+                return !!(_converse.api.disco.stream.getFeature('ver', 'urn:xmpp:features:rosterver') && this.data.get('version'));
             },
 
             async fetchFromServer () {

+ 1 - 0
src/templates/roster.html

@@ -1,5 +1,6 @@
 <div class="d-flex controlbox-padded">
     <span class="w-100 controlbox-heading">{{{o.heading_contacts}}}</span>
+    <a class="controlbox-heading__btn sync-contacts fa fa-sync" title="{{{o.title_sync_contacts}}}"></a>
     {[ if (o.allow_contact_requests) { ]}
         <a class="controlbox-heading__btn add-contact fa fa-user-plus"
            title="{{{o.title_add_contact}}}"