Presence subscription bugfixes.
* Return the promise, so that we can wait. * `sendContactAddIQ` now returns a promise and doesn't take a callback * Don't call `destroy` on a contact that's already been removed.
This commit is contained in:
parent
2c6bd6cea1
commit
9d0cfe8f43
40
dist/converse.js
vendored
40
dist/converse.js
vendored
@ -68616,7 +68616,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].plugins
|
||||
_converse.api.chats.open(attrs.jid, attrs);
|
||||
},
|
||||
|
||||
removeContact(ev) {
|
||||
async removeContact(ev) {
|
||||
if (ev && ev.preventDefault) {
|
||||
ev.preventDefault();
|
||||
}
|
||||
@ -68625,28 +68625,35 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].plugins
|
||||
return;
|
||||
}
|
||||
|
||||
const result = confirm(__("Are you sure you want to remove this contact?"));
|
||||
if (!confirm(__("Are you sure you want to remove this contact?"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (result === true) {
|
||||
this.model.removeFromRoster(iq => {
|
||||
this.model.destroy();
|
||||
let iq;
|
||||
|
||||
try {
|
||||
iq = await this.model.removeFromRoster();
|
||||
this.remove();
|
||||
}, function (err) {
|
||||
alert(__('Sorry, there was an error while trying to remove %1$s as a contact.', name));
|
||||
|
||||
_converse.log(err, Strophe.LogLevel.ERROR);
|
||||
});
|
||||
if (this.model.collection) {
|
||||
// The model might have already been removed as
|
||||
// result of a roster push.
|
||||
this.model.destroy();
|
||||
}
|
||||
} catch (e) {
|
||||
_converse.log(e, Strophe.LogLevel.ERROR);
|
||||
|
||||
_converse.api.alert.show(Strophe.LogLevel.ERROR, __('Sorry, there was an error while trying to remove %1$s as a contact.', name));
|
||||
}
|
||||
},
|
||||
|
||||
acceptRequest(ev) {
|
||||
async acceptRequest(ev) {
|
||||
if (ev && ev.preventDefault) {
|
||||
ev.preventDefault();
|
||||
}
|
||||
|
||||
_converse.roster.sendContactAddIQ(this.model.get('jid'), this.model.getFullname(), [], () => {
|
||||
await _converse.roster.sendContactAddIQ(this.model.get('jid'), this.model.getFullname(), []);
|
||||
this.model.authorize().subscribe();
|
||||
});
|
||||
},
|
||||
|
||||
declineRequest(ev) {
|
||||
@ -77157,7 +77164,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
|
||||
return this;
|
||||
},
|
||||
|
||||
removeFromRoster(callback, errback) {
|
||||
removeFromRoster() {
|
||||
/* Instruct the XMPP server to remove this contact from our roster
|
||||
* Parameters:
|
||||
* (Function) callback
|
||||
@ -77170,10 +77177,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
|
||||
jid: this.get('jid'),
|
||||
subscription: "remove"
|
||||
});
|
||||
|
||||
_converse.api.sendIQ(iq).then(callback).catch(errback);
|
||||
|
||||
return this;
|
||||
return _converse.api.sendIQ(iq);
|
||||
}
|
||||
|
||||
});
|
||||
@ -77319,7 +77323,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
|
||||
|
||||
_.each(groups, group => iq.c('group').t(group).up());
|
||||
|
||||
_converse.api.sendIQ(iq);
|
||||
return _converse.api.sendIQ(iq);
|
||||
},
|
||||
|
||||
async addContactToRoster(jid, name, groups, attributes) {
|
||||
|
@ -513,32 +513,38 @@ converse.plugins.add('converse-rosterview', {
|
||||
_converse.api.chats.open(attrs.jid, attrs);
|
||||
},
|
||||
|
||||
removeContact (ev) {
|
||||
async removeContact (ev) {
|
||||
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
||||
if (!_converse.allow_contact_removal) { return; }
|
||||
const result = confirm(__("Are you sure you want to remove this contact?"));
|
||||
if (result === true) {
|
||||
this.model.removeFromRoster(
|
||||
(iq) => {
|
||||
this.model.destroy();
|
||||
if (!confirm(__("Are you sure you want to remove this contact?"))) { return; }
|
||||
|
||||
let iq;
|
||||
try {
|
||||
iq = await this.model.removeFromRoster();
|
||||
this.remove();
|
||||
},
|
||||
function (err) {
|
||||
alert(__('Sorry, there was an error while trying to remove %1$s as a contact.', name));
|
||||
_converse.log(err, Strophe.LogLevel.ERROR);
|
||||
if (this.model.collection) {
|
||||
// The model might have already been removed as
|
||||
// result of a roster push.
|
||||
this.model.destroy();
|
||||
}
|
||||
} catch (e) {
|
||||
_converse.log(e, Strophe.LogLevel.ERROR);
|
||||
_converse.api.alert.show(
|
||||
Strophe.LogLevel.ERROR,
|
||||
__('Sorry, there was an error while trying to remove %1$s as a contact.', name)
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
acceptRequest (ev) {
|
||||
async acceptRequest (ev) {
|
||||
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
||||
_converse.roster.sendContactAddIQ(
|
||||
|
||||
await _converse.roster.sendContactAddIQ(
|
||||
this.model.get('jid'),
|
||||
this.model.getFullname(),
|
||||
[],
|
||||
() => { this.model.authorize().subscribe(); }
|
||||
[]
|
||||
);
|
||||
this.model.authorize().subscribe();
|
||||
},
|
||||
|
||||
declineRequest (ev) {
|
||||
|
@ -322,7 +322,7 @@ converse.plugins.add('converse-roster', {
|
||||
return this;
|
||||
},
|
||||
|
||||
removeFromRoster (callback, errback) {
|
||||
removeFromRoster () {
|
||||
/* Instruct the XMPP server to remove this contact from our roster
|
||||
* Parameters:
|
||||
* (Function) callback
|
||||
@ -330,8 +330,7 @@ converse.plugins.add('converse-roster', {
|
||||
const iq = $iq({type: 'set'})
|
||||
.c('query', {xmlns: Strophe.NS.ROSTER})
|
||||
.c('item', {jid: this.get('jid'), subscription: "remove"});
|
||||
_converse.api.sendIQ(iq).then(callback).catch(errback);
|
||||
return this;
|
||||
return _converse.api.sendIQ(iq);
|
||||
}
|
||||
});
|
||||
|
||||
@ -365,7 +364,7 @@ converse.plugins.add('converse-roster', {
|
||||
/* Register a handler for roster IQ "set" stanzas, which update
|
||||
* roster contacts.
|
||||
*/
|
||||
_converse.connection.addHandler((iq) => {
|
||||
_converse.connection.addHandler(iq => {
|
||||
_converse.roster.onRosterPush(iq);
|
||||
return true;
|
||||
}, Strophe.NS.ROSTER, 'iq', "set");
|
||||
@ -470,7 +469,7 @@ converse.plugins.add('converse-roster', {
|
||||
.c('query', {'xmlns': Strophe.NS.ROSTER})
|
||||
.c('item', { jid, name });
|
||||
_.each(groups, group => iq.c('group').t(group).up());
|
||||
_converse.api.sendIQ(iq);
|
||||
return _converse.api.sendIQ(iq);
|
||||
},
|
||||
|
||||
async addContactToRoster (jid, name, groups, attributes) {
|
||||
|
Loading…
Reference in New Issue
Block a user