2019-05-22 16:03:52 +00:00
|
|
|
|
define([
|
|
|
|
|
'jquery',
|
|
|
|
|
'/common/hyperscript.js',
|
2019-06-04 14:19:47 +00:00
|
|
|
|
'/common/common-hash.js',
|
2019-07-11 12:16:04 +00:00
|
|
|
|
'/common/common-interface.js',
|
2019-05-23 13:12:59 +00:00
|
|
|
|
'/common/common-ui-elements.js',
|
2019-08-27 10:03:25 +00:00
|
|
|
|
'/common/common-util.js',
|
2019-07-18 15:18:36 +00:00
|
|
|
|
'/common/common-constants.js',
|
2019-05-23 13:12:59 +00:00
|
|
|
|
'/customize/messages.js',
|
2021-03-24 09:11:47 +00:00
|
|
|
|
'/customize/pages.js',
|
|
|
|
|
], function($, h, Hash, UI, UIElements, Util, Constants, Messages, Pages) {
|
2019-05-22 16:03:52 +00:00
|
|
|
|
|
|
|
|
|
var handlers = {};
|
|
|
|
|
|
2020-05-05 09:19:32 +00:00
|
|
|
|
var defaultDismiss = function(common, data) {
|
|
|
|
|
return function(e) {
|
2019-06-27 09:25:31 +00:00
|
|
|
|
if (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
}
|
2020-05-05 09:19:32 +00:00
|
|
|
|
common.mailbox.dismiss(data, function(err) {
|
2019-06-27 07:51:23 +00:00
|
|
|
|
if (err) { return void console.error(err); }
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2019-06-04 13:57:39 +00:00
|
|
|
|
// Friend request
|
|
|
|
|
|
2020-05-05 09:19:32 +00:00
|
|
|
|
handlers['FRIEND_REQUEST'] = function(common, data) {
|
2019-05-22 16:03:52 +00:00
|
|
|
|
var content = data.content;
|
|
|
|
|
var msg = content.msg;
|
2020-02-05 12:33:32 +00:00
|
|
|
|
var userData = msg.content.user || msg.content;
|
|
|
|
|
var name = Util.fixHTML(userData.displayName) || Messages.anonymous;
|
|
|
|
|
msg.content = { user: userData };
|
2019-05-22 16:03:52 +00:00
|
|
|
|
|
|
|
|
|
// Display the notification
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.getFormatText = function() {
|
2019-08-27 10:03:25 +00:00
|
|
|
|
return Messages._getKey('friendRequest_notification', [name]);
|
2019-06-27 07:51:23 +00:00
|
|
|
|
};
|
2019-07-01 11:52:17 +00:00
|
|
|
|
|
2019-07-02 11:42:08 +00:00
|
|
|
|
// Check authenticity
|
2020-02-05 12:33:32 +00:00
|
|
|
|
if (msg.author !== userData.curvePublic) { return; }
|
2019-07-02 11:42:08 +00:00
|
|
|
|
|
2019-07-01 11:52:17 +00:00
|
|
|
|
// if not archived, add handlers
|
|
|
|
|
if (!content.archived) {
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.handler = function() {
|
2019-07-01 11:52:17 +00:00
|
|
|
|
UIElements.displayFriendRequestModal(common, data);
|
|
|
|
|
};
|
|
|
|
|
common.addFriendRequest(data);
|
|
|
|
|
}
|
2019-05-22 16:03:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
2020-05-05 09:19:32 +00:00
|
|
|
|
handlers['FRIEND_REQUEST_ACCEPTED'] = function(common, data) {
|
2019-05-22 16:03:52 +00:00
|
|
|
|
var content = data.content;
|
|
|
|
|
var msg = content.msg;
|
2020-02-05 12:33:32 +00:00
|
|
|
|
var userData = typeof(msg.content.user) === "object" ? msg.content.user : {
|
|
|
|
|
displayName: msg.content.name,
|
|
|
|
|
curvePublic: msg.content.user
|
|
|
|
|
};
|
|
|
|
|
var name = Util.fixHTML(userData.displayName) || Messages.anonymous;
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.getFormatText = function() {
|
2019-08-27 10:03:25 +00:00
|
|
|
|
return Messages._getKey('friendRequest_accepted', [name]);
|
2019-06-27 07:51:23 +00:00
|
|
|
|
};
|
2019-07-01 11:52:17 +00:00
|
|
|
|
if (!content.archived) {
|
|
|
|
|
content.dismissHandler = defaultDismiss(common, data);
|
|
|
|
|
}
|
2019-05-23 13:25:05 +00:00
|
|
|
|
};
|
|
|
|
|
|
2020-05-05 09:19:32 +00:00
|
|
|
|
handlers['FRIEND_REQUEST_DECLINED'] = function(common, data) {
|
2019-05-23 13:25:05 +00:00
|
|
|
|
var content = data.content;
|
|
|
|
|
var msg = content.msg;
|
2020-02-05 12:33:32 +00:00
|
|
|
|
var userData = typeof(msg.content.user) === "object" ? msg.content.user : {
|
|
|
|
|
displayName: msg.content.name,
|
|
|
|
|
curvePublic: msg.content.user
|
|
|
|
|
};
|
|
|
|
|
var name = Util.fixHTML(userData.displayName) || Messages.anonymous;
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.getFormatText = function() {
|
2019-08-27 10:03:25 +00:00
|
|
|
|
return Messages._getKey('friendRequest_declined', [name]);
|
2019-06-27 07:51:23 +00:00
|
|
|
|
};
|
2019-07-01 11:52:17 +00:00
|
|
|
|
if (!content.archived) {
|
|
|
|
|
content.dismissHandler = defaultDismiss(common, data);
|
|
|
|
|
}
|
2019-05-22 16:03:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
2019-06-04 13:57:39 +00:00
|
|
|
|
// Share pad
|
2020-05-05 09:19:32 +00:00
|
|
|
|
handlers['SHARE_PAD'] = function(common, data) {
|
2019-06-04 13:57:39 +00:00
|
|
|
|
var content = data.content;
|
|
|
|
|
var msg = content.msg;
|
2019-06-04 14:19:47 +00:00
|
|
|
|
var type = Hash.parsePadUrl(msg.content.href).type;
|
2021-02-26 12:05:04 +00:00
|
|
|
|
var key = type === 'drive' ? 'notification_folderShared' : // Msg.notification_folderSharedTeam
|
|
|
|
|
(type === 'file' ? 'notification_fileShared' : // Msg.notification_fileSharedTeam
|
|
|
|
|
'notification_padShared'); // Msg.notification_padSharedTeam
|
2020-06-04 14:54:56 +00:00
|
|
|
|
|
|
|
|
|
var teamNotification = /^team-/.test(data.type) && Number(data.type.slice(5));
|
|
|
|
|
var teamName = '';
|
|
|
|
|
if (teamNotification) {
|
|
|
|
|
var privateData = common.getMetadataMgr().getPrivateData();
|
|
|
|
|
var teamsData = Util.tryParse(JSON.stringify(privateData.teams)) || {};
|
|
|
|
|
var team = teamsData[teamNotification];
|
|
|
|
|
if (!team || !team.name) { return; }
|
|
|
|
|
key += "Team";
|
|
|
|
|
teamName = Util.fixHTML(team.name);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-27 10:03:25 +00:00
|
|
|
|
var name = Util.fixHTML(msg.content.name) || Messages.anonymous;
|
|
|
|
|
var title = Util.fixHTML(msg.content.title);
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.getFormatText = function() {
|
2020-06-04 14:54:56 +00:00
|
|
|
|
return Messages._getKey(key, [name, title, teamName]);
|
2019-06-27 07:51:23 +00:00
|
|
|
|
};
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.handler = function() {
|
2020-10-30 14:00:12 +00:00
|
|
|
|
var obj = {
|
2020-10-29 13:06:16 +00:00
|
|
|
|
p: msg.content.isTemplate ? ['template'] : undefined,
|
|
|
|
|
t: teamNotification || undefined,
|
|
|
|
|
pw: msg.content.password || ''
|
2020-10-30 14:00:12 +00:00
|
|
|
|
};
|
|
|
|
|
common.openURL(Hash.getNewPadURL(msg.content.href, obj));
|
2020-10-29 13:06:16 +00:00
|
|
|
|
defaultDismiss(common, data)();
|
2019-07-01 11:52:17 +00:00
|
|
|
|
};
|
|
|
|
|
if (!content.archived) {
|
|
|
|
|
content.dismissHandler = defaultDismiss(common, data);
|
|
|
|
|
}
|
2019-06-04 13:57:39 +00:00
|
|
|
|
};
|
|
|
|
|
|
2019-07-16 12:31:57 +00:00
|
|
|
|
// New support message from the admins
|
2020-05-05 09:19:32 +00:00
|
|
|
|
handlers['SUPPORT_MESSAGE'] = function(common, data) {
|
2019-07-16 12:31:57 +00:00
|
|
|
|
var content = data.content;
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.getFormatText = function() {
|
2019-07-16 12:31:57 +00:00
|
|
|
|
return Messages.support_notification;
|
|
|
|
|
};
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.handler = function() {
|
2019-07-16 12:31:57 +00:00
|
|
|
|
common.openURL('/support/');
|
|
|
|
|
defaultDismiss(common, data)();
|
|
|
|
|
};
|
2019-09-03 16:09:48 +00:00
|
|
|
|
if (!content.archived) {
|
|
|
|
|
content.dismissHandler = defaultDismiss(common, data);
|
|
|
|
|
}
|
2019-07-16 12:37:03 +00:00
|
|
|
|
};
|
|
|
|
|
|
2020-05-05 09:19:32 +00:00
|
|
|
|
handlers['REQUEST_PAD_ACCESS'] = function(common, data) {
|
2019-07-11 12:16:04 +00:00
|
|
|
|
var content = data.content;
|
|
|
|
|
var msg = content.msg;
|
|
|
|
|
|
|
|
|
|
// Check authenticity
|
|
|
|
|
if (msg.author !== msg.content.user.curvePublic) { return; }
|
|
|
|
|
|
|
|
|
|
// Display the notification
|
2019-08-27 10:03:25 +00:00
|
|
|
|
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
|
|
|
|
|
var title = Util.fixHTML(msg.content.title);
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.getFormatText = function() {
|
2019-08-27 10:03:25 +00:00
|
|
|
|
return Messages._getKey('requestEdit_request', [title, name]);
|
2019-07-16 15:29:55 +00:00
|
|
|
|
};
|
2019-07-11 12:16:04 +00:00
|
|
|
|
|
|
|
|
|
// if not archived, add handlers
|
2019-09-03 15:58:56 +00:00
|
|
|
|
if (!content.archived) {
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.handler = function() {
|
2019-09-03 15:58:56 +00:00
|
|
|
|
var link = h('a', {
|
|
|
|
|
href: '#'
|
|
|
|
|
}, Messages.requestEdit_viewPad);
|
|
|
|
|
|
|
|
|
|
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
|
|
|
|
|
var title = Util.fixHTML(msg.content.title);
|
2019-09-20 13:27:20 +00:00
|
|
|
|
var verified = UIElements.getVerifiedFriend(common, msg.author, name);
|
2019-07-16 15:29:55 +00:00
|
|
|
|
|
2019-09-03 15:58:56 +00:00
|
|
|
|
var div = h('div', [
|
|
|
|
|
UI.setHTML(h('p'), Messages._getKey('requestEdit_confirm', [title, name])),
|
|
|
|
|
verified,
|
|
|
|
|
link
|
|
|
|
|
]);
|
2020-05-05 09:19:32 +00:00
|
|
|
|
$(link).click(function(e) {
|
2019-09-03 15:58:56 +00:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
common.openURL(msg.content.href);
|
2019-07-13 09:47:58 +00:00
|
|
|
|
});
|
2020-05-05 09:19:32 +00:00
|
|
|
|
UI.confirm(div, function(yes) {
|
2019-09-03 15:58:56 +00:00
|
|
|
|
if (!yes) { return; }
|
|
|
|
|
common.getSframeChannel().event('EV_GIVE_ACCESS', {
|
|
|
|
|
channel: msg.content.channel,
|
|
|
|
|
user: msg.content.user
|
|
|
|
|
});
|
|
|
|
|
defaultDismiss(common, data)();
|
|
|
|
|
}, {
|
|
|
|
|
ok: Messages.friendRequest_accept,
|
|
|
|
|
cancel: Messages.later
|
|
|
|
|
});
|
|
|
|
|
};
|
2019-07-13 09:47:58 +00:00
|
|
|
|
|
2019-07-16 12:31:57 +00:00
|
|
|
|
content.dismissHandler = defaultDismiss(common, data);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-05 09:19:32 +00:00
|
|
|
|
handlers['GIVE_PAD_ACCESS'] = function(common, data) {
|
2019-07-13 09:47:58 +00:00
|
|
|
|
var content = data.content;
|
|
|
|
|
var msg = content.msg;
|
|
|
|
|
|
|
|
|
|
// Check authenticity
|
|
|
|
|
if (msg.author !== msg.content.user.curvePublic) { return; }
|
|
|
|
|
|
|
|
|
|
if (!msg.content.href) { return; }
|
|
|
|
|
|
2019-08-27 10:03:25 +00:00
|
|
|
|
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
|
|
|
|
|
var title = Util.fixHTML(msg.content.title);
|
|
|
|
|
|
2019-07-13 09:47:58 +00:00
|
|
|
|
// Display the notification
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.getFormatText = function() {
|
2019-08-27 10:03:25 +00:00
|
|
|
|
return Messages._getKey('requestEdit_accepted', [title, name]);
|
2019-07-16 15:29:55 +00:00
|
|
|
|
};
|
2019-07-13 09:47:58 +00:00
|
|
|
|
|
|
|
|
|
// if not archived, add handlers
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.handler = function() {
|
2019-07-13 09:47:58 +00:00
|
|
|
|
common.openURL(msg.content.href);
|
|
|
|
|
defaultDismiss(common, data)();
|
|
|
|
|
};
|
2019-07-11 12:16:04 +00:00
|
|
|
|
};
|
|
|
|
|
|
2019-08-30 14:41:48 +00:00
|
|
|
|
|
2020-05-05 09:19:32 +00:00
|
|
|
|
handlers['ADD_OWNER'] = function(common, data) {
|
2019-08-30 14:41:48 +00:00
|
|
|
|
var content = data.content;
|
|
|
|
|
var msg = content.msg;
|
|
|
|
|
|
|
|
|
|
// Display the notification
|
2019-08-30 15:36:27 +00:00
|
|
|
|
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
|
|
|
|
|
var title = Util.fixHTML(msg.content.title);
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.getFormatText = function() {
|
2021-02-26 12:05:04 +00:00
|
|
|
|
return Messages._getKey('owner_request', [name, title]); // Msg.owner_request_accepted, .owner_request_declined
|
2019-08-30 14:41:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Check authenticity
|
2019-08-30 15:36:27 +00:00
|
|
|
|
if (msg.author !== msg.content.user.curvePublic) { return; }
|
2019-08-30 14:41:48 +00:00
|
|
|
|
|
|
|
|
|
// if not archived, add handlers
|
|
|
|
|
if (!content.archived) {
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.handler = function() {
|
2019-09-30 13:17:26 +00:00
|
|
|
|
if (msg.content.teamChannel) {
|
|
|
|
|
return void UIElements.displayAddTeamOwnerModal(common, data);
|
|
|
|
|
}
|
2019-08-30 14:41:48 +00:00
|
|
|
|
UIElements.displayAddOwnerModal(common, data);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-05 09:19:32 +00:00
|
|
|
|
handlers['ADD_OWNER_ANSWER'] = function(common, data) {
|
2019-08-30 15:36:27 +00:00
|
|
|
|
var content = data.content;
|
|
|
|
|
var msg = content.msg;
|
|
|
|
|
|
|
|
|
|
// Display the notification
|
|
|
|
|
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
|
|
|
|
|
var title = Util.fixHTML(msg.content.title);
|
|
|
|
|
var key = 'owner_request_' + (msg.content.answer ? 'accepted' : 'declined');
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.getFormatText = function() {
|
2019-08-30 15:36:27 +00:00
|
|
|
|
return Messages._getKey(key, [name, title]);
|
|
|
|
|
};
|
|
|
|
|
if (!content.archived) {
|
|
|
|
|
content.dismissHandler = defaultDismiss(common, data);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-05 09:19:32 +00:00
|
|
|
|
handlers['RM_OWNER'] = function(common, data) {
|
2019-09-02 16:46:52 +00:00
|
|
|
|
var content = data.content;
|
|
|
|
|
var msg = content.msg;
|
|
|
|
|
|
|
|
|
|
// Display the notification
|
|
|
|
|
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
|
|
|
|
|
var title = Util.fixHTML(msg.content.title);
|
2021-02-26 10:38:04 +00:00
|
|
|
|
var key = 'owner_removed' + (msg.content.pending ? 'Pending' : ''); // Msg.owner_removed, owner_removedPending
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.getFormatText = function() {
|
2019-09-02 16:46:52 +00:00
|
|
|
|
return Messages._getKey(key, [name, title]);
|
|
|
|
|
};
|
|
|
|
|
if (!content.archived) {
|
|
|
|
|
content.dismissHandler = defaultDismiss(common, data);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-05 09:19:32 +00:00
|
|
|
|
handlers['INVITE_TO_TEAM'] = function(common, data) {
|
2019-09-20 13:27:20 +00:00
|
|
|
|
var content = data.content;
|
|
|
|
|
var msg = content.msg;
|
|
|
|
|
|
|
|
|
|
// Display the notification
|
|
|
|
|
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
|
2020-05-05 09:19:32 +00:00
|
|
|
|
var teamName = Util.fixHTML(Util.find(msg, ['content', 'team', 'metadata', 'name']) || '');
|
|
|
|
|
content.getFormatText = function() {
|
2019-09-24 08:52:03 +00:00
|
|
|
|
var text = Messages._getKey('team_invitedToTeam', [name, teamName]);
|
2019-09-20 13:27:20 +00:00
|
|
|
|
return text;
|
|
|
|
|
};
|
|
|
|
|
if (!content.archived) {
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.handler = function() {
|
2019-09-20 13:27:20 +00:00
|
|
|
|
UIElements.displayInviteTeamModal(common, data);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-05 09:19:32 +00:00
|
|
|
|
handlers['KICKED_FROM_TEAM'] = function(common, data) {
|
2019-09-23 08:51:46 +00:00
|
|
|
|
var content = data.content;
|
|
|
|
|
var msg = content.msg;
|
|
|
|
|
|
|
|
|
|
// Display the notification
|
|
|
|
|
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
|
2020-05-05 09:19:32 +00:00
|
|
|
|
var teamName = Util.fixHTML(Util.find(msg, ['content', 'teamName']) || '');
|
|
|
|
|
content.getFormatText = function() {
|
2019-09-24 08:52:03 +00:00
|
|
|
|
var text = Messages._getKey('team_kickedFromTeam', [name, teamName]);
|
2019-09-23 08:51:46 +00:00
|
|
|
|
return text;
|
|
|
|
|
};
|
|
|
|
|
if (!content.archived) {
|
|
|
|
|
content.dismissHandler = defaultDismiss(common, data);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-31 08:48:15 +00:00
|
|
|
|
handlers['INVITE_TO_TEAM_ANSWERED'] = function(common, data) {
|
2019-09-20 13:27:20 +00:00
|
|
|
|
var content = data.content;
|
|
|
|
|
var msg = content.msg;
|
|
|
|
|
|
|
|
|
|
// Display the notification
|
|
|
|
|
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
|
2020-05-05 09:19:32 +00:00
|
|
|
|
var teamName = Util.fixHTML(Util.find(msg, ['content', 'team', 'metadata', 'name']) || '') ||
|
|
|
|
|
Util.fixHTML(Util.find(msg, ['content', 'teamName']));
|
2021-02-26 12:05:04 +00:00
|
|
|
|
var key = 'team_' + (msg.content.answer ? 'accept' : 'decline') + 'Invitation'; // Msg.team_acceptInvitation, team_declineInvitation
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.getFormatText = function() {
|
2019-09-24 08:52:03 +00:00
|
|
|
|
return Messages._getKey(key, [name, teamName]);
|
2019-09-20 13:27:20 +00:00
|
|
|
|
};
|
|
|
|
|
if (!content.archived) {
|
|
|
|
|
content.dismissHandler = defaultDismiss(common, data);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-05 09:19:32 +00:00
|
|
|
|
handlers['COMMENT_REPLY'] = function(common, data) {
|
2020-04-27 12:38:29 +00:00
|
|
|
|
var content = data.content;
|
|
|
|
|
var msg = content.msg;
|
|
|
|
|
|
|
|
|
|
// Display the notification
|
|
|
|
|
//var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
|
2020-05-05 09:19:32 +00:00
|
|
|
|
var comment = Util.fixHTML(msg.content.comment).slice(0, 20).trim();
|
2020-04-27 12:38:29 +00:00
|
|
|
|
if (msg.content.comment.length > 20) {
|
|
|
|
|
comment += '...';
|
|
|
|
|
}
|
2020-04-28 14:40:40 +00:00
|
|
|
|
var title = Util.fixHTML(msg.content.title || Messages.unknownPad);
|
2020-04-27 12:38:29 +00:00
|
|
|
|
var href = msg.content.href;
|
|
|
|
|
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.getFormatText = function() {
|
2020-04-27 12:38:29 +00:00
|
|
|
|
return Messages._getKey('comments_notification', [comment, title]);
|
|
|
|
|
};
|
2020-04-28 14:40:40 +00:00
|
|
|
|
if (href) {
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.handler = function() {
|
2020-04-28 14:40:40 +00:00
|
|
|
|
common.openURL(href);
|
|
|
|
|
defaultDismiss(common, data)();
|
|
|
|
|
};
|
|
|
|
|
}
|
2020-04-28 13:54:12 +00:00
|
|
|
|
if (!content.archived) {
|
|
|
|
|
content.dismissHandler = defaultDismiss(common, data);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-05 09:19:32 +00:00
|
|
|
|
handlers['MENTION'] = function(common, data) {
|
2020-04-28 13:54:12 +00:00
|
|
|
|
var content = data.content;
|
|
|
|
|
var msg = content.msg;
|
|
|
|
|
|
|
|
|
|
// Display the notification
|
|
|
|
|
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
|
2020-04-28 14:40:40 +00:00
|
|
|
|
var title = Util.fixHTML(msg.content.title || Messages.unknownPad);
|
2020-04-28 13:54:12 +00:00
|
|
|
|
var href = msg.content.href;
|
|
|
|
|
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.getFormatText = function() {
|
2020-04-28 13:54:12 +00:00
|
|
|
|
return Messages._getKey('mentions_notification', [name, title]);
|
|
|
|
|
};
|
2020-04-28 14:40:40 +00:00
|
|
|
|
if (href) {
|
2020-05-05 09:19:32 +00:00
|
|
|
|
content.handler = function() {
|
2020-04-28 14:40:40 +00:00
|
|
|
|
common.openURL(href);
|
|
|
|
|
defaultDismiss(common, data)();
|
|
|
|
|
};
|
|
|
|
|
}
|
2020-04-27 12:38:29 +00:00
|
|
|
|
if (!content.archived) {
|
|
|
|
|
content.dismissHandler = defaultDismiss(common, data);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-15 13:27:55 +00:00
|
|
|
|
handlers['MOVE_TODO'] = function(common, data) {
|
|
|
|
|
var content = data.content;
|
|
|
|
|
var msg = content.msg;
|
|
|
|
|
|
|
|
|
|
// Display the notification
|
|
|
|
|
var title = Util.fixHTML(Messages.type.todo);
|
|
|
|
|
var href = msg.content.href;
|
|
|
|
|
|
|
|
|
|
content.getFormatText = function() {
|
|
|
|
|
return Messages._getKey('todo_move', [title]);
|
|
|
|
|
};
|
|
|
|
|
if (href) {
|
|
|
|
|
content.handler = function() {
|
|
|
|
|
common.openURL(href);
|
|
|
|
|
defaultDismiss(common, data)();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
if (!content.archived) {
|
|
|
|
|
content.dismissHandler = defaultDismiss(common, data);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-08 19:34:20 +00:00
|
|
|
|
handlers['SAFE_LINKS_DEFAULT'] = function (common, data) {
|
|
|
|
|
var content = data.content;
|
|
|
|
|
content.getFormatText = function () {
|
2021-03-24 09:11:47 +00:00
|
|
|
|
var msg = Pages.setHTML(h('span'), Messages.settings_safeLinkDefault);
|
|
|
|
|
var i = msg.querySelector('i');
|
|
|
|
|
if (i) { i.classList = 'fa fa-shhare-alt'; }
|
|
|
|
|
return msg.innerHTML;
|
2020-06-08 19:34:20 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
content.handler = function () {
|
|
|
|
|
common.openURL('/settings/#security');
|
|
|
|
|
};
|
|
|
|
|
if (!content.archived) {
|
|
|
|
|
content.dismissHandler = defaultDismiss(common, data);
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-09-20 13:27:20 +00:00
|
|
|
|
|
2021-03-09 17:27:12 +00:00
|
|
|
|
handlers['BROADCAST_SURVEY'] = function (common, data) {
|
|
|
|
|
var content = data.content;
|
|
|
|
|
var msg = content.msg.content;
|
|
|
|
|
content.getFormatText = function () {
|
|
|
|
|
return Messages.broadcast_newSurvey;
|
|
|
|
|
};
|
|
|
|
|
content.handler = function () {
|
|
|
|
|
common.openUnsafeURL(msg.url);
|
2021-04-08 13:46:24 +00:00
|
|
|
|
defaultDismiss(common, data)();
|
2021-03-09 17:27:12 +00:00
|
|
|
|
};
|
|
|
|
|
if (!content.archived) {
|
|
|
|
|
content.dismissHandler = defaultDismiss(common, data);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
handlers['BROADCAST_CUSTOM'] = function (common, data) {
|
|
|
|
|
var content = data.content;
|
|
|
|
|
var msg = content.msg.content;
|
|
|
|
|
var text = msg.content;
|
|
|
|
|
var defaultL = msg.defaultLanguage;
|
2021-03-10 12:02:36 +00:00
|
|
|
|
var myLang = data.lang || Messages._languageUsed;
|
2021-03-09 17:27:12 +00:00
|
|
|
|
// Check if our language is available
|
2021-03-10 12:02:36 +00:00
|
|
|
|
var toShow = text[myLang];
|
2021-03-09 17:27:12 +00:00
|
|
|
|
// Otherwise, fallback to the default language if it exists
|
|
|
|
|
if (!toShow && defaultL) { toShow = text[defaultL]; }
|
|
|
|
|
// No translation available, dismiss
|
2021-03-12 11:46:11 +00:00
|
|
|
|
if (!toShow) { return defaultDismiss(common, data)(); }
|
2021-03-09 17:27:12 +00:00
|
|
|
|
|
2021-03-12 16:29:17 +00:00
|
|
|
|
var slice = toShow.length > 200;
|
2021-03-09 17:27:12 +00:00
|
|
|
|
toShow = Util.fixHTML(toShow);
|
|
|
|
|
|
|
|
|
|
content.getFormatText = function () {
|
|
|
|
|
if (slice) {
|
2021-03-12 16:29:17 +00:00
|
|
|
|
return toShow.slice(0, 200) + '...';
|
2021-03-09 17:27:12 +00:00
|
|
|
|
}
|
|
|
|
|
return toShow;
|
|
|
|
|
};
|
|
|
|
|
if (slice) {
|
|
|
|
|
content.handler = function () {
|
|
|
|
|
var content = h('div', [
|
|
|
|
|
h('h4', Messages.broadcast_newCustom),
|
2021-03-16 10:51:28 +00:00
|
|
|
|
h('div.cp-admin-message', toShow)
|
2021-03-09 17:27:12 +00:00
|
|
|
|
]);
|
|
|
|
|
UI.alert(content);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
if (!content.archived) {
|
|
|
|
|
content.dismissHandler = defaultDismiss(common, data);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-12 15:08:18 +00:00
|
|
|
|
Messages.reminder_missed = "You missed <b>{0}</b> on {1}"; // XXX
|
2021-04-12 15:55:56 +00:00
|
|
|
|
Messages.reminder_now = "<b>{0}</b> is starting!"; // XXX
|
2021-04-12 15:08:18 +00:00
|
|
|
|
Messages.reminder_inProgress = "<b>{0}</b> has started on {1}"; // XXX
|
|
|
|
|
Messages.reminder_inProgressAllDay = "<b>{0}</b> is happening today"; // XXX
|
2021-04-09 16:10:13 +00:00
|
|
|
|
Messages.reminder_minutes = "<b>{0}</b> will start in {1} minutes!"; // XXX
|
2021-04-12 15:55:56 +00:00
|
|
|
|
Messages.reminder_time = "<b>{0}</b> will start today at {1}!"; // XXX
|
|
|
|
|
Messages.reminder_date = "<b>{0}</b> will start on {1}!"; // XXX
|
2021-04-09 16:10:13 +00:00
|
|
|
|
handlers['REMINDER'] = function (common, data) {
|
|
|
|
|
var content = data.content;
|
|
|
|
|
var msg = content.msg.content;
|
2021-04-12 15:08:18 +00:00
|
|
|
|
var missed = content.msg.missed;
|
2021-04-09 16:10:13 +00:00
|
|
|
|
var start = msg.start;
|
2021-04-12 15:08:18 +00:00
|
|
|
|
var title = Util.fixHTML(msg.title);
|
2021-04-09 16:10:13 +00:00
|
|
|
|
content.getFormatText = function () {
|
2021-04-12 15:55:56 +00:00
|
|
|
|
var now = +new Date();
|
|
|
|
|
|
|
|
|
|
// Events that have already started
|
|
|
|
|
var wasRefresh = content.autorefresh;
|
|
|
|
|
content.autorefresh = false;
|
|
|
|
|
|
2021-04-13 08:35:22 +00:00
|
|
|
|
var nowDateStr = new Date().toLocaleDateString();
|
|
|
|
|
var startDate = new Date(start);
|
2021-04-13 14:54:46 +00:00
|
|
|
|
if (msg.isAllDay && msg.startDay) {
|
|
|
|
|
startDate = new Date(msg.startDay);
|
|
|
|
|
}
|
2021-04-13 08:35:22 +00:00
|
|
|
|
|
2021-04-12 15:08:18 +00:00
|
|
|
|
// Missed events
|
|
|
|
|
if (start < now && missed) {
|
2021-04-13 08:35:22 +00:00
|
|
|
|
return Messages._getKey('reminder_missed', [title, startDate.toLocaleString()]);
|
2021-04-12 15:08:18 +00:00
|
|
|
|
}
|
2021-04-12 15:55:56 +00:00
|
|
|
|
// Starting now
|
|
|
|
|
if (start < now && wasRefresh) {
|
|
|
|
|
return Messages._getKey('reminder_now', [title]);
|
|
|
|
|
}
|
2021-04-12 15:08:18 +00:00
|
|
|
|
// In progress, is all day
|
|
|
|
|
if (start < now && msg.isAllDay) {
|
|
|
|
|
return Messages._getKey('reminder_inProgressAllDay', [title]);
|
|
|
|
|
}
|
|
|
|
|
// In progress, normal event
|
|
|
|
|
if (start < now) {
|
2021-04-13 08:35:22 +00:00
|
|
|
|
return Messages._getKey('reminder_inProgress', [title, startDate.toLocaleString()]);
|
2021-04-12 15:08:18 +00:00
|
|
|
|
}
|
2021-04-12 15:55:56 +00:00
|
|
|
|
|
2021-04-12 15:08:18 +00:00
|
|
|
|
// Not started yet
|
2021-04-12 15:55:56 +00:00
|
|
|
|
|
2021-04-13 14:54:46 +00:00
|
|
|
|
// No precise time for allDay events
|
|
|
|
|
if (msg.isAllDay) {
|
|
|
|
|
return Messages._getKey('reminder_date', [title, startDate.toLocaleDateString()]);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-12 15:55:56 +00:00
|
|
|
|
// In less than an hour: show countdown in minutes
|
|
|
|
|
if ((start - now) < 3600000) {
|
|
|
|
|
var minutes = Math.round((start - now) / 60000);
|
|
|
|
|
content.autorefresh = true;
|
|
|
|
|
return Messages._getKey('reminder_minutes', [title, minutes]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Not today: show full date
|
|
|
|
|
if (nowDateStr !== startDate.toLocaleDateString()) {
|
|
|
|
|
return Messages._getKey('reminder_date', [title, startDate.toLocaleString()]);
|
2021-04-09 16:10:13 +00:00
|
|
|
|
}
|
2021-04-12 15:55:56 +00:00
|
|
|
|
|
|
|
|
|
// Today: show time
|
|
|
|
|
return Messages._getKey('reminder_time', [title, startDate.toLocaleTimeString()]);
|
2021-04-09 16:10:13 +00:00
|
|
|
|
};
|
|
|
|
|
if (!content.archived) {
|
|
|
|
|
content.dismissHandler = defaultDismiss(common, data);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-27 10:03:25 +00:00
|
|
|
|
// NOTE: don't forget to fixHTML everything returned by "getFormatText"
|
|
|
|
|
|
2019-05-22 16:03:52 +00:00
|
|
|
|
return {
|
2020-05-05 09:19:32 +00:00
|
|
|
|
add: function(common, data) {
|
2019-05-22 16:03:52 +00:00
|
|
|
|
var type = data.content.msg.type;
|
|
|
|
|
|
|
|
|
|
if (handlers[type]) {
|
2019-06-27 07:51:23 +00:00
|
|
|
|
handlers[type](common, data);
|
|
|
|
|
// add getters to access simply some informations
|
2019-07-01 11:52:17 +00:00
|
|
|
|
data.content.isClickable = typeof data.content.handler === "function";
|
|
|
|
|
data.content.isDismissible = typeof data.content.dismissHandler === "function";
|
2019-09-03 15:31:06 +00:00
|
|
|
|
} else {
|
|
|
|
|
data.content.dismissHandler = defaultDismiss(common, data);
|
|
|
|
|
data.content.isDismissible = typeof data.content.dismissHandler === "function";
|
2019-05-22 16:03:52 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2020-05-05 09:19:32 +00:00
|
|
|
|
remove: function(common, data) {
|
2019-05-22 16:03:52 +00:00
|
|
|
|
common.removeFriendRequest(data.hash);
|
|
|
|
|
},
|
2019-09-03 15:58:56 +00:00
|
|
|
|
allowed: Object.keys(handlers)
|
2019-05-22 16:03:52 +00:00
|
|
|
|
};
|
2020-05-15 13:27:55 +00:00
|
|
|
|
});
|