1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
import getNoteSummary from '../../misc/get-note-summary';
import getUserName from '../../misc/get-user-name';
import { clientDb, get, bulkGet } from '../db';
import { fromEntries } from '../../prelude/array';
const getTranslation = (text: string): Promise<string> => get(text, clientDb.i18n);
export default async function(type, data): Promise<[string, NotificationOptions]> {
const contexts = ['deletedNote', 'invisibleNote', 'withNFiles', '_cw.poll'];
const locale = fromEntries(await bulkGet(contexts, clientDb.i18n) as [string, string][]);
switch (type) {
case 'driveFileCreated': // TODO (Server Side)
return [await getTranslation('_notification.fileUploaded'), {
body: data.name,
icon: data.url
}];
case 'notification':
switch (data.type) {
case 'mention':
return [(await getTranslation('_notification.youGotMention')).replace('{name}', getUserName(data.user)), {
body: getNoteSummary(data.note, locale),
icon: data.user.avatarUrl
}];
case 'reply':
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),
icon: data.user.avatarUrl
}];
case 'quote':
return [(await getTranslation('_notification.youGotQuote')).replace('{name}', getUserName(data.user)), {
body: getNoteSummary(data.note, locale),
icon: data.user.avatarUrl
}];
case 'reaction':
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),
icon: data.user.avatarUrl
}];
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
}];
default:
return null;
}
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}`
}];
default:
return null;
}
}
|