···
"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
+
func (s *State) makeFollowCards(ctx context.Context, loggedInUser *oauth.User, follows []db.Follow, extractDid func(db.Follow) string) ([]pages.FollowCard, error) {
199
+
if len(follows) == 0 {
203
+
followDids := make([]string, 0, len(follows))
204
+
for _, follow := range follows {
205
+
followDids = append(followDids, extractDid(follow))
208
+
profiles, err := db.GetProfiles(s.db, db.FilterIn("did", followDids))
213
+
var loggedInUserFollowing map[string]struct{}
214
+
if loggedInUser != nil {
215
+
following, err := db.GetFollowing(s.db, loggedInUser.Did)
219
+
if len(following) > 0 {
220
+
loggedInUserFollowing = make(map[string]struct{}, len(following))
221
+
for _, follow := range following {
222
+
loggedInUserFollowing[follow.SubjectDid] = struct{}{}
227
+
followCards := make([]pages.FollowCard, 0, len(follows))
228
+
for _, did := range followDids {
230
+
if ident, err := s.idResolver.ResolveIdent(ctx, did); err != nil {
231
+
log.Printf("can't resolve handle for %s: %s", did, err)
233
+
} else if ident.Handle.IsInvalidHandle() {
234
+
handle = fmt.Sprintf("handle.invalid (%s)", did)
236
+
handle = ident.Handle.String()
238
+
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, did)
240
+
log.Printf("getting follow stats for %s: %s", did, err)
242
+
followStatus := db.IsNotFollowing
243
+
if loggedInUserFollowing != nil {
244
+
if _, exists := loggedInUserFollowing[did]; exists {
245
+
followStatus = db.IsFollowing
246
+
} else if loggedInUser.Did == did {
247
+
followStatus = db.IsSelf
250
+
var profile *db.Profile
251
+
if p, exists := profiles[did]; exists {
254
+
profile = &db.Profile{}
257
+
followCards = append(followCards, pages.FollowCard{
259
+
UserDisplayName: handle,
260
+
FollowStatus: followStatus,
261
+
FollowersCount: followersCount,
262
+
FollowingCount: followingCount,
266
+
return followCards, nil
269
+
func (s *State) followersPage(w http.ResponseWriter, r *http.Request) {
270
+
ident, ok := r.Context().Value("resolvedId").(identity.Identity)
272
+
s.pages.Error404(w)
276
+
profile, err := db.GetProfile(s.db, ident.DID.String())
278
+
log.Printf("getting profile data followers for %s: %s", ident.DID.String(), err)
281
+
loggedInUser := s.oauth.GetUser(r)
283
+
followers, err := db.GetFollowers(s.db, ident.DID.String())
285
+
log.Printf("getting followers followers for %s: %s", ident.DID.String(), err)
287
+
followerCards, err := s.makeFollowCards(
291
+
func(f db.Follow) string { return f.UserDid },
294
+
log.Printf("getting follow followers cards for %s: %s", ident.DID.String(), err)
297
+
followStatus := db.IsNotFollowing
298
+
if loggedInUser != nil {
299
+
followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, ident.DID.String())
302
+
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, ident.DID.String())
304
+
log.Printf("getting follow stats followers for %s: %s", ident.DID.String(), err)
307
+
s.pages.FollowersPage(w, pages.FollowersPageParams{
308
+
LoggedInUser: loggedInUser,
309
+
Followers: followerCards,
310
+
Card: pages.ProfileCard{
311
+
UserDid: ident.DID.String(),
312
+
UserHandle: ident.Handle.String(),
314
+
FollowStatus: followStatus,
315
+
FollowersCount: followersCount,
316
+
FollowingCount: followingCount,
321
+
func (s *State) followingPage(w http.ResponseWriter, r *http.Request) {
322
+
ident, ok := r.Context().Value("resolvedId").(identity.Identity)
324
+
s.pages.Error404(w)
328
+
profile, err := db.GetProfile(s.db, ident.DID.String())
330
+
log.Printf("getting profile data following for %s: %s", ident.DID.String(), err)
333
+
loggedInUser := s.oauth.GetUser(r)
335
+
following, err := db.GetFollowing(s.db, ident.DID.String())
337
+
log.Printf("getting following following for %s: %s", ident.DID.String(), err)
339
+
followingCards, err := s.makeFollowCards(
343
+
func(f db.Follow) string { return f.SubjectDid },
346
+
log.Printf("getting follow following cards for %s: %s", ident.DID.String(), err)
349
+
followStatus := db.IsNotFollowing
350
+
if loggedInUser != nil {
351
+
followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, ident.DID.String())
354
+
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, ident.DID.String())
356
+
log.Printf("getting follow stats following for %s: %s", ident.DID.String(), err)
359
+
s.pages.FollowingPage(w, pages.FollowingPageParams{
360
+
LoggedInUser: loggedInUser,
361
+
Following: followingCards,
362
+
Card: pages.ProfileCard{
363
+
UserDid: ident.DID.String(),
364
+
UserHandle: ident.Handle.String(),
366
+
FollowStatus: followStatus,
367
+
FollowersCount: followersCount,
368
+
FollowingCount: followingCount,