summaryrefslogtreecommitdiff
path: root/src/client/app/common/scripts/compose-notification.ts
blob: 47499e54907e72c5985fe2fe7bb4288a5fb7135a (plain)
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
import getNoteSummary from '../../../../misc/get-note-summary';
import getReactionEmoji from '../../../../misc/get-reaction-emoji';
import getUserName from '../../../../misc/get-user-name';

type Notification = {
	title: string;
	body: string;
	icon: string;
	onclick?: any;
};

// TODO: i18n

export default function(type, data): Notification {
	switch (type) {
		case 'drive_file_created':
			return {
				title: 'ファイルがアップロードされました',
				body: data.name,
				icon: data.url + '?thumbnail&size=64'
			};

		case 'unread_messaging_message':
			return {
				title: `${getUserName(data.user)}さんからメッセージ:`,
				body: data.text, // TODO: getMessagingMessageSummary(data),
				icon: data.user.avatarUrl + '?thumbnail&size=64'
			};

		case 'reversi_invited':
			return {
				title: '対局への招待があります',
				body: `${getUserName(data.parent)}さんから`,
				icon: data.parent.avatarUrl + '?thumbnail&size=64'
			};

		case 'notification':
			switch (data.type) {
				case 'mention':
					return {
						title: `${getUserName(data.user)}さんから:`,
						body: getNoteSummary(data),
						icon: data.user.avatarUrl + '?thumbnail&size=64'
					};

				case 'reply':
					return {
						title: `${getUserName(data.user)}さんから返信:`,
						body: getNoteSummary(data),
						icon: data.user.avatarUrl + '?thumbnail&size=64'
					};

				case 'quote':
					return {
						title: `${getUserName(data.user)}さんが引用:`,
						body: getNoteSummary(data),
						icon: data.user.avatarUrl + '?thumbnail&size=64'
					};

				case 'reaction':
					return {
						title: `${getUserName(data.user)}: ${getReactionEmoji(data.reaction)}:`,
						body: getNoteSummary(data.note),
						icon: data.user.avatarUrl + '?thumbnail&size=64'
					};

				default:
					return null;
			}

		default:
			return null;
	}
}