Commit 9ba8f38288170d76c141a88ba3cc8d29a11cf8e2

Authored by OpenWapp Developer
1 parent 1606d0d2d7

Fixed retrieving contact status in contact profile.

Showing 3 changed files with 33 additions and 4 deletions

app/scripts/models/contact.js View file @ 9ba8f38
... ... @@ -139,9 +139,11 @@
139 139 updateState: function (callback) {
140 140 var phones = [this.get('phone')];
141 141 var _this = this;
142   - global.client.getContactsState(phones, function (err, details) {
  142 + global.client.getContactsState(phones, function (err, statusMap) {
143 143 if (err) { return callback(err); }
144   - _this.set('state', details[0].s);
  144 + statusMap = statusMap || {};
  145 + var state = statusMap[_this.get('phone')] || '';
  146 + _this.set('state', state);
145 147 callback(null, _this.get('state'));
146 148 });
147 149 },
app/scripts/utils/contact-picker.js View file @ 9ba8f38
... ... @@ -18,7 +18,7 @@
18 18  
19 19 var activityContact = this.result;
20 20 var phone = activityContact.number;
21   - global.client.getContactsState([phone],
  21 + global.client.confirmContacts([phone],
22 22 function (err, details) {
23 23  
24 24 var contact = new Contact({
app/scripts/vendor/coseme-client/client.js View file @ 9ba8f38
... ... @@ -23,6 +23,7 @@
23 23 var _authSuccessCallback = null;
24 24 var _authErrorCallback = null;
25 25 var _contactPictureRequests = {};
  26 + var _contactStatusRequests = {};
26 27 var _contactPictureIdRequests = {};
27 28 var _groupCreateRequests = {};
28 29 var _groupParticipantRequests = {};
... ... @@ -149,6 +150,7 @@
149 150 }
150 151  
151 152 // Contact status
  153 + signals.registerListener('contacts_gotStatus', onStatusesReceived);
152 154 signals.registerListener('contact_gotProfilePicture', onPictureReceived);
153 155 signals.registerListener('group_gotPicture', onPictureReceived);
154 156 signals.registerListener(
... ... @@ -157,6 +159,17 @@
157 159 signals.registerListener('profile_setPictureError', onSetPicture);
158 160 signals.registerListener('profile_setPictureSuccess', onSetPicture);
159 161  
  162 + function defaultHandler(id) {
  163 + console.warn('No handler for response message:', id);
  164 + }
  165 +
  166 + function onStatusesReceived(id, statuses) {
  167 + var callback = _contactStatusRequests[id] ||
  168 + defaultHandler.bind(undefined, id);
  169 + delete _contactStatusRequests[id];
  170 + callback(null, statuses);
  171 + }
  172 +
160 173 function onPictureReceived(fromJID, pictureId, picture) {
161 174 var callback = _contactPictureRequests[fromJID];
162 175 delete _contactPictureRequests[fromJID];
... ... @@ -703,7 +716,7 @@
703 716 photoReader.readAsArrayBuffer(photoSet.photo);
704 717 },
705 718  
706   - getContactsState: function(numbers, callback) {
  719 + confirmContacts: function(numbers, callback) {
707 720  
708 721 CoSeMe.contacts.clearContacts();
709 722 CoSeMe.contacts.addContacts(numbers);
... ... @@ -720,6 +733,20 @@
720 733 function onError(err) {
721 734 callback(err);
722 735 }
  736 + },
  737 +
  738 + getContactsState: function(numbers, callback) {
  739 + var jids = numbers.map(this.getJID.bind(this));
  740 + var id = methods.call('contacts_getStatus', [jids]);
  741 + _contactStatusRequests[id] = function (err, statusMap) {
  742 + var phoneMap = {};
  743 + for (var jid in statusMap) {
  744 + if (statusMap.hasOwnProperty(jid)) {
  745 + phoneMap[jid.split('@')[0]] = statusMap[jid];
  746 + }
  747 + }
  748 + callback(null, phoneMap);
  749 + };
723 750 },
724 751  
725 752 subscribe: function (msisdn) {