Yōten: A social tracker for your language learning journey built on the atproto.

feat: notify people on replies

brookjeynes.dev a49edabb de1d829e

verified
+16 -4
+14 -3
internal/consumer/ingester.go
··· 633 633 return fmt.Errorf("failed to upsert comment record: %w", err) 634 634 } 635 635 636 - err = db.CreateNotification(tx, subjectDid.String(), did, subjectUri.String(), db.NotificationTypeComment) 637 - if err != nil { 638 - log.Println("failed to create notification record:", err) 636 + // Create a comment if not commenting on self post. 637 + if subjectDid.String() != did { 638 + err = db.CreateNotification(tx, subjectDid.String(), did, subjectUri.String(), db.NotificationTypeComment) 639 + if err != nil { 640 + log.Println("failed to create notification record:", err) 641 + } 642 + } 643 + 644 + // Notify comment creator of reply if not replying to their own comment. 645 + if comment.ParentCommentUri != nil && comment.ParentCommentUri.Authority().String() != did { 646 + err = db.CreateNotification(tx, comment.ParentCommentUri.Authority().String(), did, parentCommentUri.String(), db.NotificationTypeReply) 647 + if err != nil { 648 + log.Println("failed to create notification record:", err) 649 + } 639 650 } 640 651 641 652 return tx.Commit()
+1
internal/db/notification.go
··· 13 13 NotificationTypeFollow NotificationType = "follow" 14 14 NotificationTypeReaction NotificationType = "reaction" 15 15 NotificationTypeComment NotificationType = "comment" 16 + NotificationTypeReply NotificationType = "reply" 16 17 ) 17 18 18 19 type NotificationState string
+1 -1
migrations/update_notification_type.sql
··· 11 11 actor_did TEXT NOT NULL, 12 12 subject_uri TEXT NOT NULL, 13 13 state TEXT NOT NULL DEFAULT 'unread' CHECK(state IN ('unread', 'read')), 14 - type TEXT NOT NULL CHECK(type IN ('follow', 'reaction', 'comment')), 14 + type TEXT NOT NULL CHECK(type IN ('follow', 'reaction', 'comment', 'reply')), 15 15 created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')), 16 16 FOREIGN KEY (recipient_did) REFERENCES profiles(did) ON DELETE CASCADE, 17 17 FOREIGN KEY (actor_did) REFERENCES profiles(did) ON DELETE CASCADE