Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions public/firebase-messaging-sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 && {
Expand All @@ -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} */
Expand All @@ -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))
}
},
Expand Down
14 changes: 2 additions & 12 deletions src/app/api/send-fcm/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}`,
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/dto/fcm/send-fcm.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type FcmNotification<TData extends NotificationType> = {
title: string
body: string
imageUrl?: string
icon?: string
data: FcmNotificationData<TData>
}

Expand Down
8 changes: 0 additions & 8 deletions src/interfaces/push/push-action.ts

This file was deleted.

8 changes: 4 additions & 4 deletions src/interfaces/push/push-notification.ts
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down
3 changes: 0 additions & 3 deletions src/interfaces/push/push-type.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function CreateAnswerForm({ question }: CreateAnswerFormProps) {
postId: `${question.id}`,
questionAuthorId: `${question.member_id}`,
},
...(user?.image_url && { icon: user.image_url }),
})

setTimeout(() => {
Expand Down