···
"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
+
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 {
229
+
ident, err := s.idResolver.ResolveIdent(ctx, did)
231
+
log.Printf("can't resolve handle for %s: %s", did, err)
234
+
followStatus := db.IsNotFollowing
235
+
if loggedInUserFollowing != nil {
236
+
if _, exists := loggedInUserFollowing[did]; exists {
237
+
followStatus = db.IsFollowing
238
+
} else if loggedInUser.Did == did {
239
+
followStatus = db.IsSelf
242
+
var profile *db.Profile
243
+
if p, exists := profiles[did]; exists {
246
+
profile = &db.Profile{}
249
+
followCards = append(followCards, pages.FollowCard{
UserHandle: ident.Handle.String(),
FollowStatus: followStatus,
191
-
Followers: followers,
192
-
Following: following,
256
+
return followCards, nil
259
+
func (s *State) followersPage(w http.ResponseWriter, r *http.Request) {
260
+
ident, ok := r.Context().Value("resolvedId").(identity.Identity)
262
+
s.pages.Error404(w)
266
+
profile, err := db.GetProfile(s.db, ident.DID.String())
268
+
log.Printf("getting profile data for %s: %s", ident.DID.String(), err)
271
+
loggedInUser := s.oauth.GetUser(r)
273
+
followers, err := db.GetFollowers(s.db, ident.DID.String())
275
+
log.Printf("getting followers for %s: %s", ident.DID.String(), err)
277
+
followerCards, err := s.makeFollowCards(
281
+
func(f db.Follow) string { return f.UserDid },
284
+
log.Printf("getting follower cards for %s: %s", ident.DID.String(), err)
287
+
followStatus := db.IsNotFollowing
288
+
if loggedInUser != nil {
289
+
followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, ident.DID.String())
292
+
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, ident.DID.String())
294
+
log.Printf("getting follow stats repos for %s: %s", ident.DID.String(), err)
297
+
s.pages.FollowersPage(w, pages.FollowersPageParams{
298
+
LoggedInUser: loggedInUser,
299
+
Followers: followerCards,
300
+
Card: pages.ProfileCard{
301
+
UserDid: ident.DID.String(),
302
+
UserHandle: ident.Handle.String(),
304
+
FollowStatus: followStatus,
305
+
FollowersCount: followersCount,
306
+
FollowingCount: followingCount,
311
+
func (s *State) followingPage(w http.ResponseWriter, r *http.Request) {
312
+
ident, ok := r.Context().Value("resolvedId").(identity.Identity)
314
+
s.pages.Error404(w)
318
+
profile, err := db.GetProfile(s.db, ident.DID.String())
320
+
log.Printf("getting profile data for %s: %s", ident.DID.String(), err)
323
+
loggedInUser := s.oauth.GetUser(r)
325
+
following, err := db.GetFollowing(s.db, ident.DID.String())
327
+
log.Printf("getting following for %s: %s", ident.DID.String(), err)
329
+
followingCards, err := s.makeFollowCards(
333
+
func(f db.Follow) string { return f.SubjectDid },
336
+
log.Printf("getting follower cards for %s: %s", ident.DID.String(), err)
339
+
followStatus := db.IsNotFollowing
340
+
if loggedInUser != nil {
341
+
followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, ident.DID.String())
344
+
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, ident.DID.String())
346
+
log.Printf("getting follow stats repos for %s: %s", ident.DID.String(), err)
349
+
s.pages.FollowingPage(w, pages.FollowingPageParams{
350
+
LoggedInUser: loggedInUser,
351
+
Following: followingCards,
352
+
Card: pages.ProfileCard{
353
+
UserDid: ident.DID.String(),
354
+
UserHandle: ident.Handle.String(),
356
+
FollowStatus: followStatus,
357
+
FollowersCount: followersCount,
358
+
FollowingCount: followingCount,