From b1d057d060f5a35efece0c1630150f199ee281a9 Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Sun, 25 Jan 2026 20:38:13 +0900 Subject: [PATCH] appview/{pages,state}: simplify LoginPage params We don't need to pass full `MultiAccountUser` here. just `[]AccountInfo` should be enough. This way, we can make `MultiAccountUser` to always hold an active user. Signed-off-by: Seongmin Lee --- appview/oauth/accounts.go | 7 ++----- appview/oauth/accounts_test.go | 18 ------------------ appview/pages/pages.go | 8 ++++---- appview/pages/templates/user/login.html | 5 ++--- appview/pulls/pulls.go | 2 +- appview/reporesolver/resolver.go | 2 +- appview/state/login.go | 22 ++++++---------------- appview/state/timeline.go | 2 +- 8 files changed, 17 insertions(+), 49 deletions(-) diff --git a/appview/oauth/accounts.go b/appview/oauth/accounts.go index 2a7e1f89..c8948bf1 100644 --- a/appview/oauth/accounts.go +++ b/appview/oauth/accounts.go @@ -23,14 +23,11 @@ type AccountRegistry struct { } type MultiAccountUser struct { - Active *User + Active User Accounts []AccountInfo } func (m *MultiAccountUser) Did() string { - if m.Active == nil { - return "" - } return m.Active.Did } @@ -122,7 +119,7 @@ func (o *OAuth) GetMultiAccountUser(r *http.Request) *MultiAccountUser { registry := o.GetAccounts(r) return &MultiAccountUser{ - Active: &User{ + Active: User{ Did: sess.Data.AccountDID.String(), }, Accounts: registry.Accounts, diff --git a/appview/oauth/accounts_test.go b/appview/oauth/accounts_test.go index 7df95fbc..6d57536e 100644 --- a/appview/oauth/accounts_test.go +++ b/appview/oauth/accounts_test.go @@ -210,21 +210,3 @@ func TestAccountRegistry_FindAccount(t *testing.T) { } }) } - -func TestMultiAccountUser_Did(t *testing.T) { - t.Run("with active user", func(t *testing.T) { - user := &MultiAccountUser{ - Active: &User{Did: "did:plc:test"}, - } - if user.Did() != "did:plc:test" { - t.Errorf("Did() = %s, want did:plc:test", user.Did()) - } - }) - - t.Run("with nil active", func(t *testing.T) { - user := &MultiAccountUser{Active: nil} - if user.Did() != "" { - t.Errorf("Did() = %s, want empty string", user.Did()) - } - }) -} diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 9451e9eb..c1b9bc4c 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -309,10 +309,10 @@ func (p *Pages) Favicon(w io.Writer) error { } type LoginParams struct { - ReturnUrl string - ErrorCode string - AddAccount bool - LoggedInUser *oauth.MultiAccountUser + ReturnUrl string + ErrorCode string + AddAccount bool + Accounts []oauth.AccountInfo } func (p *Pages) Login(w io.Writer, params LoginParams) error { diff --git a/appview/pages/templates/user/login.html b/appview/pages/templates/user/login.html index f941e8bb..cfd52098 100644 --- a/appview/pages/templates/user/login.html +++ b/appview/pages/templates/user/login.html @@ -11,14 +11,13 @@ {{ end }} - {{ if and .LoggedInUser .LoggedInUser.Accounts }} - {{ $accounts := .LoggedInUser.Accounts }} + {{ if .Accounts }}
Saved accounts
- {{ range $accounts }} + {{ range .Accounts }}