diff --git a/public/firebase-messaging-sw.js b/public/firebase-messaging-sw.js index b276d23..c9fa41f 100644 --- a/public/firebase-messaging-sw.js +++ b/public/firebase-messaging-sw.js @@ -17,8 +17,8 @@ self.addEventListener("push", (/** @type {PushEvent} */ event) => { requireInteraction: true, body: notification.body, badge: notification.badge ?? "/icons/outline-badge-icon.png", + image: notification.image, icon: notification.icon ?? "/icon.png", - actions: notification.actions ?? actions[data.type], data: { ...data, ...(notification.click_action && { @@ -32,8 +32,6 @@ self.addEventListener("push", (/** @type {PushEvent} */ event) => { self.addEventListener( "notificationclick", async function (/** @type {NotificationEvent} */ event) { - /** @type {import ('../src/interfaces/push/push-action').NotificationAction['action']} */ - const action = event.action /** @type {import ("../src/interfaces/push/push-notification").AppPushNotification} */ const notification = event.notification /** @type {import ("../src/interfaces/push/push-notification").AppNotificationClickData} */ @@ -43,13 +41,11 @@ self.addEventListener( const worker = event.currentTarget if (data.type === "answer") { - if (action === "answer:close") return + notification.close() const linkUrl = data.click_action ?? `https://kernelsquare.live/question/${data.postId}` - notification.close() - event.waitUntil(worker.clients.openWindow(linkUrl)) } }, diff --git a/src/app/api/send-fcm/route.ts b/src/app/api/send-fcm/route.ts index b84632e..b713c72 100644 --- a/src/app/api/send-fcm/route.ts +++ b/src/app/api/send-fcm/route.ts @@ -43,7 +43,7 @@ export async function POST(request: NextRequest) { const notification = payload.notification if (type === "answer" && isAppNotificationPayload("answer", notification)) { - const { data, ...notificationPayload } = notification + const { data, icon, ...notificationPayload } = notification const { postId, questionAuthorId } = data @@ -78,17 +78,7 @@ export async function POST(request: NextRequest) { badge: process.env.NEXT_PUBLIC_SITE_URL + "/icons/outline-badge-icon.png", - icon: process.env.NEXT_PUBLIC_SITE_URL + "/icon.png", - actions: [ - { - action: "answer:view", - title: "글 보기", - }, - { - action: "answer:close", - title: "알림 닫기", - }, - ], + icon: icon ?? `${process.env.NEXT_PUBLIC_SITE_URL}/icon.png`, }, fcmOptions: { link: `${process.env.NEXT_PUBLIC_SITE_URL}/question/${postId}`, diff --git a/src/interfaces/dto/fcm/send-fcm.dto.ts b/src/interfaces/dto/fcm/send-fcm.dto.ts index 32cc30f..3409205 100644 --- a/src/interfaces/dto/fcm/send-fcm.dto.ts +++ b/src/interfaces/dto/fcm/send-fcm.dto.ts @@ -12,6 +12,7 @@ export type FcmNotification = { title: string body: string imageUrl?: string + icon?: string data: FcmNotificationData } diff --git a/src/interfaces/push/push-action.ts b/src/interfaces/push/push-action.ts deleted file mode 100644 index 5846c12..0000000 --- a/src/interfaces/push/push-action.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { NotificationType } from "./push-type" - -export interface NotificationAction { - action: NotificationType - title: string -} - -export type NotificationActions = NotificationAction[] diff --git a/src/interfaces/push/push-notification.ts b/src/interfaces/push/push-notification.ts index b580d60..ece01a2 100644 --- a/src/interfaces/push/push-notification.ts +++ b/src/interfaces/push/push-notification.ts @@ -1,18 +1,18 @@ import { FcmNotificationData, NotificationType } from "../dto/fcm/send-fcm.dto" -import { NotificationActions } from "./push-action" export interface AppPushNotification extends Notification { + image?: string click_action?: string - actions?: NotificationActions } export type AppPushNotificationData = Omit< FcmNotificationData<"answer">, "questionAuthorId" -> +> & { + type: NotificationType +} export type AppNotificationClickData = AppPushNotificationData & { - type: NotificationType click_action?: string } diff --git a/src/interfaces/push/push-type.ts b/src/interfaces/push/push-type.ts deleted file mode 100644 index 144388b..0000000 --- a/src/interfaces/push/push-type.ts +++ /dev/null @@ -1,3 +0,0 @@ -type NotificationAnswerType = "answer:view" | "answer:close" - -export type NotificationType = NotificationAnswerType diff --git a/src/page/qna-detail/components/Answers/form/CreateAnswerForm.tsx b/src/page/qna-detail/components/Answers/form/CreateAnswerForm.tsx index a2d3caf..35f933c 100644 --- a/src/page/qna-detail/components/Answers/form/CreateAnswerForm.tsx +++ b/src/page/qna-detail/components/Answers/form/CreateAnswerForm.tsx @@ -49,6 +49,7 @@ function CreateAnswerForm({ question }: CreateAnswerFormProps) { postId: `${question.id}`, questionAuthorId: `${question.member_id}`, }, + ...(user?.image_url && { icon: user.image_url }), }) setTimeout(() => {