From 1402ff5f90303e6589355324dcf5a4962355cc07 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Sun, 03 May 2026 15:08:11 +0000 Subject: [PATCH] appview/state: add htmx handler for profile popups Signed-off-by: oppiliappan --- appview/pages/pages.go | 18 ++++++++++++++++++ appview/state/profile.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ appview/state/router.go | 2 ++ 3 file(s) changed, 69 insertion(s)(+), 0 deletion(s)(-) diff --git a/appview/pages/pages.go b/appview/pages/pages.go --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -768,6 +768,24 @@ return p.executePlain("user/fragments/follow-oob", w, params) } +type ProfilePopoverParams struct { + LoggedInUser *oauth.MultiAccountUser + UserDid string + Profile *models.Profile + FollowStatus models.FollowStatus + VouchRelationship *models.VouchRelationship + Stats ProfilePopoverStats +} + +type ProfilePopoverStats struct { + FollowersCount int64 + FollowingCount int64 +} + +func (p *Pages) ProfilePopoverFragment(w io.Writer, params ProfilePopoverParams) error { + return p.executePlain("user/fragments/profilePopover", w, params) +} + type EditBioParams struct { LoggedInUser *oauth.MultiAccountUser Profile *models.Profile diff --git a/appview/state/profile.go b/appview/state/profile.go --- a/appview/state/profile.go +++ b/appview/state/profile.go @@ -905,6 +905,55 @@ s.pages.HxRedirect(w, "/"+user.Did) } +func (s *State) ProfilePopover(w http.ResponseWriter, r *http.Request) { + l := s.logger.With("handler", "ProfilePopover") + + did := r.URL.Query().Get("did") + if did == "" { + l.Warn("missing did param") + w.WriteHeader(http.StatusBadRequest) + return + } + + profile, err := db.GetProfile(s.db, did) + if err != nil { + l.Error("failed to get profile", "did", did, "err", err) + w.WriteHeader(http.StatusInternalServerError) + return + } + if profile == nil { + profile = &models.Profile{Did: did} + } + + followStats, err := db.GetFollowerFollowingCount(s.db, did) + if err != nil { + l.Error("failed to get follower stats", "did", did, "err", err) + w.WriteHeader(http.StatusInternalServerError) + return + } + + loggedInUser := s.oauth.GetMultiAccountUser(r) + followStatus := models.IsNotFollowing + var vouchRelationship *models.VouchRelationship + + if loggedInUser != nil { + followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, did) + vouchRelationship, _ = db.GetVouchRelationship(s.db, syntax.DID(loggedInUser.Did), syntax.DID(did)) + } + + s.pages.ProfilePopoverFragment(w, pages.ProfilePopoverParams{ + LoggedInUser: loggedInUser, + UserDid: did, + Profile: profile, + FollowStatus: followStatus, + VouchRelationship: vouchRelationship, + Stats: pages.ProfilePopoverStats{ + FollowersCount: followStats.Followers, + FollowingCount: followStats.Following, + }, + }) +} + func (s *State) EditBioFragment(w http.ResponseWriter, r *http.Request) { l := s.logger.With("handler", "EditBioFragment") user := s.oauth.GetMultiAccountUser(r) diff --git a/appview/state/router.go b/appview/state/router.go --- a/appview/state/router.go +++ b/appview/state/router.go @@ -195,6 +195,8 @@ r.Delete("/", s.React) }) + r.Get("/profile/popover", s.ProfilePopover) + r.Route("/profile", func(r chi.Router) { r.Use(middleware.AuthMiddleware(s.oauth)) r.Get("/edit-bio", s.EditBioFragment) -- tangled.sh