···
tabVal := r.URL.Query().Get("tab")
28
+
s.profileHomePage(w, r)
34
-
func (s *State) profilePage(w http.ResponseWriter, r *http.Request) {
34
+
type ProfilePageParams struct {
35
+
Id identity.Identity
36
+
LoggedInUser *oauth.User
37
+
Card pages.ProfileCard
40
+
func (s *State) profilePage(w http.ResponseWriter, r *http.Request) *ProfilePageParams {
didOrHandle := chi.URLParam(r, "user")
37
-
http.Error(w, "Bad request", http.StatusBadRequest)
43
+
http.Error(w, "bad request", http.StatusBadRequest)
ident, ok := r.Context().Value("resolvedId").(identity.Identity)
49
+
log.Printf("malformed middleware")
50
+
w.WriteHeader(http.StatusInternalServerError)
53
+
did := ident.DID.String()
47
-
profile, err := db.GetProfile(s.db, ident.DID.String())
55
+
profile, err := db.GetProfile(s.db, did)
49
-
log.Printf("getting profile data for %s: %s", ident.DID.String(), err)
57
+
log.Printf("getting profile data for %s: %s", did, err)
60
+
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, did)
62
+
log.Printf("getting follow stats for %s: %s", did, err)
65
+
loggedInUser := s.oauth.GetUser(r)
66
+
followStatus := db.IsNotFollowing
67
+
if loggedInUser != nil {
68
+
followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, did)
71
+
return &ProfilePageParams{
73
+
LoggedInUser: loggedInUser,
74
+
Card: pages.ProfileCard{
76
+
UserHandle: ident.Handle.String(),
78
+
FollowStatus: followStatus,
79
+
FollowersCount: followersCount,
80
+
FollowingCount: followingCount,
85
+
func (s *State) profileHomePage(w http.ResponseWriter, r *http.Request) {
86
+
pageWithProfile := s.profilePage(w, r)
87
+
if pageWithProfile == nil {
91
+
id := pageWithProfile.Id
repos, err := db.GetRepos(
55
-
db.FilterEq("did", ident.DID.String()),
95
+
db.FilterEq("did", id.DID),
58
-
log.Printf("getting repos for %s: %s", ident.DID.String(), err)
98
+
log.Printf("getting repos for %s: %s", id.DID, err)
101
+
profile := pageWithProfile.Card.Profile
// filter out ones that are pinned
pinnedRepos := []db.Repo{}
for i, r := range repos {
···
75
-
collaboratingRepos, err := db.CollaboratingIn(s.db, ident.DID.String())
116
+
collaboratingRepos, err := db.CollaboratingIn(s.db, id.DID.String())
77
-
log.Printf("getting collaborating repos for %s: %s", ident.DID.String(), err)
118
+
log.Printf("getting collaborating repos for %s: %s", id.DID, err)
pinnedCollaboratingRepos := []db.Repo{}
···
88
-
timeline, err := db.MakeProfileTimeline(s.db, ident.DID.String())
129
+
timeline, err := db.MakeProfileTimeline(s.db, id.DID.String())
90
-
log.Printf("failed to create profile timeline for %s: %s", ident.DID.String(), err)
131
+
log.Printf("failed to create profile timeline for %s: %s", id.DID, err)
var didsToResolve []string
···
112
-
followers, following, err := db.GetFollowerFollowingCount(s.db, ident.DID.String())
114
-
log.Printf("getting follow stats repos for %s: %s", ident.DID.String(), err)
117
-
loggedInUser := s.oauth.GetUser(r)
118
-
followStatus := db.IsNotFollowing
119
-
if loggedInUser != nil {
120
-
followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, ident.DID.String())
startOfYear := time.Date(now.Year(), 1, 1, 0, 0, 0, 0, time.UTC)
punchcard, err := db.MakePunchcard(
127
-
db.FilterEq("did", ident.DID.String()),
157
+
db.FilterEq("did", id.DID),
db.FilterGte("date", startOfYear.Format(time.DateOnly)),
db.FilterLte("date", now.Format(time.DateOnly)),
132
-
log.Println("failed to get punchcard for did", "did", ident.DID.String(), "err", err)
162
+
log.Println("failed to get punchcard for did", "did", id.DID, "err", err)
135
-
s.pages.ProfilePage(w, pages.ProfilePageParams{
136
-
LoggedInUser: loggedInUser,
165
+
s.pages.ProfileHomePage(w, pages.ProfileHomePageParams{
166
+
LoggedInUser: pageWithProfile.LoggedInUser,
CollaboratingRepos: pinnedCollaboratingRepos,
139
-
Card: pages.ProfileCard{
140
-
UserDid: ident.DID.String(),
141
-
UserHandle: ident.Handle.String(),
143
-
FollowStatus: followStatus,
144
-
FollowersCount: followers,
145
-
FollowingCount: following,
147
-
Punchcard: punchcard,
148
-
ProfileTimeline: timeline,
169
+
Card: pageWithProfile.Card,
170
+
Punchcard: punchcard,
171
+
ProfileTimeline: timeline,
func (s *State) reposPage(w http.ResponseWriter, r *http.Request) {
153
-
ident, ok := r.Context().Value("resolvedId").(identity.Identity)
155
-
s.pages.Error404(w)
176
+
pageWithProfile := s.profilePage(w, r)
177
+
if pageWithProfile == nil {
159
-
profile, err := db.GetProfile(s.db, ident.DID.String())
161
-
log.Printf("getting profile data for %s: %s", ident.DID.String(), err)
181
+
id := pageWithProfile.Id
repos, err := db.GetRepos(
167
-
db.FilterEq("did", ident.DID.String()),
185
+
db.FilterEq("did", id.DID),
170
-
log.Printf("getting repos for %s: %s", ident.DID.String(), err)
173
-
loggedInUser := s.oauth.GetUser(r)
174
-
followStatus := db.IsNotFollowing
175
-
if loggedInUser != nil {
176
-
followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, ident.DID.String())
179
-
followers, following, err := db.GetFollowerFollowingCount(s.db, ident.DID.String())
181
-
log.Printf("getting follow stats repos for %s: %s", ident.DID.String(), err)
188
+
log.Printf("getting repos for %s: %s", id.DID, err)
s.pages.ReposPage(w, pages.ReposPageParams{
185
-
LoggedInUser: loggedInUser,
192
+
LoggedInUser: pageWithProfile.LoggedInUser,
187
-
Card: pages.ProfileCard{
188
-
UserDid: ident.DID.String(),
189
-
UserHandle: ident.Handle.String(),
191
-
FollowStatus: followStatus,
192
-
FollowersCount: followers,
193
-
FollowingCount: following,
194
+
Card: pageWithProfile.Card,
···
func (s *State) followPage(w http.ResponseWriter, r *http.Request, fetchFollows func(db.Execer, string) ([]db.Follow, error), extractDid func(db.Follow) string) *FollowsPageParams {
205
-
ident, ok := r.Context().Value("resolvedId").(identity.Identity)
207
-
s.pages.Error404(w)
205
+
pageWithProfile := s.profilePage(w, r)
206
+
if pageWithProfile == nil {
210
-
did := ident.DID.String()
212
-
profile, err := db.GetProfile(s.db, did)
214
-
log.Printf("getting profile data for %s: %s", did, err)
217
-
loggedInUser := s.oauth.GetUser(r)
210
+
id := pageWithProfile.Id
219
-
follows, err := fetchFollows(s.db, did)
212
+
follows, err := fetchFollows(s.db, id.DID.String())
221
-
log.Printf("getting followers for %s: %s", did, err)
214
+
log.Printf("getting followers for %s: %s", id.DID, err)
···
232
+
loggedInUser := pageWithProfile.LoggedInUser
var loggedInUserFollowing map[string]struct{}
following, err := db.GetFollowing(s.db, loggedInUser.Did)
···
283
-
followStatus := db.IsNotFollowing
284
-
if loggedInUser != nil {
285
-
followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, did)
288
-
followersCount, followingCount, err := db.GetFollowerFollowingCount(s.db, did)
290
-
log.Printf("getting follow stats followers for %s: %s", did, err)
return &FollowsPageParams{
LoggedInUser: loggedInUser,
296
-
Card: pages.ProfileCard{
298
-
UserHandle: ident.Handle.String(),
300
-
FollowStatus: followStatus,
301
-
FollowersCount: followersCount,
302
-
FollowingCount: followingCount,
280
+
Card: pageWithProfile.Card,