···
"github.com/gorilla/feeds"
"tangled.sh/tangled.sh/core/api/tangled"
"tangled.sh/tangled.sh/core/appview/db"
20
+
"tangled.sh/tangled.sh/core/appview/oauth"
"tangled.sh/tangled.sh/core/appview/pages"
···
32
+
s.followersPage(w, r)
34
+
s.followingPage(w, r)
···
CollaboratingRepos: pinnedCollaboratingRepos,
139
-
UserDid: ident.DID.String(),
140
-
UserHandle: ident.Handle.String(),
142
-
FollowStatus: followStatus,
143
-
Followers: followers,
144
-
Following: following,
144
+
UserDid: ident.DID.String(),
145
+
UserHandle: ident.Handle.String(),
147
+
FollowStatus: followStatus,
148
+
FollowersCount: followers,
149
+
FollowingCount: following,
ProfileTimeline: timeline,
···
LoggedInUser: loggedInUser,
187
-
UserDid: ident.DID.String(),
188
-
UserHandle: ident.Handle.String(),
190
-
FollowStatus: followStatus,
191
-
Followers: followers,
192
-
Following: following,
192
+
UserDid: ident.DID.String(),
193
+
UserHandle: ident.Handle.String(),
195
+
FollowStatus: followStatus,
196
+
FollowersCount: followers,
197
+
FollowingCount: following,
202
+
type FollowsPageParams struct {
203
+
LoggedInUser *oauth.User
204
+
Follows []pages.FollowCard
205
+
Card pages.ProfileCard
208
+
func (s *State) followPage(w http.ResponseWriter, r *http.Request, fetchFollows func(db.Execer, string) ([]db.Follow, error), extractDid func(db.Follow) string) *FollowsPageParams {
209
+
ident, ok := r.Context().Value("resolvedId").(identity.Identity)
211
+
s.pages.Error404(w)
214
+
did := ident.DID.String()
216
+
profile, err := db.GetProfile(s.db, did)
218
+
log.Printf("getting profile data for %s: %s", did, err)
221
+
loggedInUser := s.oauth.GetUser(r)
223
+
follows, err := fetchFollows(s.db, did)
225
+
log.Printf("getting followers for %s: %s", did, err)
228
+
if len(follows) == 0 {
232
+
followDids := make([]string, 0, len(follows))
233
+
for _, follow := range follows {
234
+
followDids = append(followDids, extractDid(follow))
237
+
profiles, err := db.GetProfiles(s.db, db.FilterIn("did", followDids))
239
+
log.Printf("getting profile for %s: %s", followDids, err)
243
+
var loggedInUserFollowing map[string]struct{}
244
+
if loggedInUser != nil {
245
+
following, err := db.GetFollowing(s.db, loggedInUser.Did)
249
+
if len(following) > 0 {
250
+
loggedInUserFollowing = make(map[string]struct{}, len(following))
251
+
for _, follow := range following {
252
+
loggedInUserFollowing[follow.SubjectDid] = struct{}{}
257
+
followCards := make([]pages.FollowCard, 0, len(follows))
258
+
for _, did := range followDids {
259
+
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, did)
261
+
log.Printf("getting follow stats for %s: %s", did, err)
263
+
followStatus := db.IsNotFollowing
264
+
if loggedInUserFollowing != nil {
265
+
if _, exists := loggedInUserFollowing[did]; exists {
266
+
followStatus = db.IsFollowing
267
+
} else if loggedInUser.Did == did {
268
+
followStatus = db.IsSelf
271
+
var profile *db.Profile
272
+
if p, exists := profiles[did]; exists {
275
+
profile = &db.Profile{}
278
+
followCards = append(followCards, pages.FollowCard{
280
+
FollowStatus: followStatus,
281
+
FollowersCount: followersCount,
282
+
FollowingCount: followingCount,
287
+
followStatus := db.IsNotFollowing
288
+
if loggedInUser != nil {
289
+
followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, did)
292
+
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, did)
294
+
log.Printf("getting follow stats followers for %s: %s", did, err)
297
+
return &FollowsPageParams{
298
+
LoggedInUser: loggedInUser,
299
+
Follows: followCards,
300
+
Card: pages.ProfileCard{
302
+
UserHandle: ident.Handle.String(),
304
+
FollowStatus: followStatus,
305
+
FollowersCount: followersCount,
306
+
FollowingCount: followingCount,
311
+
func (s *State) followersPage(w http.ResponseWriter, r *http.Request) {
312
+
followPage := s.followPage(w, r, db.GetFollowers, func(f db.Follow) string { return f.UserDid })
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 := s.followPage(w, r, db.GetFollowing, func(f db.Follow) string { return f.SubjectDid })
324
+
s.pages.FollowingPage(w, pages.FollowingPageParams{
325
+
LoggedInUser: followPage.LoggedInUser,
326
+
Following: followPage.Follows,
327
+
Card: followPage.Card,
func (s *State) feedFromRequest(w http.ResponseWriter, r *http.Request) *feeds.Feed {
ident, ok := r.Context().Value("resolvedId").(identity.Identity)