···
"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,
120
-
UserDid: ident.DID.String(),
121
-
UserHandle: ident.Handle.String(),
123
-
FollowStatus: followStatus,
124
-
Followers: followers,
125
-
Following: following,
125
+
UserDid: ident.DID.String(),
126
+
UserHandle: ident.Handle.String(),
128
+
FollowStatus: followStatus,
129
+
FollowersCount: followers,
130
+
FollowingCount: following,
ProfileTimeline: timeline,
···
LoggedInUser: loggedInUser,
168
-
UserDid: ident.DID.String(),
169
-
UserHandle: ident.Handle.String(),
171
-
FollowStatus: followStatus,
172
-
Followers: followers,
173
-
Following: following,
173
+
UserDid: ident.DID.String(),
174
+
UserHandle: ident.Handle.String(),
176
+
FollowStatus: followStatus,
177
+
FollowersCount: followers,
178
+
FollowingCount: following,
183
+
type FollowsPageParams struct {
184
+
LoggedInUser *oauth.User
185
+
Follows []pages.FollowCard
186
+
Card pages.ProfileCard
189
+
func (s *State) followPage(w http.ResponseWriter, r *http.Request, fetchFollows func(db.Execer, string) ([]db.Follow, error), extractDid func(db.Follow) string) *FollowsPageParams {
190
+
ident, ok := r.Context().Value("resolvedId").(identity.Identity)
192
+
s.pages.Error404(w)
195
+
did := ident.DID.String()
197
+
profile, err := db.GetProfile(s.db, did)
199
+
log.Printf("getting profile data for %s: %s", did, err)
202
+
loggedInUser := s.oauth.GetUser(r)
204
+
follows, err := fetchFollows(s.db, did)
206
+
log.Printf("getting followers for %s: %s", did, err)
209
+
if len(follows) == 0 {
213
+
followDids := make([]string, 0, len(follows))
214
+
for _, follow := range follows {
215
+
followDids = append(followDids, extractDid(follow))
218
+
profiles, err := db.GetProfiles(s.db, db.FilterIn("did", followDids))
220
+
log.Printf("getting profile for %s: %s", followDids, err)
224
+
var loggedInUserFollowing map[string]struct{}
225
+
if loggedInUser != nil {
226
+
following, err := db.GetFollowing(s.db, loggedInUser.Did)
230
+
if len(following) > 0 {
231
+
loggedInUserFollowing = make(map[string]struct{}, len(following))
232
+
for _, follow := range following {
233
+
loggedInUserFollowing[follow.SubjectDid] = struct{}{}
238
+
followCards := make([]pages.FollowCard, 0, len(follows))
239
+
for _, did := range followDids {
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
+
FollowStatus: followStatus,
262
+
FollowersCount: followersCount,
263
+
FollowingCount: followingCount,
268
+
followStatus := db.IsNotFollowing
269
+
if loggedInUser != nil {
270
+
followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, did)
273
+
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, did)
275
+
log.Printf("getting follow stats followers for %s: %s", did, err)
278
+
return &FollowsPageParams{
279
+
LoggedInUser: loggedInUser,
280
+
Follows: followCards,
281
+
Card: pages.ProfileCard{
283
+
UserHandle: ident.Handle.String(),
285
+
FollowStatus: followStatus,
286
+
FollowersCount: followersCount,
287
+
FollowingCount: followingCount,
292
+
func (s *State) followersPage(w http.ResponseWriter, r *http.Request) {
293
+
followPage := s.followPage(w, r, db.GetFollowers, func(f db.Follow) string { return f.UserDid })
295
+
s.pages.FollowersPage(w, pages.FollowersPageParams{
296
+
LoggedInUser: followPage.LoggedInUser,
297
+
Followers: followPage.Follows,
298
+
Card: followPage.Card,
302
+
func (s *State) followingPage(w http.ResponseWriter, r *http.Request) {
303
+
followPage := s.followPage(w, r, db.GetFollowing, func(f db.Follow) string { return f.SubjectDid })
305
+
s.pages.FollowingPage(w, pages.FollowingPageParams{
306
+
LoggedInUser: followPage.LoggedInUser,
307
+
Following: followPage.Follows,
308
+
Card: followPage.Card,
func (s *State) feedFromRequest(w http.ResponseWriter, r *http.Request) *feeds.Feed {
ident, ok := r.Context().Value("resolvedId").(identity.Identity)