···
···
"github.com/gorilla/feeds"
"tangled.sh/tangled.sh/core/api/tangled"
"tangled.sh/tangled.sh/core/appview/db"
21
+
"tangled.sh/tangled.sh/core/appview/oauth"
"tangled.sh/tangled.sh/core/appview/pages"
···
33
+
s.followersPage(w, r)
35
+
s.followingPage(w, r)
···
CollaboratingRepos: pinnedCollaboratingRepos,
120
-
UserDid: ident.DID.String(),
121
-
UserHandle: ident.Handle.String(),
123
-
FollowStatus: followStatus,
124
-
Followers: followers,
125
-
Following: following,
126
+
UserDid: ident.DID.String(),
127
+
UserHandle: ident.Handle.String(),
129
+
FollowStatus: followStatus,
130
+
FollowersCount: followers,
131
+
FollowingCount: following,
ProfileTimeline: timeline,
···
LoggedInUser: loggedInUser,
168
-
UserDid: ident.DID.String(),
169
-
UserHandle: ident.Handle.String(),
171
-
FollowStatus: followStatus,
172
-
Followers: followers,
173
-
Following: following,
174
+
UserDid: ident.DID.String(),
175
+
UserHandle: ident.Handle.String(),
177
+
FollowStatus: followStatus,
178
+
FollowersCount: followers,
179
+
FollowingCount: following,
184
+
type FollowsPageParams struct {
185
+
LoggedInUser *oauth.User
186
+
Follows []pages.FollowCard
187
+
Card pages.ProfileCard
190
+
func (s *State) followPage(w http.ResponseWriter, r *http.Request, fetchFollows func(db.Execer, string) ([]db.Follow, error), extractDid func(db.Follow) string) (FollowsPageParams, error) {
191
+
ident, ok := r.Context().Value("resolvedId").(identity.Identity)
193
+
s.pages.Error404(w)
194
+
return FollowsPageParams{}, errors.New("identity not found")
196
+
did := ident.DID.String()
198
+
profile, err := db.GetProfile(s.db, did)
200
+
log.Printf("getting profile data for %s: %s", did, err)
201
+
return FollowsPageParams{}, err
204
+
loggedInUser := s.oauth.GetUser(r)
206
+
follows, err := fetchFollows(s.db, did)
208
+
log.Printf("getting followers for %s: %s", did, err)
209
+
return FollowsPageParams{}, err
212
+
var loggedInUserFollowing map[string]struct{}
213
+
if loggedInUser != nil {
214
+
following, err := db.GetFollowing(s.db, loggedInUser.Did)
216
+
return FollowsPageParams{}, err
218
+
if len(following) > 0 {
219
+
loggedInUserFollowing = make(map[string]struct{}, len(following))
220
+
for _, follow := range following {
221
+
loggedInUserFollowing[follow.SubjectDid] = struct{}{}
226
+
followStatus := db.IsNotFollowing
227
+
if loggedInUser != nil {
228
+
followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, did)
231
+
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, did)
233
+
log.Printf("getting follow stats followers for %s: %s", did, err)
234
+
return FollowsPageParams{}, err
237
+
if len(follows) == 0 {
238
+
return FollowsPageParams{
239
+
LoggedInUser: loggedInUser,
240
+
Follows: []pages.FollowCard{},
241
+
Card: pages.ProfileCard{
243
+
UserHandle: ident.Handle.String(),
245
+
FollowStatus: followStatus,
246
+
FollowersCount: followersCount,
247
+
FollowingCount: followingCount,
252
+
followDids := make([]string, 0, len(follows))
253
+
for _, follow := range follows {
254
+
followDids = append(followDids, extractDid(follow))
257
+
profiles, err := db.GetProfiles(s.db, db.FilterIn("did", followDids))
259
+
log.Printf("getting profile for %s: %s", followDids, err)
260
+
return FollowsPageParams{}, err
263
+
followCards := make([]pages.FollowCard, 0, len(follows))
264
+
for _, did := range followDids {
265
+
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, did)
267
+
log.Printf("getting follow stats for %s: %s", did, err)
269
+
followStatus := db.IsNotFollowing
270
+
if loggedInUserFollowing != nil {
271
+
if _, exists := loggedInUserFollowing[did]; exists {
272
+
followStatus = db.IsFollowing
273
+
} else if loggedInUser.Did == did {
274
+
followStatus = db.IsSelf
277
+
var profile *db.Profile
278
+
if p, exists := profiles[did]; exists {
281
+
profile = &db.Profile{}
284
+
followCards = append(followCards, pages.FollowCard{
286
+
FollowStatus: followStatus,
287
+
FollowersCount: followersCount,
288
+
FollowingCount: followingCount,
293
+
return FollowsPageParams{
294
+
LoggedInUser: loggedInUser,
295
+
Follows: followCards,
296
+
Card: pages.ProfileCard{
298
+
UserHandle: ident.Handle.String(),
300
+
FollowStatus: followStatus,
301
+
FollowersCount: followersCount,
302
+
FollowingCount: followingCount,
307
+
func (s *State) followersPage(w http.ResponseWriter, r *http.Request) {
308
+
followPage, err := s.followPage(w, r, db.GetFollowers, func(f db.Follow) string { return f.UserDid })
310
+
s.pages.Notice(w, "all-followers", "Failed to load followers")
314
+
s.pages.FollowersPage(w, pages.FollowersPageParams{
315
+
LoggedInUser: followPage.LoggedInUser,
316
+
Followers: followPage.Follows,
317
+
Card: followPage.Card,
321
+
func (s *State) followingPage(w http.ResponseWriter, r *http.Request) {
322
+
followPage, err := s.followPage(w, r, db.GetFollowing, func(f db.Follow) string { return f.SubjectDid })
324
+
s.pages.Notice(w, "all-following", "Failed to load following")
328
+
s.pages.FollowingPage(w, pages.FollowingPageParams{
329
+
LoggedInUser: followPage.LoggedInUser,
330
+
Following: followPage.Follows,
331
+
Card: followPage.Card,
func (s *State) AtomFeedPage(w http.ResponseWriter, r *http.Request) {
ident, ok := r.Context().Value("resolvedId").(identity.Identity)