Signed-off-by: Anirudh Oppiliappan anirudh@tangled.org
appview/ingester.go
appview/ingester.go
This file has not been changed.
+36
-38
appview/state/profile.go
+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
appview/state/router.go
This file has not been changed.
History
7 rounds
1 comment
anirudh.fi
submitted
#6
1 commit
expand
collapse
appview/state: handle profile pic uploads
Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>
expand 0 comments
pull request successfully merged
anirudh.fi
submitted
#5
1 commit
expand
collapse
appview/state: handle profile pic uploads
Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>
expand 0 comments
anirudh.fi
submitted
#4
1 commit
expand
collapse
appview/state: handle profile pic uploads
Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>
expand 0 comments
anirudh.fi
submitted
#3
1 commit
expand
collapse
appview/state: handle profile pic uploads
Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>
expand 0 comments
anirudh.fi
submitted
#2
1 commit
expand
collapse
appview/state: handle profile pic uploads
Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>
expand 0 comments
anirudh.fi
submitted
#1
1 commit
expand
collapse
appview/state: handle profile pic uploads
Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>
expand 1 comment
anirudh.fi
submitted
#0
1 commit
expand
collapse
appview/state: handle profile pic uploads
Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>
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: