Add the ability to reject presence subscriptions.
Still part of the refactoring of strophe.roster.
This commit is contained in:
parent
f380e11851
commit
1ea770c79a
61
converse.js
61
converse.js
|
@ -30,21 +30,7 @@
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
root.converse = factory(
|
root.converse = factory(templates, jQuery, $iq, $msg, $pres, $build, DSA, OTR, Strophe, _, moment, utils, b64_sha1);
|
||||||
templates,
|
|
||||||
jQuery,
|
|
||||||
$iq,
|
|
||||||
$msg,
|
|
||||||
$pres,
|
|
||||||
$build,
|
|
||||||
DSA,
|
|
||||||
OTR,
|
|
||||||
Strophe,
|
|
||||||
_,
|
|
||||||
moment,
|
|
||||||
utils,
|
|
||||||
b64_sha1
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}(this, function (templates, $, $iq, $msg, $pres, $build, DSA, OTR, Strophe, _, moment, utils, b64_sha1) {
|
}(this, function (templates, $, $iq, $msg, $pres, $build, DSA, OTR, Strophe, _, moment, utils, b64_sha1) {
|
||||||
// "use strict";
|
// "use strict";
|
||||||
|
@ -397,8 +383,27 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.rejectPresenceSubscription = function (jid, message) {
|
||||||
|
/* Reject or cancel another user's subscription to our presence updates.
|
||||||
|
* Parameters:
|
||||||
|
* (String) jid - The Jabber ID of the user whose subscription
|
||||||
|
* is being canceled.
|
||||||
|
* (String) message - An optional message to the user
|
||||||
|
*/
|
||||||
|
var pres = $pres({to: jid, type: "unsubscribed"});
|
||||||
|
if (message && message !== "") { pres.c("status").t(message); }
|
||||||
|
converse.connection.send(pres);
|
||||||
|
};
|
||||||
|
|
||||||
this.getVCard = function (jid, callback, errback) {
|
this.getVCard = function (jid, callback, errback) {
|
||||||
|
/* Request the VCard of another user.
|
||||||
|
* Parameters:
|
||||||
|
* (String) jid - The Jabber ID of the user whose VCard is being requested.
|
||||||
|
* (Function) callback - A function to call once the VCard is returned
|
||||||
|
* (Function) errback - A function to call if an error occured
|
||||||
|
* while trying to fetch the VCard.
|
||||||
|
*/
|
||||||
if (!this.use_vcards) {
|
if (!this.use_vcards) {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(jid, jid);
|
callback(jid, jid);
|
||||||
|
@ -3511,14 +3516,24 @@
|
||||||
unauthorize: function (message) {
|
unauthorize: function (message) {
|
||||||
/* Unauthorize this contact's presence subscription
|
/* Unauthorize this contact's presence subscription
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* (String) message - An optional message to send to the person being unauthorized.
|
* (String) message - Optional message to send to the person being unauthorized
|
||||||
*/
|
*/
|
||||||
var pres = $pres({to: this.get('jid'), type: "unsubscribed"});
|
converse.rejectPresenceSubscription(this.get('jid'), message);
|
||||||
if (message && message !== "") { pres.c("status").t(message); }
|
|
||||||
converse.connection.send(pres);
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
authorize: function (message) {
|
||||||
|
/* Authorize presence subscription
|
||||||
|
* Parameters:
|
||||||
|
* (String) message - Optional message to send to the person being authorized
|
||||||
|
*/
|
||||||
|
var pres = $pres({to: jid, type: "subscribed"});
|
||||||
|
if (message && message !== "") {
|
||||||
|
pres.c("status").t(message);
|
||||||
|
}
|
||||||
|
converse.connection.send(pres);
|
||||||
|
},
|
||||||
|
|
||||||
removeFromRoster: function (callback) {
|
removeFromRoster: function (callback) {
|
||||||
/* Instruct the XMPP server to remove this contact from our roster
|
/* Instruct the XMPP server to remove this contact from our roster
|
||||||
* Parameters:
|
* Parameters:
|
||||||
|
@ -3657,7 +3672,7 @@
|
||||||
acceptRequest: function (ev) {
|
acceptRequest: function (ev) {
|
||||||
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
||||||
var jid = this.model.get('jid');
|
var jid = this.model.get('jid');
|
||||||
converse.connection.roster.authorize(jid);
|
this.model.authorize();
|
||||||
converse.connection.roster.add(jid, this.model.get('fullname'), [], function (iq) {
|
converse.connection.roster.add(jid, this.model.get('fullname'), [], function (iq) {
|
||||||
converse.roster.subscribe(jid, null, converse.xmppstatus.get('fullname'));
|
converse.roster.subscribe(jid, null, converse.xmppstatus.get('fullname'));
|
||||||
});
|
});
|
||||||
|
@ -3667,8 +3682,7 @@
|
||||||
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
||||||
var result = confirm(__("Are you sure you want to decline this contact request?"));
|
var result = confirm(__("Are you sure you want to decline this contact request?"));
|
||||||
if (result === true) {
|
if (result === true) {
|
||||||
converse.connection.roster.unauthorize(this.model.get('jid'));
|
this.model.unauthorize().destroy();
|
||||||
this.model.destroy();
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -3902,9 +3916,8 @@
|
||||||
handleIncomingSubscription: function (jid) {
|
handleIncomingSubscription: function (jid) {
|
||||||
var bare_jid = Strophe.getBareJidFromJid(jid);
|
var bare_jid = Strophe.getBareJidFromJid(jid);
|
||||||
var item = this.get(bare_jid);
|
var item = this.get(bare_jid);
|
||||||
|
|
||||||
if (!converse.allow_contact_requests) {
|
if (!converse.allow_contact_requests) {
|
||||||
converse.connection.roster.unauthorize(bare_jid);
|
converse.rejectPresenceSubscription(jid, __("This client does not allow presence subscriptions"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (converse.auto_subscribe) {
|
if (converse.auto_subscribe) {
|
||||||
|
|
|
@ -889,35 +889,32 @@
|
||||||
// mock_connection.
|
// mock_connection.
|
||||||
var name = mock.req_names.sort()[0];
|
var name = mock.req_names.sort()[0];
|
||||||
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
||||||
spyOn(this.connection.roster, 'authorize');
|
var contact = this.roster.get(jid);
|
||||||
|
spyOn(contact, 'authorize');
|
||||||
converse.rosterview.$el.find(".req-contact-name:contains('"+name+"')")
|
converse.rosterview.$el.find(".req-contact-name:contains('"+name+"')")
|
||||||
.siblings('.request-actions')
|
.siblings('.request-actions')
|
||||||
.find('.accept-xmpp-request').click();
|
.find('.accept-xmpp-request').click();
|
||||||
|
expect(contact.authorize).toHaveBeenCalled();
|
||||||
expect(this.connection.roster.authorize).toHaveBeenCalled();
|
|
||||||
}, converse));
|
}, converse));
|
||||||
|
|
||||||
it("can have their requests denied by the user", $.proxy(function () {
|
it("can have their requests denied by the user", $.proxy(function () {
|
||||||
this.rosterview.model.reset();
|
this.rosterview.model.reset();
|
||||||
runs($.proxy(function () {
|
runs($.proxy(function () {
|
||||||
spyOn(converse, 'emit');
|
|
||||||
spyOn(this.connection.roster, 'unauthorize');
|
|
||||||
spyOn(window, 'confirm').andReturn(true);
|
|
||||||
utils.createContacts('requesting').openControlBox();
|
utils.createContacts('requesting').openControlBox();
|
||||||
converse.rosterview.update(); // XXX: Hack to make sure $roster element is attaced.
|
converse.rosterview.update(); // XXX: Hack to make sure $roster element is attaced.
|
||||||
}, this));
|
}, this));
|
||||||
waits(50);
|
waits(50);
|
||||||
runs($.proxy(function () {
|
runs($.proxy(function () {
|
||||||
var name = mock.req_names.sort()[1];
|
var name = mock.req_names.sort()[1];
|
||||||
|
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
||||||
|
var contact = this.roster.get(jid);
|
||||||
|
spyOn(window, 'confirm').andReturn(true);
|
||||||
|
spyOn(contact, 'unauthorize').andCallFake(function () { return contact; });
|
||||||
converse.rosterview.$el.find(".req-contact-name:contains('"+name+"')")
|
converse.rosterview.$el.find(".req-contact-name:contains('"+name+"')")
|
||||||
.siblings('.request-actions')
|
.siblings('.request-actions')
|
||||||
.find('.decline-xmpp-request').click();
|
.find('.decline-xmpp-request').click();
|
||||||
}, this));
|
|
||||||
waits(50);
|
|
||||||
runs($.proxy(function () {
|
|
||||||
expect(window.confirm).toHaveBeenCalled();
|
expect(window.confirm).toHaveBeenCalled();
|
||||||
expect(this.connection.roster.unauthorize).toHaveBeenCalled();
|
expect(contact.unauthorize).toHaveBeenCalled();
|
||||||
// There should now be one less contact
|
// There should now be one less contact
|
||||||
expect(this.roster.length).toEqual(mock.req_names.length-1);
|
expect(this.roster.length).toEqual(mock.req_names.length-1);
|
||||||
}, this));
|
}, this));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user