2020-01-29 13:37:25 -06:00
|
|
|
import getNoteSummary from '../../misc/get-note-summary';
|
|
|
|
import getUserName from '../../misc/get-user-name';
|
2020-05-22 23:19:31 -05:00
|
|
|
import { clientDb, get, bulkGet } from '../db';
|
2017-11-20 14:09:45 -06:00
|
|
|
|
2020-05-22 23:19:31 -05:00
|
|
|
const getTranslation = (text: string): Promise<string> => get(text, clientDb.i18n);
|
2017-11-20 14:09:45 -06:00
|
|
|
|
2020-05-22 23:19:31 -05:00
|
|
|
export default async function(type, data): Promise<[string, NotificationOptions]> {
|
2020-06-02 23:30:17 -05:00
|
|
|
const contexts = ['deletedNote', 'invisibleNote', 'withNFiles', 'poll'];
|
2020-05-23 09:21:09 -05:00
|
|
|
const locale = Object.fromEntries(await bulkGet(contexts, clientDb.i18n) as [string, string][]);
|
2017-11-20 14:09:45 -06:00
|
|
|
|
|
|
|
switch (type) {
|
2020-05-22 23:19:31 -05:00
|
|
|
case 'driveFileCreated': // TODO (Server Side)
|
|
|
|
return [await getTranslation('_notification.fileUploaded'), {
|
2017-11-20 14:09:45 -06:00
|
|
|
body: data.name,
|
2018-07-24 09:43:14 -05:00
|
|
|
icon: data.url
|
2020-05-22 23:19:31 -05:00
|
|
|
}];
|
2018-06-20 21:35:28 -05:00
|
|
|
case 'notification':
|
|
|
|
switch (data.type) {
|
|
|
|
case 'mention':
|
2020-05-22 23:19:31 -05:00
|
|
|
return [(await getTranslation('_notification.youGotMention')).replace('{name}', getUserName(data.user)), {
|
|
|
|
body: getNoteSummary(data.note, locale),
|
2018-07-24 09:43:14 -05:00
|
|
|
icon: data.user.avatarUrl
|
2020-05-22 23:19:31 -05:00
|
|
|
}];
|
2018-06-20 21:35:28 -05:00
|
|
|
|
|
|
|
case 'reply':
|
2020-05-22 23:19:31 -05:00
|
|
|
return [(await getTranslation('_notification.youGotReply')).replace('{name}', getUserName(data.user)), {
|
|
|
|
body: getNoteSummary(data.note, locale),
|
|
|
|
icon: data.user.avatarUrl
|
|
|
|
}];
|
|
|
|
|
|
|
|
case 'renote':
|
|
|
|
return [(await getTranslation('_notification.youRenoted')).replace('{name}', getUserName(data.user)), {
|
|
|
|
body: getNoteSummary(data.note, locale),
|
2018-07-24 09:43:14 -05:00
|
|
|
icon: data.user.avatarUrl
|
2020-05-22 23:19:31 -05:00
|
|
|
}];
|
2018-06-20 21:35:28 -05:00
|
|
|
|
|
|
|
case 'quote':
|
2020-05-22 23:19:31 -05:00
|
|
|
return [(await getTranslation('_notification.youGotQuote')).replace('{name}', getUserName(data.user)), {
|
|
|
|
body: getNoteSummary(data.note, locale),
|
2018-07-24 09:43:14 -05:00
|
|
|
icon: data.user.avatarUrl
|
2020-05-22 23:19:31 -05:00
|
|
|
}];
|
2018-06-20 21:35:28 -05:00
|
|
|
|
|
|
|
case 'reaction':
|
2020-05-22 23:19:31 -05:00
|
|
|
return [`${data.reaction} ${getUserName(data.user)}`, {
|
|
|
|
body: getNoteSummary(data.note, locale),
|
|
|
|
icon: data.user.avatarUrl
|
|
|
|
}];
|
|
|
|
|
|
|
|
case 'pollVote':
|
|
|
|
return [(await getTranslation('_notification.youGotPoll')).replace('{name}', getUserName(data.user)), {
|
|
|
|
body: getNoteSummary(data.note, locale),
|
|
|
|
icon: data.user.avatarUrl
|
|
|
|
}];
|
|
|
|
|
|
|
|
case 'follow':
|
|
|
|
return [await getTranslation('_notification.youWereFollowed'), {
|
|
|
|
body: getUserName(data.user),
|
2018-07-24 09:43:14 -05:00
|
|
|
icon: data.user.avatarUrl
|
2020-05-22 23:19:31 -05:00
|
|
|
}];
|
|
|
|
|
|
|
|
case 'receiveFollowRequest':
|
|
|
|
return [await getTranslation('_notification.youReceivedFollowRequest'), {
|
|
|
|
body: getUserName(data.user),
|
|
|
|
icon: data.user.avatarUrl
|
|
|
|
}];
|
|
|
|
|
|
|
|
case 'followRequestAccepted':
|
|
|
|
return [await getTranslation('_notification.yourFollowRequestAccepted'), {
|
|
|
|
body: getUserName(data.user),
|
|
|
|
icon: data.user.avatarUrl
|
|
|
|
}];
|
|
|
|
|
|
|
|
case 'groupInvited':
|
|
|
|
return [await getTranslation('_notification.youWereInvitedToGroup'), {
|
|
|
|
body: data.group.name
|
|
|
|
}];
|
2018-06-20 21:35:28 -05:00
|
|
|
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
2020-05-22 23:19:31 -05:00
|
|
|
case 'unreadMessagingMessage':
|
|
|
|
if (data.groupId === null) {
|
|
|
|
return [(await getTranslation('_notification.youGotMessagingMessageFromUser')).replace('{name}', getUserName(data.user)), {
|
|
|
|
icon: data.user.avatarUrl,
|
|
|
|
tag: `messaging:user:${data.user.id}`
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
return [(await getTranslation('_notification.youGotMessagingMessageFromGroup')).replace('{name}', data.group.name), {
|
|
|
|
icon: data.user.avatarUrl,
|
|
|
|
tag: `messaging:group:${data.group.id}`
|
|
|
|
}];
|
2017-11-20 14:09:45 -06:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|