this repo has no description
0
fork

Configure Feed

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

get sub uri so we can delete posts

+32 -7
+5
feedgenerator.go
··· 14 14 GetSubscriptionsForUser(ctx context.Context, userDID string) ([]store.Subscription, error) 15 15 DeleteSubscriptionBySubRKeyAndUser(userDID, rkey string) error 16 16 DeleteFeedPostsForSubscribedPostURIandUserDID(subscribedPostURI, userDID string) error 17 + GetSubscriptionURIByRKeyAndUserDID(userDID, rkey string) (string, error) 17 18 } 18 19 19 20 type FeedGenerator struct { ··· 74 75 func (f *FeedGenerator) DeleteFeedPostsForSubscribedPostURIandUserDID(subscribedPostURI, userDID string) error { 75 76 return f.store.DeleteFeedPostsForSubscribedPostURIandUserDID(subscribedPostURI, userDID) 76 77 } 78 + 79 + func (f *FeedGenerator) GetSubscriptionURIByRKeyAndUserDID(userDID, rkey string) (string, error) { 80 + return f.GetSubscriptionURIByRKeyAndUserDID(userDID, rkey) 81 + }
+7 -7
frontend_handlers.go
··· 96 96 97 97 usersDid := didCookie.Value 98 98 99 - // id, err := strconv.Atoi(sub) 100 - // if err != nil { 101 - // slog.Error("failed to convert sub ID to int", "error", err) 102 - // http.Error(w, "invalid ID", http.StatusBadRequest) 103 - // return 104 - // } 99 + subURI, err := s.feeder.GetSubscriptionURIByRKeyAndUserDID(usersDid, subRKey) 100 + if err != nil { 101 + slog.Error("get sub URI by rkey and user did", "error", err, "subscription URI", subRKey) 102 + http.Error(w, "failed to delete feed posts for subscription and user", http.StatusInternalServerError) 103 + return 104 + } 105 105 106 - err = s.feeder.DeleteFeedPostsForSubscribedPostURIandUserDID(subRKey, usersDid) 106 + err = s.feeder.DeleteFeedPostsForSubscribedPostURIandUserDID(subURI, usersDid) 107 107 if err != nil { 108 108 slog.Error("delete feed posts for subscription and user", "error", err, "subscription URI", subRKey) 109 109 http.Error(w, "failed to delete feed posts for subscription and user", http.StatusInternalServerError)
+1
server.go
··· 15 15 GetSubscriptionsForUser(ctx context.Context, userDID string) ([]store.Subscription, error) 16 16 DeleteSubscriptionBySubRKeyAndUser(userDID, rkey string) error 17 17 DeleteFeedPostsForSubscribedPostURIandUserDID(subscribedPostURI, userDID string) error 18 + GetSubscriptionURIByRKeyAndUserDID(userDID, rkey string) (string, error) 18 19 } 19 20 20 21 type Server struct {
+19
store/subscription.go
··· 124 124 } 125 125 return nil 126 126 } 127 + 128 + func (s *Store) GetSubscriptionURIByRKeyAndUserDID(userDID, rkey string) (string, error) { 129 + sql := "SELECT subscribedPostURI FROM subscriptions WHERE subscriptionPostRkey = ? AND userDID = ?;" 130 + rows, err := s.db.Query(sql, userDID) 131 + if err != nil { 132 + return "", fmt.Errorf("run query to get subscribed by rkey and userDID: %w", err) 133 + } 134 + defer rows.Close() 135 + 136 + var result string 137 + for rows.Next() { 138 + if err := rows.Scan(&result); err != nil { 139 + return "", fmt.Errorf("scan row: %w", err) 140 + } 141 + 142 + return result, nil 143 + } 144 + return "", nil 145 + }