Skip to content

Commit 406b84d

Browse files
committed
improvements to notification system
1 parent fbdac70 commit 406b84d

1 file changed

Lines changed: 41 additions & 13 deletions

File tree

notifications/notification_manager.go

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ func readJetstreamMessages(ws *websocket.Conn, incomingMessages chan JetstreamPo
307307
// 3. Converting the text into a twitter post
308308
// 4. Send the twitter post's content as a push notification via SGN.
309309
func sendPushNotificationForPost(did string, typeOfNotification string, didOfPoster string, rkey string, indexed_at *int64) {
310+
notifiedUser, err := blueskyapi.GetUserInfoRaw("https://public.api.bsky.app", "", did)
311+
if err != nil {
312+
return
313+
}
314+
310315
notificationBody := map[string]interface{}{}
311316
// GetPost
312317

@@ -335,9 +340,13 @@ func sendPushNotificationForPost(did string, typeOfNotification string, didOfPos
335340
// our body
336341
notificationBody = map[string]interface{}{
337342
"aps": map[string]interface{}{
338-
"alert": fmt.Sprintf("Mentioned by @%s: %s", tweet.User.ScreenName, tweet.Text),
343+
"alert": map[string]interface{}{
344+
"body": fmt.Sprintf("Mentioned by @%s: %s", tweet.User.ScreenName, tweet.Text),
345+
"loc-args": []string{tweet.User.ScreenName, notifiedUser.Handle, tweet.Text, tweet.IDStr},
346+
},
339347
"sound": "default",
340348
},
349+
"A": "M",
341350
}
342351
}
343352
case "liked", "liked_following":
@@ -369,9 +378,13 @@ func sendPushNotificationForPost(did string, typeOfNotification string, didOfPos
369378
// our body
370379
notificationBody = map[string]interface{}{
371380
"aps": map[string]interface{}{
372-
"alert": fmt.Sprintf("@%s favourited your tweet: %s", bskyUser.ScreenName, tweet.Text), // idk what this is
381+
"alert": map[string]interface{}{
382+
"body": fmt.Sprintf("@%s favourited your tweet: %s", bskyUser.ScreenName, tweet.Text),
383+
"loc-args": []string{tweet.User.ScreenName, notifiedUser.Handle, tweet.Text, tweet.IDStr},
384+
},
373385
"sound": "default",
374386
},
387+
"A": "F",
375388
}
376389
}
377390
case "retweet", "retweet_following":
@@ -409,9 +422,13 @@ func sendPushNotificationForPost(did string, typeOfNotification string, didOfPos
409422
// our body
410423
notificationBody = map[string]interface{}{
411424
"aps": map[string]interface{}{
412-
"alert": fmt.Sprintf("@%s: %s", tweet.User.ScreenName, tweet.Text),
425+
"alert": map[string]interface{}{
426+
"body": fmt.Sprintf("@%s: %s", tweet.User.ScreenName, tweet.Text),
427+
"loc-args": []string{tweet.User.ScreenName, notifiedUser.Handle, tweet.Text, tweet.IDStr},
428+
},
413429
"sound": "default",
414430
},
431+
"A": "R",
415432
}
416433
}
417434
case "follow":
@@ -421,12 +438,15 @@ func sendPushNotificationForPost(did string, typeOfNotification string, didOfPos
421438
return
422439
}
423440

424-
// our body
425441
notificationBody = map[string]interface{}{
426442
"aps": map[string]interface{}{
427-
"alert": fmt.Sprintf("@%s is now following you!", bskyUser.ScreenName),
443+
"alert": map[string]interface{}{
444+
"body": fmt.Sprintf("@%s is now following you!", bskyUser.ScreenName),
445+
"loc-args": []string{bskyUser.ScreenName, notifiedUser.Handle},
446+
},
428447
"sound": "default",
429448
},
449+
"A": "O",
430450
}
431451
}
432452
}
@@ -456,14 +476,6 @@ func sendPushNotificationForMonitoredUser(monitoredDID string, rkey string) {
456476

457477
tweet := twitterv1.TranslatePostToTweet(bskyPost.Thread.Post, "", "", "", nil, nil, "", "https://public.api.bsky.app")
458478

459-
notificationBody := map[string]interface{}{
460-
"aps": map[string]interface{}{
461-
"alert": fmt.Sprintf("@%s: %s", tweet.User.ScreenName, tweet.Text),
462-
"sound": "default",
463-
},
464-
"A": "T",
465-
}
466-
467479
// our body
468480
for _, acc := range accountsMonitoring {
469481
pushTokens, err := db_controller.GetPushTokensForDID(acc.UserDIDToNotify)
@@ -475,6 +487,22 @@ func sendPushNotificationForMonitoredUser(monitoredDID string, rkey string) {
475487
continue
476488
}
477489

490+
notifiedUser, err := blueskyapi.GetUserInfoRaw("https://public.api.bsky.app", "", acc.UserDIDToNotify)
491+
if err != nil {
492+
continue
493+
}
494+
495+
notificationBody := map[string]interface{}{
496+
"aps": map[string]interface{}{
497+
"alert": map[string]interface{}{
498+
"body": fmt.Sprintf("@%s: %s", tweet.User.ScreenName, tweet.Text),
499+
"loc-args": []string{tweet.User.ScreenName, notifiedUser.Handle, tweet.Text, tweet.IDStr},
500+
},
501+
"sound": "default",
502+
},
503+
"A": "T",
504+
}
505+
478506
if err := sgn.SendNotification(token.DeviceToken, notificationBody); err != nil {
479507
fmt.Println(err.Error())
480508
}

0 commit comments

Comments
 (0)