diff --git a/backend/internal/api/apikey.go b/backend/internal/api/apikey.go index 2c292de..a33af3d 100644 --- a/backend/internal/api/apikey.go +++ b/backend/internal/api/apikey.go @@ -16,6 +16,7 @@ import ( "github.com/go-chi/chi/v5" "margin.at/internal/db" + "margin.at/internal/domain" "margin.at/internal/logger" "margin.at/internal/xrpc" ) @@ -221,7 +222,8 @@ func (h *APIKeyHandler) QuickBookmark(w http.ResponseWriter, r *http.Request) { h.db.UpdateAPIKeyLastUsed(apiKey.ID) capturedTags := append([]string(nil), req.Tags...) - go func(did, url string) { + capturedURLHash := db.HashURL(req.URL) + go func(did, url, urlHash string) { prefs, dbErr := h.db.GetPreferences(did) communityEnabled := dbErr == nil && prefs != nil && (prefs.EnableCommunityBookmarks == nil || *prefs.EnableCommunityBookmarks) if !communityEnabled { @@ -242,8 +244,19 @@ func (h *APIKeyHandler) QuickBookmark(w http.ResponseWriter, r *http.Request) { } ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - _, _ = client.CreateRecord(ctx, did, xrpc.CollectionCommunityBookmark, communityRecord) - }(apiKey.OwnerDID, req.URL) + communityResult, communityErr := client.CreateRecord(ctx, did, xrpc.CollectionCommunityBookmark, communityRecord) + if communityErr == nil && communityResult != nil { + _ = h.db.CreateNote(&domain.Note{ + URI: communityResult.URI, + AuthorDID: did, + Motivation: "bookmarking", + TargetSource: url, + TargetHash: urlHash, + CreatedAt: time.Now(), + IndexedAt: time.Now(), + }) + } + }(apiKey.OwnerDID, req.URL, capturedURLHash) var titlePtr, bodyValuePtr, tagsJSONPtr *string if req.Title != "" { diff --git a/backend/internal/api/notes.go b/backend/internal/api/notes.go index 576131e..fddac54 100644 --- a/backend/internal/api/notes.go +++ b/backend/internal/api/notes.go @@ -1035,7 +1035,18 @@ func (s *NoteWriteService) CreateBookmark(w http.ResponseWriter, r *http.Request if len(capturedTags) > 0 { communityRecord["tags"] = capturedTags } - _, _ = client.CreateRecord(ctx, capturedSession.DID, xrpc.CollectionCommunityBookmark, communityRecord) + communityResult, communityErr := client.CreateRecord(ctx, capturedSession.DID, xrpc.CollectionCommunityBookmark, communityRecord) + if communityErr == nil && communityResult != nil { + _ = s.db.CreateNote(&domain.Note{ + URI: communityResult.URI, + AuthorDID: capturedSession.DID, + Motivation: "bookmarking", + TargetSource: capturedURL, + TargetHash: capturedURLHash, + CreatedAt: time.Now(), + IndexedAt: time.Now(), + }) + } }() var titlePtr *string