summaryrefslogtreecommitdiff
path: root/packages/backend/src
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-12-25 13:38:55 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2021-12-25 13:38:55 +0900
commit322b64c0b4e1b4ecf47d168a48b259695c7ca36f (patch)
treea4562381422cb5bc84ab9e5aad82779b4f387a08 /packages/backend/src
parentclean up (diff)
parentTruncate push notification message (#8089) (diff)
downloadmisskey-322b64c0b4e1b4ecf47d168a48b259695c7ca36f.tar.gz
misskey-322b64c0b4e1b4ecf47d168a48b259695c7ca36f.tar.bz2
misskey-322b64c0b4e1b4ecf47d168a48b259695c7ca36f.zip
Merge branch 'develop' of https://github.com/misskey-dev/misskey into develop
Diffstat (limited to 'packages/backend/src')
-rw-r--r--packages/backend/src/services/push-notification.ts27
1 files changed, 26 insertions, 1 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) => {