Monorepo for Tangled tangled.org

appview/pages: upload and render avatar #894

merged opened by anirudh.fi targeting master from icy/tolqpt
Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:hwevmowznbiukdf6uk5dwrrq/sh.tangled.repo.pull/3m7znwnzq6k22
+20 -38
Interdiff #1 #2
+20 -38
appview/pages/funcmap.go
··· 360 "fullAvatar": func(handle string) string { 361 return p.AvatarUrl(handle, "") 362 }, 363 "profileAvatarUrl": func(profile *models.Profile, size string) string { 364 - return p.ProfileAvatarUrl(profile, size) 365 }, 366 "langColor": enry.GetColor, 367 "layoutSide": func() string { ··· 415 416 417 return fmt.Sprintf("%s/%s/%s?%s", p.avatar.Host, signature, handle, sizeArg) 418 - } 419 - 420 - func (p *Pages) ProfileAvatarUrl(profile *models.Profile, size string) string { 421 - if profile != nil && profile.Avatar != "" { 422 - ident, err := p.resolver.ResolveIdent(context.Background(), profile.Did) 423 - if err == nil && ident.PDSEndpoint() != "" { 424 - blobUrl := fmt.Sprintf("%s/xrpc/com.atproto.sync.getBlob?did=%s&cid=%s", 425 - ident.PDSEndpoint(), 426 - profile.Did, 427 - profile.Avatar) 428 - 429 - handle := strings.TrimPrefix(profile.Did, "@") 430 - handle = p.resolveDid(handle) 431 - 432 - secret := p.avatar.SharedSecret 433 - h := hmac.New(sha256.New, []byte(secret)) 434 - h.Write([]byte(handle)) 435 - signature := hex.EncodeToString(h.Sum(nil)) 436 - 437 - sizeArg := "" 438 - if size != "" { 439 - sizeArg = fmt.Sprintf("&size=%s", size) 440 - } 441 - 442 - return fmt.Sprintf("%s/%s/%s?blob=%s%s", 443 - p.avatar.Host, 444 - signature, 445 - handle, 446 - url.QueryEscape(blobUrl), 447 - sizeArg) 448 - } 449 - } 450 - 451 - if profile != nil { 452 - return p.AvatarUrl(profile.Did, size) 453 - } 454 - return "" 455 } 456 457 func (p *Pages) icon(name string, classes []string) (template.HTML, error) {
··· 360 "fullAvatar": func(handle string) string { 361 return p.AvatarUrl(handle, "") 362 }, 363 + "placeholderAvatar": func(size string) template.HTML { 364 + sizeClass := "size-6" 365 + iconSize := "size-4" 366 + if size == "tiny" { 367 + sizeClass = "size-6" 368 + iconSize = "size-4" 369 + } else if size == "small" { 370 + sizeClass = "size-8" 371 + iconSize = "size-5" 372 + } else { 373 + sizeClass = "size-12" 374 + iconSize = "size-8" 375 + } 376 + icon, _ := p.icon("user-round", []string{iconSize, "text-gray-400", "dark:text-gray-500"}) 377 + return template.HTML(fmt.Sprintf(`<div class="%s rounded-full bg-gray-200 dark:bg-gray-700 flex items-center justify-center flex-shrink-0">%s</div>`, sizeClass, icon)) 378 + }, 379 "profileAvatarUrl": func(profile *models.Profile, size string) string { 380 + if profile != nil { 381 + return p.AvatarUrl(profile.Did, size) 382 + } 383 + return "" 384 }, 385 "langColor": enry.GetColor, 386 "layoutSide": func() string { ··· 434 435 436 return fmt.Sprintf("%s/%s/%s?%s", p.avatar.Host, signature, handle, sizeArg) 437 } 438 439 func (p *Pages) icon(name string, classes []string) (template.HTML, error) {
appview/pages/templates/layouts/profilebase.html

This file has not been changed.

appview/pages/templates/user/fragments/editAvatar.html

This file has not been changed.

appview/pages/templates/user/fragments/profileCard.html

This file has not been changed.

appview/pages/templates/user/settings/emails.html

This file has not been changed.

appview/pages/templates/user/settings/keys.html

This file has not been changed.

History

7 rounds 2 comments
sign up or login to add to the discussion
1 commit
expand
appview/pages: upload and render avatar
3/3 success
expand
expand 0 comments
pull request successfully merged
1 commit
expand
appview/pages: upload and render avatar
3/3 success
expand
expand 0 comments
1 commit
expand
appview/pages: upload and render avatar
3/3 success
expand
expand 0 comments
1 commit
expand
appview/pages: upload and render avatar
3/3 success
expand
expand 0 comments
1 commit
expand
appview/pages: upload and render avatar
expand 0 comments
1 commit
expand
appview/pages: upload and render avatar
expand 2 comments
  • profileAvatarUrl is only used where models.Profile is available, is the uploaded profile picture not rendered across the board? (the previous PR in the stack implies otherwise, in which case, why do we need any special logic for avatar URLs on the appview?)
  • this resolves handle again, we already have a resolved identity in ident
  • there is repetition between ProfileAvatarUrl and AvatarUrl (the signature calculation logic is duplicated)

profileAvatarUrl is only used where models.Profile is available, is the uploaded profile picture not rendered across the board? (the previous PR in the stack implies otherwise, in which case, why do we need any special logic for avatar URLs on the appview?)

it exists to construct the blob url to to fetch from the pds. the avatar service merely checks if a blob url has been provided (if not, fallback to bsky). i could clean this up though, i didn't particularly like it myself.

1 commit
expand
appview/pages: upload and render avatar
expand 0 comments