Merge branch 'mailbox' into staging
commit
7666a008d7
@ -0,0 +1,43 @@
|
|||||||
|
@import (reference) "./colortheme-all.less";
|
||||||
|
|
||||||
|
.notifications_main() {
|
||||||
|
--LessLoader_require: LessLoader_currentFile();
|
||||||
|
}
|
||||||
|
& {
|
||||||
|
@notif-height: 50px;
|
||||||
|
.cp-notifications-container {
|
||||||
|
max-width: 300px;
|
||||||
|
display: flex;
|
||||||
|
flex-flow: column;
|
||||||
|
.cp-notification {
|
||||||
|
height: @notif-height;
|
||||||
|
display: flex;
|
||||||
|
.cp-notification-content {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
p {
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
&.cp-clickable {
|
||||||
|
cursor: pointer;
|
||||||
|
&:hover {
|
||||||
|
background-color: rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.cp-notification-dismiss {
|
||||||
|
color: black;
|
||||||
|
width: 25px;
|
||||||
|
height: 100%;
|
||||||
|
display: none;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
span {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,58 @@
|
|||||||
|
define([
|
||||||
|
'jquery',
|
||||||
|
'/common/hyperscript.js',
|
||||||
|
'/common/common-ui-elements.js',
|
||||||
|
'/customize/messages.js',
|
||||||
|
], function ($, h, UIElements, Messages) {
|
||||||
|
|
||||||
|
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-content').addClass("cp-clickable");
|
||||||
|
$(el).find('.cp-notification-content p')
|
||||||
|
.html(Messages._getKey('friendRequest_notification', [msg.content.displayName])
|
||||||
|
.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(Messages._getKey('friendRequest_accepted', [msg.content.displayName])
|
||||||
|
$(el).find('.cp-notification-dismiss').css('display', 'flex');
|
||||||
|
};
|
||||||
|
|
||||||
|
handlers['DECLINE_FRIEND_REQUEST'] = function (common, data, el) {
|
||||||
|
var content = data.content;
|
||||||
|
var msg = content.msg;
|
||||||
|
$(el).find('.cp-notification-content p')
|
||||||
|
.html(Messages._getKey('friendRequest_declined', [msg.content.displayName])
|
||||||
|
$(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,59 @@
|
|||||||
|
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['DECLINE_FRIEND_REQUEST'] = function (ctx, box, data, cb) {
|
||||||
|
// Our friend request was declined.
|
||||||
|
if (!ctx.store.proxy.friends_pending[data.msg.author]) { return void cb(true); }
|
||||||
|
delete ctx.store.proxy.friends_pending[data.msg.author];
|
||||||
|
ctx.updateMetadata();
|
||||||
|
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