diff --git a/clientapp/helpers/xmppEventHandlers.js b/clientapp/helpers/xmppEventHandlers.js index f02ed90..fe37350 100644 --- a/clientapp/helpers/xmppEventHandlers.js +++ b/clientapp/helpers/xmppEventHandlers.js @@ -147,6 +147,12 @@ module.exports = function (client, app) { }); }); + client.on('subscribe', function (pres) { + me.contactRequests.add({ + jid: pres.from.bare + }); + }); + client.on('available', function (pres) { pres = pres.toJSON(); var contact = me.getContact(pres.from); diff --git a/clientapp/models/contactRequest.js b/clientapp/models/contactRequest.js new file mode 100644 index 0000000..603d846 --- /dev/null +++ b/clientapp/models/contactRequest.js @@ -0,0 +1,12 @@ +/*global app, me*/ +"use strict"; + +var HumanModel = require('human-model'); + + +module.exports = HumanModel.define({ + type: 'contactRequest', + props: { + jid: ['string', true, ''] + } +}); diff --git a/clientapp/models/contactRequests.js b/clientapp/models/contactRequests.js new file mode 100644 index 0000000..6028507 --- /dev/null +++ b/clientapp/models/contactRequests.js @@ -0,0 +1,10 @@ +"use strict"; + +var BaseCollection = require('./baseCollection'); +var ContactRequest = require('./contactRequest'); + + +module.exports = BaseCollection.extend({ + type: 'contactRequests', + model: ContactRequest +}); diff --git a/clientapp/models/me.js b/clientapp/models/me.js index ec147ac..ad832fd 100644 --- a/clientapp/models/me.js +++ b/clientapp/models/me.js @@ -8,6 +8,7 @@ var Calls = require('./calls'); var Contact = require('./contact'); var MUCs = require('./mucs'); var MUC = require('./muc'); +var ContactRequests = require('./contactRequests'); var fetchAvatar = require('../helpers/fetchAvatar'); @@ -45,6 +46,7 @@ module.exports = HumanModel.define({ }, collections: { contacts: Contacts, + contactRequests: ContactRequests, mucs: MUCs, calls: Calls }, @@ -104,8 +106,9 @@ module.exports = HumanModel.define({ } }, removeContact: function (jid) { - this.contacts.remove(jid.bare); - app.storage.roster.remove(jid.bare); + var contact = this.getContact(jid); + this.contacts.remove(contact.jid); + app.storage.roster.remove(contact.storageId); }, load: function () { if (!this.jid.bare) return; diff --git a/clientapp/pages/main.js b/clientapp/pages/main.js index c6b621f..e79ed64 100644 --- a/clientapp/pages/main.js +++ b/clientapp/pages/main.js @@ -5,6 +5,8 @@ var crypto = require('crypto'); var BasePage = require('./base'); var templates = require('../templates'); +var ContactRequestItem = require('../views/contactRequest'); + module.exports = BasePage.extend({ template: templates.pages.main, @@ -20,13 +22,19 @@ module.exports = BasePage.extend({ events: { 'click .enableAlerts': 'enableAlerts', 'click .installFirefox': 'installFirefox', + 'click .addContact': 'handleAddContact', 'dragover': 'handleAvatarChangeDragOver', 'drop': 'handleAvatarChange', 'change #uploader': 'handleAvatarChange', 'blur .status': 'handleStatusChange' }, initialize: function (spec) { + this.render(); + }, + render: function () { this.renderAndBind(); + this.renderCollection(this.model.contactRequests, ContactRequestItem, this.$('#contactrequests')); + return this; }, enableAlerts: function () { if (app.notifications.permissionNeeded()) { @@ -92,5 +100,16 @@ module.exports = BasePage.extend({ status: text, caps: client.disco.caps }); + }, + handleAddContact: function (e) { + e.preventDefault(); + + var contact = this.$('#addcontact').val(); + if (contact) { + app.api.sendPresence({to: contact, type: 'subscribe'}); + } + this.$('#addcontact').val(''); + + return false; } }); diff --git a/clientapp/templates.js b/clientapp/templates.js index 02461c2..a60ba21 100644 --- a/clientapp/templates.js +++ b/clientapp/templates.js @@ -74,6 +74,15 @@ exports.includes.contactListItemResource = function anonymous(locals) { return buf.join(""); }; +// contactRequest.jade compiled template +exports.includes.contactRequest = function anonymous(locals) { + var buf = []; + with (locals || {}) { + buf.push('
Drag and drop a new avatar here
Drag and drop a new avatar here