Skip to content

Commit 48562ff

Browse files
committed
Send notification on will do
1 parent ec5f159 commit 48562ff

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

server/src/methods/createLinearIssue.ts

+41-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { createMessage, ServerMessageKind } from "../ws/protocol"
3232
import { MessageAttachmentExternalTask_Status, type Update } from "@in/protocol/core"
3333
import { RealtimeUpdates } from "../realtime/message"
3434
import { examples, prompt } from "../libs/linear/prompt"
35+
import { Notifications } from "../modules/notifications/notifications"
3536

3637
type Context = {
3738
currentUserId: number
@@ -42,6 +43,7 @@ export const Input = Type.Object({
4243
messageId: Type.Number(),
4344
chatId: Type.Number(),
4445
peerId: TInputPeerInfo,
46+
fromId: Type.Number(),
4547
})
4648

4749
export const Response = Type.Object({
@@ -52,7 +54,7 @@ export const handler = async (
5254
input: Static<typeof Input>,
5355
{ currentUserId }: Context,
5456
): Promise<Static<typeof Response>> => {
55-
let { text, messageId, peerId, chatId } = input
57+
let { text, messageId, peerId, chatId, fromId } = input
5658

5759
const [labels, [user], linearUsers] = await Promise.all([
5860
getLinearIssueLabels({ userId: currentUserId }),
@@ -152,6 +154,18 @@ export const handler = async (
152154
}
153155
}
154156

157+
let [senderUser] = await db.select().from(users).where(eq(users.id, fromId))
158+
159+
if (senderUser && fromId !== currentUserId) {
160+
console.log("sending notification to user", fromId)
161+
sendNotificationToUser({
162+
userId: fromId,
163+
userName: senderUser.firstName ?? "User",
164+
issueTitle: response.title,
165+
currentUserId,
166+
chatId,
167+
})
168+
}
155169
return { link: result?.link }
156170
} catch (error) {
157171
Log.shared.error("Failed to create issue", { error })
@@ -350,3 +364,29 @@ function parseResponse(msg: any): any {
350364
const jsonResponse = JSON.parse(jsonString)
351365
return jsonResponse
352366
}
367+
368+
/** Send push notifications for this message */
369+
async function sendNotificationToUser({
370+
userId,
371+
userName,
372+
issueTitle,
373+
currentUserId,
374+
chatId,
375+
}: {
376+
userId: number
377+
userName: string
378+
issueTitle: string
379+
currentUserId: number
380+
chatId: number
381+
}) {
382+
const title = `${userName} marked as will do`
383+
let body = `"${issueTitle}"`
384+
385+
Notifications.sendToUser({
386+
userId,
387+
senderUserId: currentUserId,
388+
threadId: `chat_${chatId}`,
389+
title,
390+
body,
391+
})
392+
}

0 commit comments

Comments
 (0)