You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.9 KiB
JavaScript
59 lines
1.9 KiB
JavaScript
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);
|
|
},
|
|
};
|
|
});
|