···
"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"
···
CollaboratingRepos: pinnedCollaboratingRepos,
139
-
UserDid: ident.DID.String(),
140
-
UserHandle: ident.Handle.String(),
142
-
FollowStatus: followStatus,
143
-
Followers: followers,
144
-
Following: following,
140
+
UserDid: ident.DID.String(),
141
+
UserHandle: ident.Handle.String(),
143
+
FollowStatus: followStatus,
144
+
FollowersCount: followers,
145
+
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,
188
+
UserDid: ident.DID.String(),
189
+
UserHandle: ident.Handle.String(),
191
+
FollowStatus: followStatus,
192
+
FollowersCount: followers,
193
+
FollowingCount: following,
198
+
type FollowsPageParams struct {
199
+
LoggedInUser *oauth.User
200
+
Follows []pages.FollowCard
201
+
Card pages.ProfileCard
204
+
func (s *State) followPage(w http.ResponseWriter, r *http.Request, fetchFollows func(db.Execer, string) ([]db.Follow, error), extractDid func(db.Follow) string) *FollowsPageParams {
205
+
ident, ok := r.Context().Value("resolvedId").(identity.Identity)
207
+
s.pages.Error404(w)
210
+
did := ident.DID.String()
212
+
profile, err := db.GetProfile(s.db, did)
214
+
log.Printf("getting profile data for %s: %s", did, err)
217
+
loggedInUser := s.oauth.GetUser(r)
219
+
follows, err := fetchFollows(s.db, did)
221
+
log.Printf("getting followers for %s: %s", did, err)
224
+
if len(follows) == 0 {
228
+
followDids := make([]string, 0, len(follows))
229
+
for _, follow := range follows {
230
+
followDids = append(followDids, extractDid(follow))
233
+
profiles, err := db.GetProfiles(s.db, db.FilterIn("did", followDids))
235
+
log.Printf("getting profile for %s: %s", followDids, err)
239
+
var loggedInUserFollowing map[string]struct{}
240
+
if loggedInUser != nil {
241
+
following, err := db.GetFollowing(s.db, loggedInUser.Did)
245
+
if len(following) > 0 {
246
+
loggedInUserFollowing = make(map[string]struct{}, len(following))
247
+
for _, follow := range following {
248
+
loggedInUserFollowing[follow.SubjectDid] = struct{}{}
253
+
followCards := make([]pages.FollowCard, 0, len(follows))
254
+
for _, did := range followDids {
255
+
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, did)
257
+
log.Printf("getting follow stats for %s: %s", did, err)
259
+
followStatus := db.IsNotFollowing
260
+
if loggedInUserFollowing != nil {
261
+
if _, exists := loggedInUserFollowing[did]; exists {
262
+
followStatus = db.IsFollowing
263
+
} else if loggedInUser.Did == did {
264
+
followStatus = db.IsSelf
267
+
var profile *db.Profile
268
+
if p, exists := profiles[did]; exists {
271
+
profile = &db.Profile{}
274
+
followCards = append(followCards, pages.FollowCard{
276
+
FollowStatus: followStatus,
277
+
FollowersCount: followersCount,
278
+
FollowingCount: followingCount,
283
+
followStatus := db.IsNotFollowing
284
+
if loggedInUser != nil {
285
+
followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, did)
288
+
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, did)
290
+
log.Printf("getting follow stats followers for %s: %s", did, err)
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 := s.followPage(w, r, db.GetFollowers, func(f db.Follow) string { return f.UserDid })
310
+
s.pages.FollowersPage(w, pages.FollowersPageParams{
311
+
LoggedInUser: followPage.LoggedInUser,
312
+
Followers: followPage.Follows,
313
+
Card: followPage.Card,
317
+
func (s *State) followingPage(w http.ResponseWriter, r *http.Request) {
318
+
followPage := s.followPage(w, r, db.GetFollowing, func(f db.Follow) string { return f.SubjectDid })
320
+
s.pages.FollowingPage(w, pages.FollowingPageParams{
321
+
LoggedInUser: followPage.LoggedInUser,
322
+
Following: followPage.Follows,
323
+
Card: followPage.Card,
func (s *State) feedFromRequest(w http.ResponseWriter, r *http.Request) *feeds.Feed {
ident, ok := r.Context().Value("resolvedId").(identity.Identity)