Skip to content

Commit

Permalink
Merge pull request loqui#883 from cmeerw/send-and-receive-vCards
Browse files Browse the repository at this point in the history
implemented sending and receiving of vCards
  • Loading branch information
cmeerw committed Nov 10, 2015
2 parents 876a164 + 49f32c1 commit e280743
Show file tree
Hide file tree
Showing 13 changed files with 786 additions and 14 deletions.
Binary file added src/img/contact.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ <h1></h1>
<i class="material-icons">&#xE0C8;</i>
<span data-l10n-id="MediaType_url">Location</span>
</li>
<li class="vcard" data-menu-onclick="vcardSend">
<i class="material-icons">&#xE0C8;</i>
<span data-l10n-id="MediaType_vCard">Contact</span>
</li>
<li class="bolt" data-menu-onclick="bolt">
<i class="material-icons">&#xE3E7;</i>
<span data-l10n-id="MediaType_bolt">Bolt</span>
Expand Down Expand Up @@ -504,6 +508,9 @@ <h1></h1>
<script type="text/javascript;version=1.7" src="scripts/loqui/blaze/renderers.js"></script>
<script type="text/javascript;version=1.7" src="scripts/meteor/blaze.js"></script>
<script type="text/javascript;version=1.7" src="scripts/mozilla/async_storage.js"></script>
<script type="text/javascript;version=1.7" src="scripts/mozilla/setImmediate.js"></script>
<script type="text/javascript;version=1.7" src="scripts/mozilla/text_normalizer.js"></script>
<script type="text/javascript;version=1.7" src="scripts/mozilla/contact2vcard.js"></script>
<script type="text/javascript;version=1.7" src="scripts/caolan/async.js"></script>
<script type="text/javascript;version=1.7" src="scripts/taylorhakes/promise-polyfill.js"></script>
<script type="text/javascript;version=1.7" src="scripts/paj/sha1.js"></script>
Expand Down
1 change: 1 addition & 0 deletions src/l10n/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ MediaType_audio=sound
MediaType_video=video
MediaType_file=File
MediaType_url=location
MediaType_vCard=Contact
MediaType_bolt=bolt
ConfirmMediaSend=Do you want to send "{{file}}" to "{{chat}}"?
Geolocating=Geolocating
Expand Down
29 changes: 22 additions & 7 deletions src/scripts/loqui/connectors/coseme.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,20 @@ App.connectors.coseme = function (account) {
Tools.locThumb(loc, 120, 120, function (thumb) {
var method = 'message_locationSend';
MI.call(method, [jid, loc.lat, loc.long, thumb]);
self.addMediaMessageToChat('url', thumb, 'https://maps.google.com/maps?q=' + loc.lat + ',' + loc.long, account.core.user, jid, Math.floor((new Date()).getTime() / 1000) + '-1');
self.addMediaMessageToChat('url', thumb, 'https://maps.google.com/maps?q=' + loc.lat + ',' + loc.long, [ loc.lat, loc.long ], account.core.user, jid, Math.floor((new Date()).getTime() / 1000) + '-1');
App.audio('sent');
});
};

this.vcardSend = function (jid, name, vcard) {
var self = this;
Tools.vcardThumb(null, 120, 120, function (thumb) {
var method = 'message_vcardSend';
MI.call(method, [jid, vcard, name]);
self.addMediaMessageToChat('vCard', thumb, null, [ name, vcard ], account.core.user, jid, Math.floor((new Date()).getTime() / 1000) + '-1');
});
};

this.avatarSet = function (blob) {
function UrlToBin (url, cb) {
var reader = new FileReader();
Expand Down Expand Up @@ -392,7 +401,7 @@ App.connectors.coseme = function (account) {
group_setSubjectSuccess: null,
group_messageReceived: this.events.onGroupMessage,
group_imageReceived: this.events.onGroupImageReceived,
group_vcardReceived: null,
group_vcardReceived: this.events.onGroupVCardReceived,
group_videoReceived: this.events.onGroupVideoReceived,
group_audioReceived: this.events.onGroupAudioReceived,
group_locationReceived: this.events.onGroupLocationReceived,
Expand Down Expand Up @@ -504,7 +513,7 @@ App.connectors.coseme = function (account) {

this.events.onVCardReceived = function (msgId, fromAttribute, vcardName, vcardData, wantsReceipt, isBroadcast, notifyName) {
var to = this.account.core.fullJid;
return this.mediaProcess('vCard', msgId, fromAttribute, to, vcardName, vcardData, null, wantsReceipt, false, notifyName);
return this.mediaProcess('vCard', msgId, fromAttribute, to, [vcardName, vcardData], null, null, wantsReceipt, false, notifyName);
};

this.events.onAvatar = function (jid, picId, blob) {
Expand Down Expand Up @@ -820,6 +829,10 @@ App.connectors.coseme = function (account) {
return this.mediaProcess('url', msgId, author, group, [mlatitude, mlongitude, name], null, null, wantsReceipt, true, notifyName);
};

this.events.onGroupVCardReceived = function (msgId, group, author, vcardName, vcardData, wantsReceipt, notifyName) {
return this.mediaProcess('vCard', msgId, author, group, [vcardName, vcardData], null, null, wantsReceipt, true, notifyName);
};

this.events.onContactsGotStatus = function (id, statuses) {
var i = Iterator(statuses);
for (let [jid, status] in i) {
Expand Down Expand Up @@ -923,7 +936,7 @@ App.connectors.coseme = function (account) {
method,
[toJID, url, hash, '0', thumb.split(',').pop()]
);
self.addMediaMessageToChat(type, thumb, url, account.core.user, toJID, Math.floor((new Date()).getTime() / 1000) + '-1');
self.addMediaMessageToChat(type, thumb, url, null, account.core.user, toJID, Math.floor((new Date()).getTime() / 1000) + '-1');
App.audio('sent');
var ext = url.split('.').pop();
var localUrl = App.pathFiles + Tools.localize(Tools.stamp(id)).replace(/[-:]/g, '') + url.split('/').pop().substring(0, 5).toUpperCase() + '.' + ext;
Expand Down Expand Up @@ -953,11 +966,12 @@ App.connectors.coseme = function (account) {
this.events.onUploadRequestDuplicate = function (hash) {
Lungo.Notification.error(_('NotUploaded'), _('DuplicatedUpload'), 'warning-sign', 5);
};
this.addMediaMessageToChat = function(type, data, url, from, to, id) {
this.addMediaMessageToChat = function(type, data, url, payload, from, to, id) {
var account = this.account;
var msgMedia = {
type: type,
thumb: data,
payload: payload,
url: url,
downloaded: true
};
Expand All @@ -978,6 +992,7 @@ App.connectors.coseme = function (account) {
var media = {
type: fileType,
thumb: thumb,
payload: mediaUrl ? null : payload,
url: mediaUrl,
downloaded: false
};
Expand Down Expand Up @@ -1013,10 +1028,10 @@ App.connectors.coseme = function (account) {
break;
case 'url':
mediaUrl = 'https://maps.google.com/maps?q=' + payload[0] + ',' + payload[1];
process('img/location.jpg');
process('img/location.png');
break;
case 'vCard':
process(null);
process('img/contact.png');
break;
}
};
Expand Down
4 changes: 4 additions & 0 deletions src/scripts/loqui/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ var Menu = {
Lungo.Router.section('back');
Plus.locationSend();
},
vcardSend: function () {
Lungo.Router.section('back');
Plus.vcardSend();
},
bolt: function () {
Lungo.Router.section('back');
Plus.bolt();
Expand Down
9 changes: 8 additions & 1 deletion src/scripts/loqui/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,14 @@ var Message = {
case 'vCard':
onClick = function(e){
e.preventDefault();
return alert('vCard');
return new MozActivity({
name: 'open',
data: {
type: 'text/vcard',
blob: new Blob([ message.core.media.payload[1] ],
{ type : 'text/vcard' })
}
});
};
break;

Expand Down
28 changes: 24 additions & 4 deletions src/scripts/loqui/plus.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global Accounts, App, Tools, Lungo, Messenger, Geo, Chat, OTR, Message, Make */
/* global Accounts, App, Tools, Lungo, Messenger, Geo, Chat, OTR, Message, Make, ContactToVcard */

/**
* @file Holds {@link Plus}
Expand Down Expand Up @@ -77,9 +77,29 @@ var Plus = {
};
},

/**
* Sends the current location to the active chat.
*/
vcardSend: function () {
var account = Accounts.current;
var to = $('section#chat')[0].dataset.jid;

var e = new MozActivity({
name: 'pick',
data: {
type: 'webcontacts/tel'
}
});

e.onsuccess = function () {
var contact = this.result;
var name = Array.isArray(contact.name) ? contact.name[0] : contact.name;
var str = '';
ContactToVcard([contact], function (vcards, nCards) {
str += vcards;
}, function () {
account.connector.vcardSend(to, name, str);
}, 0, true);
};
},

locationSend: function () {
var account = Accounts.current;
if (account.supports('locationSend')) {
Expand Down
5 changes: 3 additions & 2 deletions src/scripts/loqui/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ var Providers = {
* @const
*/
features: ['localContacts', 'receipts', 'imageSend', 'videoSend',
'audioSend', 'locationSend', 'pay', 'muc', 'csn', 'avatarChange',
'nickChange', 'statusChange', 'presence', 'mucCreate', 'readReceipts'],
'audioSend', 'locationSend', 'vcardSend', 'pay', 'muc', 'csn',
'avatarChange', 'nickChange', 'statusChange', 'presence',
'mucCreate', 'readReceipts'],

/**
* @type {string}
Expand Down
4 changes: 4 additions & 0 deletions src/scripts/loqui/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ var Tools = {
callback('img/location.png');
},

vcardThumb: function (blob, width, height, callback) {
callback('img/contact.png');
},

getFileType: function(type) {
var fileType = null;
switch (type) {
Expand Down
Loading

0 comments on commit e280743

Please sign in to comment.