From 31ff8376ca7ba86c2a2f1bee702b2a6be0dcd9de Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Thu, 30 Oct 2025 14:29:38 +0000 Subject: [PATCH] appview/repo: remove EmailToDidOrHandle Change-Id: msnlwkzsyxwssuzqvnssrtxmkptpukym we no longer resolve handles from DIDs at the handlers, we do this dynamically when rendering the templates. EmailToDidOrHandle did not follow this pattern. there were a few negative side effects from this: the `tinyAvatar` helper requires that the input be a DID; and not a handle. when a handle is passed, it results in a different default color for users without profile pictures; resulting in different colors in repo-log versus, say, the topbar. Signed-off-by: oppiliappan --- appview/pages/pages.go | 41 ++++++++++++------------ appview/pages/templates/repo/commit.html | 22 ++++++------- appview/pages/templates/repo/index.html | 16 ++------- appview/pages/templates/repo/log.html | 12 +++---- appview/repo/index.go | 10 +++--- appview/repo/repo.go | 16 ++++----- appview/repo/repo_util.go | 35 -------------------- 7 files changed, 54 insertions(+), 98 deletions(-) diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 9608ff2e..6f32e5a8 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -660,13 +660,13 @@ type RepoIndexParams struct { TagsTrunc []*types.TagReference BranchesTrunc []types.Branch // ForkInfo *types.ForkInfo - HTMLReadme template.HTML - Raw bool - EmailToDidOrHandle map[string]string - VerifiedCommits commitverify.VerifiedCommits - Languages []types.RepoLanguageDetails - Pipelines map[string]models.Pipeline - NeedsKnotUpgrade bool + HTMLReadme template.HTML + Raw bool + EmailToDid map[string]string + VerifiedCommits commitverify.VerifiedCommits + Languages []types.RepoLanguageDetails + Pipelines map[string]models.Pipeline + NeedsKnotUpgrade bool types.RepoIndexResponse } @@ -701,14 +701,15 @@ func (p *Pages) RepoIndexPage(w io.Writer, params RepoIndexParams) error { } type RepoLogParams struct { - LoggedInUser *oauth.User - RepoInfo repoinfo.RepoInfo - TagMap map[string][]string + LoggedInUser *oauth.User + RepoInfo repoinfo.RepoInfo + TagMap map[string][]string + Active string + EmailToDid map[string]string + VerifiedCommits commitverify.VerifiedCommits + Pipelines map[string]models.Pipeline + types.RepoLogResponse - Active string - EmailToDidOrHandle map[string]string - VerifiedCommits commitverify.VerifiedCommits - Pipelines map[string]models.Pipeline } func (p *Pages) RepoLog(w io.Writer, params RepoLogParams) error { @@ -717,12 +718,12 @@ func (p *Pages) RepoLog(w io.Writer, params RepoLogParams) error { } type RepoCommitParams struct { - LoggedInUser *oauth.User - RepoInfo repoinfo.RepoInfo - Active string - EmailToDidOrHandle map[string]string - Pipeline *models.Pipeline - DiffOpts types.DiffOpts + LoggedInUser *oauth.User + RepoInfo repoinfo.RepoInfo + Active string + EmailToDid map[string]string + Pipeline *models.Pipeline + DiffOpts types.DiffOpts // singular because it's always going to be just one VerifiedCommit commitverify.VerifiedCommits diff --git a/appview/pages/templates/repo/commit.html b/appview/pages/templates/repo/commit.html index 4a5525b2..1ee12893 100644 --- a/appview/pages/templates/repo/commit.html +++ b/appview/pages/templates/repo/commit.html @@ -24,25 +24,25 @@ -
-

- {{ $didOrHandle := index $.EmailToDidOrHandle $commit.Author.Email }} +

+

+ {{ $did := index $.EmailToDid $commit.Author.Email }} - {{ if $didOrHandle }} - {{ $didOrHandle }} + {{ if $did }} + {{ template "user/fragments/picHandleLink" $did }} {{ else }} {{ $commit.Author.Name }} {{ end }} + {{ template "repo/fragments/time" $commit.Author.When }} -

-

{{ slice $commit.This 0 8 }} + {{ if $commit.Parent }} - {{ i "arrow-left" "w-3 h-3 mx-1" }} - {{ slice $commit.Parent 0 8 }} + {{ i "arrow-left" "w-3 h-3 mx-1" }} + {{ slice $commit.Parent 0 8 }} {{ end }}

@@ -58,8 +58,8 @@
This commit was signed with the committer's known signature.
{{ i "user" "w-4 h-4" }} - {{ $committerDidOrHandle := index $.EmailToDidOrHandle $commit.Committer.Email }} - {{ template "user/fragments/picHandleLink" $committerDidOrHandle }} + {{ $committerDid := index $.EmailToDid $commit.Committer.Email }} + {{ template "user/fragments/picHandleLink" $committerDid }}
SSH Key Fingerprint:
diff --git a/appview/pages/templates/repo/index.html b/appview/pages/templates/repo/index.html index f8148dba..6ce13417 100644 --- a/appview/pages/templates/repo/index.html +++ b/appview/pages/templates/repo/index.html @@ -222,20 +222,10 @@ class="mx-1 before:content-['·'] before:select-none" > - {{ $didOrHandle := index $.EmailToDidOrHandle .Author.Email }} - {{ if $didOrHandle }} - {{ template "user/fragments/picHandleLink" $didOrHandle }} - {{ else }} - {{ .Author.Name }} - {{ end }} + >{{ if $did }}{{ template "user/fragments/picHandleLink" $did }}{{ else }}{{ .Author.Name }}{{ end }}
{{ template "repo/fragments/time" .Committer.When }} diff --git a/appview/pages/templates/repo/log.html b/appview/pages/templates/repo/log.html index 4cbc439e..207b90f3 100644 --- a/appview/pages/templates/repo/log.html +++ b/appview/pages/templates/repo/log.html @@ -27,9 +27,9 @@ {{ $messageParts := splitN $commit.Message "\n\n" 2 }}
- {{ $didOrHandle := index $.EmailToDidOrHandle $commit.Author.Email }} - {{ if $didOrHandle }} - {{ template "user/fragments/picHandleLink" $didOrHandle }} + {{ $did := index $.EmailToDid $commit.Author.Email }} + {{ if $did }} + {{ template "user/fragments/picHandleLink" $did }} {{ else }} {{ $commit.Author.Name }} {{ end }} @@ -153,10 +153,10 @@ - {{ $didOrHandle := index $.EmailToDidOrHandle $commit.Author.Email }} - - {{ if $didOrHandle }}{{ template "user/fragments/picHandleLink" $didOrHandle }}{{ else }}{{ $commit.Author.Name }}{{ end }} + {{ if $did }}{{ template "user/fragments/picHandleLink" $did }}{{ else }}{{ $commit.Author.Name }}{{ end }}
diff --git a/appview/repo/index.go b/appview/repo/index.go index 3e3865cd..23e09c88 100644 --- a/appview/repo/index.go +++ b/appview/repo/index.go @@ -154,11 +154,11 @@ func (rp *Repo) RepoIndex(w http.ResponseWriter, r *http.Request) { CommitsTrunc: commitsTrunc, TagsTrunc: tagsTrunc, // ForkInfo: forkInfo, // TODO: reinstate this after xrpc properly lands - BranchesTrunc: branchesTrunc, - EmailToDidOrHandle: emailToDidOrHandle(rp, emailToDidMap), - VerifiedCommits: vc, - Languages: languageInfo, - Pipelines: pipelines, + BranchesTrunc: branchesTrunc, + EmailToDid: emailToDidMap, + VerifiedCommits: vc, + Languages: languageInfo, + Pipelines: pipelines, }) } diff --git a/appview/repo/repo.go b/appview/repo/repo.go index 14b38700..7ddd6357 100644 --- a/appview/repo/repo.go +++ b/appview/repo/repo.go @@ -242,13 +242,13 @@ func (rp *Repo) RepoLog(w http.ResponseWriter, r *http.Request) { } rp.pages.RepoLog(w, pages.RepoLogParams{ - LoggedInUser: user, - TagMap: tagMap, - RepoInfo: repoInfo, - RepoLogResponse: xrpcResp, - EmailToDidOrHandle: emailToDidOrHandle(rp, emailToDidMap), - VerifiedCommits: vc, - Pipelines: pipelines, + LoggedInUser: user, + TagMap: tagMap, + RepoInfo: repoInfo, + RepoLogResponse: xrpcResp, + EmailToDid: emailToDidMap, + VerifiedCommits: vc, + Pipelines: pipelines, }) } @@ -422,7 +422,7 @@ func (rp *Repo) RepoCommit(w http.ResponseWriter, r *http.Request) { LoggedInUser: user, RepoInfo: f.RepoInfo(user), RepoCommitResponse: result, - EmailToDidOrHandle: emailToDidOrHandle(rp, emailToDidMap), + EmailToDid: emailToDidMap, VerifiedCommit: vc, Pipeline: pipeline, DiffOpts: diffOpts, diff --git a/appview/repo/repo_util.go b/appview/repo/repo_util.go index 1bbe45da..816f51f9 100644 --- a/appview/repo/repo_util.go +++ b/appview/repo/repo_util.go @@ -1,9 +1,7 @@ package repo import ( - "context" "crypto/rand" - "fmt" "math/big" "slices" "sort" @@ -92,39 +90,6 @@ func balanceIndexItems(commitCount, branchCount, tagCount, fileCount int) (commi return } -// emailToDidOrHandle takes an emailToDidMap from db.GetEmailToDid -// and resolves all dids to handles and returns a new map[string]string -func emailToDidOrHandle(r *Repo, emailToDidMap map[string]string) map[string]string { - if emailToDidMap == nil { - return nil - } - - var dids []string - for _, v := range emailToDidMap { - dids = append(dids, v) - } - resolvedIdents := r.idResolver.ResolveIdents(context.Background(), dids) - - didHandleMap := make(map[string]string) - for _, identity := range resolvedIdents { - if !identity.Handle.IsInvalidHandle() { - didHandleMap[identity.DID.String()] = fmt.Sprintf("@%s", identity.Handle.String()) - } else { - didHandleMap[identity.DID.String()] = identity.DID.String() - } - } - - // Create map of email to didOrHandle for commit display - emailToDidOrHandle := make(map[string]string) - for email, did := range emailToDidMap { - if didOrHandle, ok := didHandleMap[did]; ok { - emailToDidOrHandle[email] = didOrHandle - } - } - - return emailToDidOrHandle -} - func randomString(n int) string { const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" result := make([]byte, n) -- 2.43.0