egirlskey/src/client/app/common/scripts/compose-notification.ts

75 lines
1.6 KiB
TypeScript
Raw Normal View History

2018-07-07 10:19:00 +00:00
import getNoteSummary from '../../../../misc/get-note-summary';
import getReactionEmoji from '../../../../misc/get-reaction-emoji';
import getUserName from '../../../../misc/get-user-name';
2017-11-20 20:09:45 +00:00
type Notification = {
title: string;
body: string;
icon: string;
onclick?: any;
};
// TODO: i18n
export default function(type, data): Notification {
switch (type) {
case 'driveFileCreated':
2017-11-20 20:09:45 +00:00
return {
2019-02-28 11:57:38 +00:00
title: 'File uploaded',
2017-11-20 20:09:45 +00:00
body: data.name,
2018-07-24 14:43:14 +00:00
icon: data.url
2017-11-20 20:09:45 +00:00
};
case 'unreadMessagingMessage':
2017-11-20 20:09:45 +00:00
return {
2019-02-28 11:57:38 +00:00
title: `New message from ${getUserName(data.user)}`,
2017-11-20 20:09:45 +00:00
body: data.text, // TODO: getMessagingMessageSummary(data),
2018-07-24 14:43:14 +00:00
icon: data.user.avatarUrl
2017-11-20 20:09:45 +00:00
};
case 'reversiInvited':
2018-03-17 08:53:35 +00:00
return {
2019-02-28 11:57:38 +00:00
title: 'Play reversi with me',
body: `You got reversi invitation from ${getUserName(data.parent)}`,
2018-07-24 14:43:14 +00:00
icon: data.parent.avatarUrl
2018-03-17 08:53:35 +00:00
};
2018-06-21 02:35:28 +00:00
case 'notification':
switch (data.type) {
case 'mention':
return {
2019-02-28 11:57:38 +00:00
title: `${getUserName(data.user)}:`,
2018-06-21 02:35:28 +00:00
body: getNoteSummary(data),
2018-07-24 14:43:14 +00:00
icon: data.user.avatarUrl
2018-06-21 02:35:28 +00:00
};
case 'reply':
return {
2019-02-28 11:57:38 +00:00
title: `You got reply from ${getUserName(data.user)}:`,
2018-06-21 02:35:28 +00:00
body: getNoteSummary(data),
2018-07-24 14:43:14 +00:00
icon: data.user.avatarUrl
2018-06-21 02:35:28 +00:00
};
case 'quote':
return {
2019-02-28 11:57:38 +00:00
title: `${getUserName(data.user)}:`,
2018-06-21 02:35:28 +00:00
body: getNoteSummary(data),
2018-07-24 14:43:14 +00:00
icon: data.user.avatarUrl
2018-06-21 02:35:28 +00:00
};
case 'reaction':
return {
title: `${getUserName(data.user)}: ${getReactionEmoji(data.reaction)}:`,
body: getNoteSummary(data.note),
2018-07-24 14:43:14 +00:00
icon: data.user.avatarUrl
2018-06-21 02:35:28 +00:00
};
default:
return null;
}
2017-11-20 20:09:45 +00:00
default:
return null;
}
}