Improve friend request process and UI
parent
38f8535dd5
commit
9cb1a059f2
@ -0,0 +1,50 @@
|
|||||||
|
define([
|
||||||
|
'jquery',
|
||||||
|
'/common/hyperscript.js',
|
||||||
|
'/common/common-ui-elements.js'
|
||||||
|
], function ($, h, UIElements) {
|
||||||
|
|
||||||
|
var handlers = {};
|
||||||
|
|
||||||
|
handlers['FRIEND_REQUEST'] = function (common, data, el) {
|
||||||
|
var content = data.content;
|
||||||
|
var msg = content.msg;
|
||||||
|
|
||||||
|
// Check authenticity
|
||||||
|
if (msg.author !== msg.content.curvePublic) { return; }
|
||||||
|
|
||||||
|
common.addFriendRequest(data);
|
||||||
|
|
||||||
|
// Display the notification
|
||||||
|
$(el).find('.cp-notification-dismiss').attr('title', 'IGNORE').css('display', 'flex'); // XXX
|
||||||
|
$(el).find('.cp-notification-content').addClass("cp-clickable");
|
||||||
|
$(el).find('.cp-notification-content p')
|
||||||
|
.html('New friend request: <b>'+msg.content.displayName+'</b>') // XXX
|
||||||
|
.click(function () {
|
||||||
|
UIElements.displayFriendRequestModal(common, data);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
handlers['ACCEPT_FRIEND_REQUEST'] = function (common, data, el) {
|
||||||
|
var content = data.content;
|
||||||
|
var msg = content.msg;
|
||||||
|
$(el).find('.cp-notification-content p')
|
||||||
|
.html('Friend request accepted: <b>'+msg.content.displayName+'</b>');
|
||||||
|
$(el).find('.cp-notification-dismiss').css('display', 'flex');
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
add: function (common, data, el) {
|
||||||
|
var type = data.content.msg.type;
|
||||||
|
|
||||||
|
if (handlers[type]) {
|
||||||
|
handlers[type](common, data, el);
|
||||||
|
} else {
|
||||||
|
$(el).find('.cp-notification-dismiss').css('display', 'flex');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
remove: function (common, data) {
|
||||||
|
common.removeFriendRequest(data.hash);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
@ -0,0 +1,52 @@
|
|||||||
|
define([
|
||||||
|
'/common/common-messaging.js',
|
||||||
|
], function (Messaging) {
|
||||||
|
|
||||||
|
var handlers = {};
|
||||||
|
|
||||||
|
handlers['FRIEND_REQUEST'] = function (ctx, data, cb) {
|
||||||
|
if (data.msg.author === data.msg.content.curvePublic &&
|
||||||
|
Messaging.getFriend(ctx.store.proxy, data.msg.author)) {
|
||||||
|
Messaging.acceptFriendRequest(ctx.store, data.msg.content, function (obj) {
|
||||||
|
if (obj && obj.error) { return void cb(); }
|
||||||
|
cb(true);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cb();
|
||||||
|
};
|
||||||
|
handlers['ACCEPT_FRIEND_REQUEST'] = function (ctx, box, data, cb) {
|
||||||
|
// Our friend request was accepted.
|
||||||
|
// Make sure we really sent it
|
||||||
|
if (!ctx.store.proxy.friends_pending[data.msg.author]) { return void cb(); }
|
||||||
|
// And add the friend
|
||||||
|
Messaging.addToFriendList({
|
||||||
|
proxy: ctx.store.proxy,
|
||||||
|
realtime: ctx.store.realtime,
|
||||||
|
pinPads: ctx.pinPads
|
||||||
|
}, data.msg.content, function (err) {
|
||||||
|
if (err) { console.error(err); }
|
||||||
|
delete ctx.store.proxy.friends_pending[data.msg.author];
|
||||||
|
if (ctx.store.messenger) {
|
||||||
|
ctx.store.messenger.onFriendAdded(data.msg.content);
|
||||||
|
}
|
||||||
|
ctx.updateMetadata();
|
||||||
|
});
|
||||||
|
cb();
|
||||||
|
};
|
||||||
|
|
||||||
|
return function (ctx, box, data, cb) {
|
||||||
|
var type = data.msg.type;
|
||||||
|
|
||||||
|
if (handlers[type]) {
|
||||||
|
try {
|
||||||
|
handlers[type](ctx, box, data, cb);
|
||||||
|
} catch (e) {
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue