Monorepo for Tangled tangled.org

appview/state: handle profile pic uploads #892

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/3m7znwnzpve22
+36 -38
Interdiff #0 #1
appview/ingester.go

This file has not been changed.

+36 -38
appview/state/profile.go
··· 802 802 return 803 803 } 804 804 805 - profile, err := db.GetProfile(s.db, user.Did) 806 - if err != nil { 807 - l.Warn("getting profile data from DB", "err", err) 808 - profile = &models.Profile{Did: user.Did} 809 - } 810 - 811 - profile.Avatar = uploadBlobResp.Blob.Ref.String() 812 - 813 - profileRecord := &tangled.ActorProfile{ 814 - Avatar: uploadBlobResp.Blob, 815 - Bluesky: profile.IncludeBluesky, 816 - } 817 - 818 - if profile.Description != "" { 819 - profileRecord.Description = &profile.Description 820 - } 821 - if profile.Location != "" { 822 - profileRecord.Location = &profile.Location 823 - } 824 - if profile.Pronouns != "" { 825 - profileRecord.Pronouns = &profile.Pronouns 826 - } 827 - 828 - for _, link := range profile.Links { 829 - if link != "" { 830 - profileRecord.Links = append(profileRecord.Links, link) 805 + var profileRecord *tangled.ActorProfile 806 + if getRecordResp.Value != nil { 807 + if val, ok := getRecordResp.Value.Val.(*tangled.ActorProfile); ok { 808 + profileRecord = val 809 + } else { 810 + l.Warn("profile record type assertion failed, creating new record") 811 + profileRecord = &tangled.ActorProfile{} 831 812 } 813 + } else { 814 + l.Warn("no existing profile record, creating new record") 815 + profileRecord = &tangled.ActorProfile{} 832 816 } 833 817 834 - for _, stat := range profile.Stats { 835 - if stat.Kind != "" { 836 - profileRecord.Stats = append(profileRecord.Stats, string(stat.Kind)) 837 - } 838 - } 818 + profileRecord.Avatar = uploadBlobResp.Blob 839 819 840 - for _, pin := range profile.PinnedRepos { 841 - if pin != "" { 842 - profileRecord.PinnedRepositories = append(profileRecord.PinnedRepositories, string(pin)) 843 - } 844 - } 845 - 846 820 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 847 821 Collection: tangled.ActorProfileNSID, 848 822 Repo: user.Did, ··· 860 834 861 835 l.Info("successfully updated profile with avatar") 862 836 863 - s.pages.HxRefresh(w) 837 + profile, err := db.GetProfile(s.db, user.Did) 838 + if err != nil { 839 + l.Warn("getting profile data from DB", "err", err) 840 + profile = &models.Profile{Did: user.Did} 841 + } 842 + profile.Avatar = uploadBlobResp.Blob.Ref.String() 843 + 844 + tx, err := s.db.BeginTx(r.Context(), nil) 845 + if err != nil { 846 + l.Error("failed to start transaction", "err", err) 847 + s.pages.HxRefresh(w) 848 + w.WriteHeader(http.StatusOK) 849 + return 850 + } 851 + 852 + err = db.UpsertProfile(tx, profile) 853 + if err != nil { 854 + l.Error("failed to update profile in DB", "err", err) 855 + tx.Rollback() 856 + s.pages.HxRefresh(w) 857 + w.WriteHeader(http.StatusOK) 858 + return 859 + } 860 + 861 + w.Header().Set("HX-Redirect", r.Header.Get("Referer")) 864 862 w.WriteHeader(http.StatusOK) 865 863 }
appview/state/router.go

This file has not been changed.

History

7 rounds 1 comment
sign up or login to add to the discussion
1 commit
expand
appview/state: handle profile pic uploads
expand 0 comments
pull request successfully merged
1 commit
expand
appview/state: handle profile pic uploads
expand 0 comments
1 commit
expand
appview/state: handle profile pic uploads
expand 0 comments
1 commit
expand
appview/state: handle profile pic uploads
expand 0 comments
1 commit
expand
appview/state: handle profile pic uploads
expand 0 comments
1 commit
expand
appview/state: handle profile pic uploads
expand 1 comment

we need similar logic to accept the blob CID from firehose ingester here. the existing ingester will include a null CID because it uses this constructor:

		profile := models.Profile{
			Did:            did,
			Description:    description,
			IncludeBluesky: includeBluesky,
			Location:       location,
			Links:          links,
			Stats:          stats,
			PinnedRepos:    pinned,
			Pronouns:       pronouns,
		}
1 commit
expand
appview/state: handle profile pic uploads
expand 0 comments