···
···
"github.com/gorilla/feeds"
"tangled.sh/tangled.sh/core/api/tangled"
"tangled.sh/tangled.sh/core/appview/db"
"tangled.sh/tangled.sh/core/appview/pages"
···
···
CollaboratingRepos: pinnedCollaboratingRepos,
-
UserDid: ident.DID.String(),
-
UserHandle: ident.Handle.String(),
-
FollowStatus: followStatus,
ProfileTimeline: timeline,
···
LoggedInUser: loggedInUser,
-
UserDid: ident.DID.String(),
-
UserHandle: ident.Handle.String(),
-
FollowStatus: followStatus,
func (s *State) AtomFeedPage(w http.ResponseWriter, r *http.Request) {
ident, ok := r.Context().Value("resolvedId").(identity.Identity)
···
···
"github.com/gorilla/feeds"
"tangled.sh/tangled.sh/core/api/tangled"
"tangled.sh/tangled.sh/core/appview/db"
+
"tangled.sh/tangled.sh/core/appview/oauth"
"tangled.sh/tangled.sh/core/appview/pages"
···
···
CollaboratingRepos: pinnedCollaboratingRepos,
+
UserDid: ident.DID.String(),
+
UserHandle: ident.Handle.String(),
+
FollowStatus: followStatus,
+
FollowersCount: followers,
+
FollowingCount: following,
ProfileTimeline: timeline,
···
LoggedInUser: loggedInUser,
+
UserDid: ident.DID.String(),
+
UserHandle: ident.Handle.String(),
+
FollowStatus: followStatus,
+
FollowersCount: followers,
+
FollowingCount: following,
+
type FollowsPageParams struct {
+
LoggedInUser *oauth.User
+
Follows []pages.FollowCard
+
func (s *State) followPage(w http.ResponseWriter, r *http.Request, fetchFollows func(db.Execer, string) ([]db.Follow, error), extractDid func(db.Follow) string) (FollowsPageParams, error) {
+
ident, ok := r.Context().Value("resolvedId").(identity.Identity)
+
return FollowsPageParams{}, errors.New("identity not found")
+
did := ident.DID.String()
+
profile, err := db.GetProfile(s.db, did)
+
log.Printf("getting profile data for %s: %s", did, err)
+
return FollowsPageParams{}, err
+
loggedInUser := s.oauth.GetUser(r)
+
follows, err := fetchFollows(s.db, did)
+
log.Printf("getting followers for %s: %s", did, err)
+
return FollowsPageParams{}, err
+
var loggedInUserFollowing map[string]struct{}
+
if loggedInUser != nil {
+
following, err := db.GetFollowing(s.db, loggedInUser.Did)
+
return FollowsPageParams{}, err
+
if len(following) > 0 {
+
loggedInUserFollowing = make(map[string]struct{}, len(following))
+
for _, follow := range following {
+
loggedInUserFollowing[follow.SubjectDid] = struct{}{}
+
followStatus := db.IsNotFollowing
+
if loggedInUser != nil {
+
followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, did)
+
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, did)
+
log.Printf("getting follow stats followers for %s: %s", did, err)
+
return FollowsPageParams{}, err
+
return FollowsPageParams{
+
LoggedInUser: loggedInUser,
+
Follows: []pages.FollowCard{},
+
Card: pages.ProfileCard{
+
UserHandle: ident.Handle.String(),
+
FollowStatus: followStatus,
+
FollowersCount: followersCount,
+
FollowingCount: followingCount,
+
followDids := make([]string, 0, len(follows))
+
for _, follow := range follows {
+
followDids = append(followDids, extractDid(follow))
+
profiles, err := db.GetProfiles(s.db, db.FilterIn("did", followDids))
+
log.Printf("getting profile for %s: %s", followDids, err)
+
return FollowsPageParams{}, err
+
followCards := make([]pages.FollowCard, 0, len(follows))
+
for _, did := range followDids {
+
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, did)
+
log.Printf("getting follow stats for %s: %s", did, err)
+
followStatus := db.IsNotFollowing
+
if loggedInUserFollowing != nil {
+
if _, exists := loggedInUserFollowing[did]; exists {
+
followStatus = db.IsFollowing
+
} else if loggedInUser.Did == did {
+
followStatus = db.IsSelf
+
var profile *db.Profile
+
if p, exists := profiles[did]; exists {
+
profile = &db.Profile{}
+
followCards = append(followCards, pages.FollowCard{
+
FollowStatus: followStatus,
+
FollowersCount: followersCount,
+
FollowingCount: followingCount,
+
return FollowsPageParams{
+
LoggedInUser: loggedInUser,
+
Card: pages.ProfileCard{
+
UserHandle: ident.Handle.String(),
+
FollowStatus: followStatus,
+
FollowersCount: followersCount,
+
FollowingCount: followingCount,
+
func (s *State) followersPage(w http.ResponseWriter, r *http.Request) {
+
followPage, err := s.followPage(w, r, db.GetFollowers, func(f db.Follow) string { return f.UserDid })
+
s.pages.Notice(w, "all-followers", "Failed to load followers")
+
s.pages.FollowersPage(w, pages.FollowersPageParams{
+
LoggedInUser: followPage.LoggedInUser,
+
Followers: followPage.Follows,
+
func (s *State) followingPage(w http.ResponseWriter, r *http.Request) {
+
followPage, err := s.followPage(w, r, db.GetFollowing, func(f db.Follow) string { return f.SubjectDid })
+
s.pages.Notice(w, "all-following", "Failed to load following")
+
s.pages.FollowingPage(w, pages.FollowingPageParams{
+
LoggedInUser: followPage.LoggedInUser,
+
Following: followPage.Follows,
func (s *State) AtomFeedPage(w http.ResponseWriter, r *http.Request) {
ident, ok := r.Context().Value("resolvedId").(identity.Identity)