@@ -32,6 +32,7 @@ import { createMessage, ServerMessageKind } from "../ws/protocol"
32
32
import { MessageAttachmentExternalTask_Status , type Update } from "@in/protocol/core"
33
33
import { RealtimeUpdates } from "../realtime/message"
34
34
import { examples , prompt } from "../libs/linear/prompt"
35
+ import { Notifications } from "../modules/notifications/notifications"
35
36
36
37
type Context = {
37
38
currentUserId : number
@@ -42,6 +43,7 @@ export const Input = Type.Object({
42
43
messageId : Type . Number ( ) ,
43
44
chatId : Type . Number ( ) ,
44
45
peerId : TInputPeerInfo ,
46
+ fromId : Type . Number ( ) ,
45
47
} )
46
48
47
49
export const Response = Type . Object ( {
@@ -52,7 +54,7 @@ export const handler = async (
52
54
input : Static < typeof Input > ,
53
55
{ currentUserId } : Context ,
54
56
) : Promise < Static < typeof Response > > => {
55
- let { text, messageId, peerId, chatId } = input
57
+ let { text, messageId, peerId, chatId, fromId } = input
56
58
57
59
const [ labels , [ user ] , linearUsers ] = await Promise . all ( [
58
60
getLinearIssueLabels ( { userId : currentUserId } ) ,
@@ -152,6 +154,18 @@ export const handler = async (
152
154
}
153
155
}
154
156
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
+ }
155
169
return { link : result ?. link }
156
170
} catch ( error ) {
157
171
Log . shared . error ( "Failed to create issue" , { error } )
@@ -350,3 +364,29 @@ function parseResponse(msg: any): any {
350
364
const jsonResponse = JSON . parse ( jsonString )
351
365
return jsonResponse
352
366
}
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