···
"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
+
var displayName string
231
+
if ident, err := s.idResolver.ResolveIdent(ctx, did); err != nil {
232
+
log.Printf("can't resolve handle for %s: %s", did, err)
234
+
} else if ident.Handle.IsInvalidHandle() {
235
+
displayName = fmt.Sprintf("handle.invalid (%s)", did)
237
+
displayName = ident.Handle.String()
238
+
handle = ident.Handle.String()
240
+
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, did)
242
+
log.Printf("getting follow stats for %s: %s", did, err)
244
+
followStatus := db.IsNotFollowing
245
+
if loggedInUserFollowing != nil {
246
+
if _, exists := loggedInUserFollowing[did]; exists {
247
+
followStatus = db.IsFollowing
248
+
} else if loggedInUser.Did == did {
249
+
followStatus = db.IsSelf
252
+
var profile *db.Profile
253
+
if p, exists := profiles[did]; exists {
256
+
profile = &db.Profile{}
259
+
followCards = append(followCards, pages.FollowCard{
261
+
UserHandle: handle,
262
+
UserDisplayName: displayName,
263
+
FollowStatus: followStatus,
264
+
FollowersCount: followersCount,
265
+
FollowingCount: followingCount,
269
+
return followCards, nil
272
+
func (s *State) followersPage(w http.ResponseWriter, r *http.Request) {
273
+
ident, ok := r.Context().Value("resolvedId").(identity.Identity)
275
+
s.pages.Error404(w)
279
+
profile, err := db.GetProfile(s.db, ident.DID.String())
281
+
log.Printf("getting profile data followers for %s: %s", ident.DID.String(), err)
284
+
loggedInUser := s.oauth.GetUser(r)
286
+
followers, err := db.GetFollowers(s.db, ident.DID.String())
288
+
log.Printf("getting followers followers for %s: %s", ident.DID.String(), err)
290
+
followerCards, err := s.makeFollowCards(
294
+
func(f db.Follow) string { return f.UserDid },
297
+
log.Printf("getting follow followers cards for %s: %s", ident.DID.String(), err)
300
+
followStatus := db.IsNotFollowing
301
+
if loggedInUser != nil {
302
+
followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, ident.DID.String())
305
+
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, ident.DID.String())
307
+
log.Printf("getting follow stats followers for %s: %s", ident.DID.String(), err)
310
+
s.pages.FollowersPage(w, pages.FollowersPageParams{
311
+
LoggedInUser: loggedInUser,
312
+
Followers: followerCards,
313
+
Card: pages.ProfileCard{
314
+
UserDid: ident.DID.String(),
315
+
UserHandle: ident.Handle.String(),
317
+
FollowStatus: followStatus,
318
+
FollowersCount: followersCount,
319
+
FollowingCount: followingCount,
324
+
func (s *State) followingPage(w http.ResponseWriter, r *http.Request) {
325
+
ident, ok := r.Context().Value("resolvedId").(identity.Identity)
327
+
s.pages.Error404(w)
331
+
profile, err := db.GetProfile(s.db, ident.DID.String())
333
+
log.Printf("getting profile data following for %s: %s", ident.DID.String(), err)
336
+
loggedInUser := s.oauth.GetUser(r)
338
+
following, err := db.GetFollowing(s.db, ident.DID.String())
340
+
log.Printf("getting following following for %s: %s", ident.DID.String(), err)
342
+
followingCards, err := s.makeFollowCards(
346
+
func(f db.Follow) string { return f.SubjectDid },
349
+
log.Printf("getting follow following cards for %s: %s", ident.DID.String(), err)
352
+
followStatus := db.IsNotFollowing
353
+
if loggedInUser != nil {
354
+
followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, ident.DID.String())
357
+
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, ident.DID.String())
359
+
log.Printf("getting follow stats following for %s: %s", ident.DID.String(), err)
362
+
s.pages.FollowingPage(w, pages.FollowingPageParams{
363
+
LoggedInUser: loggedInUser,
364
+
Following: followingCards,
365
+
Card: pages.ProfileCard{
366
+
UserDid: ident.DID.String(),
367
+
UserHandle: ident.Handle.String(),
369
+
FollowStatus: followStatus,
370
+
FollowersCount: followersCount,
371
+
FollowingCount: followingCount,