Monorepo for Tangled tangled.org

appview/profile: show dummy profile when no tangled profile #1051

merged opened by lewis.moe targeting master from lewis.moe/tangled-core: push-pzoouymnzvnq
Labels

None yet.

assignee

None yet.

Participants 3
AT URI
at://did:plc:3fwecdnvtcscjnrx2p4n7alz/sh.tangled.repo.pull/3me4obj5tra22
+40 -6
Diff #0
+1 -3
appview/db/profile.go
··· 360 did, 361 ).Scan(&avatar, &profile.Description, &includeBluesky, &profile.Location, &pronouns) 362 if err == sql.ErrNoRows { 363 - profile := models.Profile{} 364 - profile.Did = did 365 - return &profile, nil 366 } 367 368 if err != nil {
··· 360 did, 361 ).Scan(&avatar, &profile.Description, &includeBluesky, &profile.Location, &pronouns) 362 if err == sql.ErrNoRows { 363 + return nil, nil 364 } 365 366 if err != nil {
+2 -2
appview/oauth/handler.go
··· 199 did := sessData.AccountDID.String() 200 l := o.Logger.With("did", did) 201 202 - _, err := db.GetProfile(o.Db, did) 203 - if err == nil { 204 l.Debug("profile already exists in DB") 205 return 206 }
··· 199 did := sessData.AccountDID.String() 200 l := o.Logger.With("did", did) 201 202 + profile, _ := db.GetProfile(o.Db, did) 203 + if profile != nil { 204 l.Debug("profile already exists in DB") 205 return 206 }
+1
appview/pages/pages.go
··· 523 524 type ProfileCard struct { 525 UserDid string 526 FollowStatus models.FollowStatus 527 Punchcard *models.Punchcard 528 Profile *models.Profile
··· 523 524 type ProfileCard struct { 525 UserDid string 526 + HasProfile bool 527 FollowStatus models.FollowStatus 528 Punchcard *models.Punchcard 529 Profile *models.Profile
+13
appview/pages/templates/layouts/profilebase.html
··· 18 {{ end }} 19 20 {{ define "content" }} 21 {{ template "profileTabs" . }} 22 <section class="bg-white dark:bg-gray-800 px-2 py-6 md:p-6 rounded w-full dark:text-white drop-shadow-sm"> 23 <div class="grid grid-cols-1 md:grid-cols-11 gap-4"> ··· 35 {{ block "profileContent" . }} {{ end }} 36 </div> 37 </section> 38 {{ end }} 39 40 {{ define "profileTabs" }}
··· 18 {{ end }} 19 20 {{ define "content" }} 21 + {{ if not .Card.HasProfile }} 22 + <section class="bg-white dark:bg-gray-800 px-2 py-6 md:p-6 rounded w-full dark:text-white drop-shadow-sm"> 23 + <div class="flex items-center gap-6 p-4"> 24 + <img class="w-28 h-28 shrink-0 object-cover rounded-full" src="{{ profileAvatarUrl .Card.Profile "" }}" /> 25 + <div> 26 + <p class="text-lg font-bold">{{ resolve .Card.UserDid }}</p> 27 + <p class="text-gray-700 dark:text-gray-300 mt-2">This user hasn't joined Tangled yet.</p> 28 + <p class="text-sm text-gray-500 dark:text-gray-400 mt-1">Let them know we're waiting for them!</p> 29 + </div> 30 + </div> 31 + </section> 32 + {{ else }} 33 {{ template "profileTabs" . }} 34 <section class="bg-white dark:bg-gray-800 px-2 py-6 md:p-6 rounded w-full dark:text-white drop-shadow-sm"> 35 <div class="grid grid-cols-1 md:grid-cols-11 gap-4"> ··· 47 {{ block "profileContent" . }} {{ end }} 48 </div> 49 </section> 50 + {{ end }} 51 {{ end }} 52 53 {{ define "profileTabs" }}
+22
appview/state/profile.go
··· 58 return nil, fmt.Errorf("failed to get profile: %w", err) 59 } 60 61 repoCount, err := db.CountRepos(s.db, orm.FilterEq("did", did)) 62 if err != nil { 63 return nil, fmt.Errorf("failed to get repo count: %w", err) ··· 98 99 return &pages.ProfileCard{ 100 UserDid: did, 101 Profile: profile, 102 FollowStatus: followStatus, 103 Stats: pages.ProfileStats{ ··· 533 if err != nil { 534 log.Printf("getting profile data for %s: %s", user.Active.Did, err) 535 } 536 537 profile.Description = r.FormValue("description") 538 profile.IncludeBluesky = r.FormValue("includeBluesky") == "on" ··· 581 if err != nil { 582 log.Printf("getting profile data for %s: %s", user.Active.Did, err) 583 } 584 585 i := 0 586 var pinnedRepos [6]syntax.ATURI ··· 681 if err != nil { 682 log.Printf("getting profile data for %s: %s", user.Active.Did, err) 683 } 684 685 s.pages.EditBioFragment(w, pages.EditBioParams{ 686 LoggedInUser: user, ··· 695 if err != nil { 696 log.Printf("getting profile data for %s: %s", user.Active.Did, err) 697 } 698 699 repos, err := db.GetRepos(s.db, 0, orm.FilterEq("did", user.Active.Did)) 700 if err != nil { ··· 821 profile, err := db.GetProfile(s.db, user.Did) 822 if err != nil { 823 l.Warn("getting profile data from DB", "err", err) 824 profile = &models.Profile{Did: user.Did} 825 } 826 profile.Avatar = uploadBlobResp.Blob.Ref.String() ··· 897 profile, err := db.GetProfile(s.db, user.Did) 898 if err != nil { 899 l.Warn("getting profile data from DB", "err", err) 900 profile = &models.Profile{Did: user.Did} 901 } 902 profile.Avatar = ""
··· 58 return nil, fmt.Errorf("failed to get profile: %w", err) 59 } 60 61 + hasProfile := profile != nil 62 + if !hasProfile { 63 + profile = &models.Profile{Did: did} 64 + } 65 + 66 repoCount, err := db.CountRepos(s.db, orm.FilterEq("did", did)) 67 if err != nil { 68 return nil, fmt.Errorf("failed to get repo count: %w", err) ··· 103 104 return &pages.ProfileCard{ 105 UserDid: did, 106 + HasProfile: hasProfile, 107 Profile: profile, 108 FollowStatus: followStatus, 109 Stats: pages.ProfileStats{ ··· 539 if err != nil { 540 log.Printf("getting profile data for %s: %s", user.Active.Did, err) 541 } 542 + if profile == nil { 543 + profile = &models.Profile{Did: user.Active.Did} 544 + } 545 546 profile.Description = r.FormValue("description") 547 profile.IncludeBluesky = r.FormValue("includeBluesky") == "on" ··· 590 if err != nil { 591 log.Printf("getting profile data for %s: %s", user.Active.Did, err) 592 } 593 + if profile == nil { 594 + profile = &models.Profile{Did: user.Active.Did} 595 + } 596 597 i := 0 598 var pinnedRepos [6]syntax.ATURI ··· 693 if err != nil { 694 log.Printf("getting profile data for %s: %s", user.Active.Did, err) 695 } 696 + if profile == nil { 697 + profile = &models.Profile{Did: user.Active.Did} 698 + } 699 700 s.pages.EditBioFragment(w, pages.EditBioParams{ 701 LoggedInUser: user, ··· 710 if err != nil { 711 log.Printf("getting profile data for %s: %s", user.Active.Did, err) 712 } 713 + if profile == nil { 714 + profile = &models.Profile{Did: user.Active.Did} 715 + } 716 717 repos, err := db.GetRepos(s.db, 0, orm.FilterEq("did", user.Active.Did)) 718 if err != nil { ··· 839 profile, err := db.GetProfile(s.db, user.Did) 840 if err != nil { 841 l.Warn("getting profile data from DB", "err", err) 842 + } 843 + if profile == nil { 844 profile = &models.Profile{Did: user.Did} 845 } 846 profile.Avatar = uploadBlobResp.Blob.Ref.String() ··· 917 profile, err := db.GetProfile(s.db, user.Did) 918 if err != nil { 919 l.Warn("getting profile data from DB", "err", err) 920 + } 921 + if profile == nil { 922 profile = &models.Profile{Did: user.Did} 923 } 924 profile.Avatar = ""
+1 -1
appview/state/state.go
··· 126 wrapper, 127 false, 128 129 - // in-memory filter is inapplicalble to appview so 130 // we'll never log dids anyway. 131 false, 132 )
··· 126 wrapper, 127 false, 128 129 + // in-memory filter is inapplicable to appview so 130 // we'll never log dids anyway. 131 false, 132 )

History

1 round 5 comments
sign up or login to add to the discussion
lewis.moe submitted #0
1 commit
expand
appview/profile: show dummy profile when no tangled profile
expand 5 comments

Currently this just relies on tangled's own db of having correctly pulled a profile record at time of streaming on the jetstream. I avoided overengineering an async request to the PDS to verify that there might be a tangled profile record after the fact. Just lmk if we should do that too :P

Like:

  1. I load the page for obama, tangled says no profile just from db
  2. behind the scenes, tangled backend pings obama's pds just in case he does in fact have a profile record after the fact
  3. tangled htmx updates the display of obama's profile to me inline in the page

Was testing it out and funnily enough, it shows me no profile for https://tangled.wizardry.systems/anirudh.fi.

that's because tangled.wizardry.systems doesn't have perfect backfill unfortunately, I think I'm lucky to even have as many saved profiles as I do

Fair enough; code LGTM! I'll test this out locally to confirm.

pull request successfully merged