summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authortamaina <tamaina@hotmail.co.jp>2021-12-25 02:01:35 +0900
committerGitHub <noreply@github.com>2021-12-25 02:01:35 +0900
commitc77fe1f2cf5da7c111e9008d869c702644075d44 (patch)
treeafa6df1d25051465429848ac01ed5452bdf3fa9a /packages
parentfix(client): ドロワーメニューでセーフエリアを考慮するよ... (diff)
downloadmisskey-c77fe1f2cf5da7c111e9008d869c702644075d44.tar.gz
misskey-c77fe1f2cf5da7c111e9008d869c702644075d44.tar.bz2
misskey-c77fe1f2cf5da7c111e9008d869c702644075d44.zip
Truncate push notification message (#8089)
* Truncate push notification message * fix
Diffstat (limited to 'packages')
-rw-r--r--packages/backend/src/services/push-notification.ts27
-rw-r--r--packages/client/src/sw/compose-notification.ts13
2 files changed, 32 insertions, 8 deletions
diff --git a/packages/backend/src/services/push-notification.ts b/packages/backend/src/services/push-notification.ts
index 616bc74411..2133768a96 100644
--- a/packages/backend/src/services/push-notification.ts
+++ b/packages/backend/src/services/push-notification.ts
@@ -3,10 +3,33 @@ import config from '@/config/index';
import { SwSubscriptions } from '@/models/index';
import { fetchMeta } from '@/misc/fetch-meta';
import { Packed } from '@/misc/schema';
+import { getNoteSummary } from '@/misc/get-note-summary';
type notificationType = 'notification' | 'unreadMessagingMessage';
type notificationBody = Packed<'Notification'> | Packed<'MessagingMessage'>;
+// プッシュメッセージサーバーには文字数制限があるため、内容を削減します
+function truncateNotification(notification: Packed<'Notification'>): any {
+ if (notification.note) {
+ return {
+ ...notification,
+ note: {
+ ...notification.note,
+ // textをgetNoteSummaryしたものに置き換える
+ text: getNoteSummary(notification.type === 'renote' ? notification.note.renote as Packed<'Note'> : notification.note),
+ ...{
+ cw: undefined,
+ reply: undefined,
+ renote: undefined,
+ user: undefined as any, // 通知を受け取ったユーザーである場合が多いのでこれも捨てる
+ }
+ }
+ };
+ }
+
+ return notification;
+}
+
export default async function(userId: string, type: notificationType, body: notificationBody) {
const meta = await fetchMeta();
@@ -32,7 +55,9 @@ export default async function(userId: string, type: notificationType, body: noti
};
push.sendNotification(pushSubscription, JSON.stringify({
- type, body,
+ type,
+ body: type === 'notification' ? truncateNotification(body as Packed<'Notification'>) : body,
+ userId,
}), {
proxy: config.proxy,
}).catch((err: any) => {
diff --git a/packages/client/src/sw/compose-notification.ts b/packages/client/src/sw/compose-notification.ts
index 0aed9610ea..10bd27c9ec 100644
--- a/packages/client/src/sw/compose-notification.ts
+++ b/packages/client/src/sw/compose-notification.ts
@@ -3,7 +3,6 @@
*/
declare var self: ServiceWorkerGlobalScope;
-import { getNoteSummary } from '@/scripts/get-note-summary';
import * as misskey from 'misskey-js';
function getUserName(user: misskey.entities.User): string {
@@ -26,37 +25,37 @@ export default async function(type, data, i18n): Promise<[string, NotificationOp
switch (data.type) {
case 'mention':
return [i18n.t('_notification.youGotMention', { name: getUserName(data.user) }), {
- body: getNoteSummary(data.note, i18n.locale),
+ body: data.note.text,
icon: data.user.avatarUrl
}];
case 'reply':
return [i18n.t('_notification.youGotReply', { name: getUserName(data.user) }), {
- body: getNoteSummary(data.note, i18n.locale),
+ body: data.note.text,
icon: data.user.avatarUrl
}];
case 'renote':
return [i18n.t('_notification.youRenoted', { name: getUserName(data.user) }), {
- body: getNoteSummary(data.note, i18n.locale),
+ body: data.note.text,
icon: data.user.avatarUrl
}];
case 'quote':
return [i18n.t('_notification.youGotQuote', { name: getUserName(data.user) }), {
- body: getNoteSummary(data.note, i18n.locale),
+ body: data.note.text,
icon: data.user.avatarUrl
}];
case 'reaction':
return [`${data.reaction} ${getUserName(data.user)}`, {
- body: getNoteSummary(data.note, i18n.locale),
+ body: data.note.text,
icon: data.user.avatarUrl
}];
case 'pollVote':
return [i18n.t('_notification.youGotPoll', { name: getUserName(data.user) }), {
- body: getNoteSummary(data.note, i18n.locale),
+ body: data.note.text,
icon: data.user.avatarUrl
}];