(READ ONLY) Margin is an open annotation layer for the internet. Powered by the AT Protocol. margin.at
extension web atproto comments
99
fork

Configure Feed

Select the types of activity you want to include in your feed.

some fixes

+37 -1
+1
backend/internal/api/hydration.go
··· 1023 1023 b := APIBookmark{ 1024 1024 ID: n.URI, 1025 1025 Type: "Bookmark", 1026 + Motivation: "bookmarking", 1026 1027 Author: profiles[n.AuthorDID], 1027 1028 Source: n.TargetSource, 1028 1029 Title: title,
+21 -1
backend/internal/api/notes.go
··· 51 51 SaveEditHistory(uri, recordType, previousContent string, previousCID *string) error 52 52 HashURL(rawURL string) string 53 53 CommunityBookmarkExists(authorDID, targetHash, tagsJSON string) (bool, error) 54 + GetCommunityBookmarkURI(authorDID, targetHash string) (string, error) 54 55 } 55 56 56 57 type dbAdapter struct{ d *db.DB } ··· 129 130 func (a *dbAdapter) HashURL(rawURL string) string { return db.HashURL(rawURL) } 130 131 func (a *dbAdapter) CommunityBookmarkExists(did, hash, tags string) (bool, error) { 131 132 return a.d.CommunityBookmarkExists(did, hash, tags) 133 + } 134 + func (a *dbAdapter) GetCommunityBookmarkURI(did, hash string) (string, error) { 135 + return a.d.GetCommunityBookmarkURI(did, hash) 132 136 } 133 137 134 138 type NoteWriteService struct { ··· 1126 1130 1127 1131 did := session.DID 1128 1132 collection := xrpc.CollectionNote 1133 + var targetHash string 1129 1134 for _, col := range []string{xrpc.CollectionNote, xrpc.CollectionBookmark, xrpc.CollectionCommunityBookmark} { 1130 1135 uri := "at://" + did + "/" + col + "/" + rkey 1131 1136 if note, dbErr := s.db.GetNoteByURI(uri); dbErr == nil && note != nil { 1132 1137 collection = col 1138 + targetHash = note.TargetHash 1133 1139 break 1134 - } else if _, dbErr := s.db.GetBookmarkByURI(uri); dbErr == nil { 1140 + } else if bm, dbErr := s.db.GetBookmarkByURI(uri); dbErr == nil && bm != nil { 1135 1141 collection = col 1142 + targetHash = bm.SourceHash 1136 1143 break 1137 1144 } 1138 1145 } ··· 1147 1154 uri := "at://" + did + "/" + collection + "/" + rkey 1148 1155 s.db.DeleteBookmark(uri) 1149 1156 s.db.DeleteNote(uri) 1157 + 1158 + if collection != xrpc.CollectionCommunityBookmark && targetHash != "" { 1159 + if communityURI, err := s.db.GetCommunityBookmarkURI(did, targetHash); err == nil && communityURI != "" { 1160 + parts := strings.Split(communityURI, "/") 1161 + if len(parts) == 5 { 1162 + communityRkey := parts[4] 1163 + _ = s.refresher.ExecuteWithAutoRefresh(r, session, func(client *xrpc.Client, did string) error { 1164 + return client.DeleteRecord(r.Context(), did, xrpc.CollectionCommunityBookmark, communityRkey) 1165 + }) 1166 + } 1167 + s.db.DeleteNote(communityURI) 1168 + } 1169 + } 1150 1170 1151 1171 WriteSuccess(w, map[string]bool{"success": true}) 1152 1172 }
+15
backend/internal/db/queries_notes.go
··· 75 75 return true, nil 76 76 } 77 77 78 + func (db *DB) GetCommunityBookmarkURI(authorDID, targetHash string) (string, error) { 79 + var uri string 80 + err := db.QueryRow(` 81 + SELECT uri FROM notes 82 + WHERE author_did = $1 83 + AND target_hash = $2 84 + AND uri LIKE 'at://%/community.lexicon.bookmarks.bookmark/%' 85 + LIMIT 1 86 + `, authorDID, targetHash).Scan(&uri) 87 + if err == sql.ErrNoRows { 88 + return "", nil 89 + } 90 + return uri, err 91 + } 92 + 78 93 func (db *DB) CommunityBookmarkExists(authorDID, targetHash, tagsJSON string) (bool, error) { 79 94 query := ` 80 95 SELECT 1 FROM notes