backend for xcvr appview
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

publish profile record to user repository

rachel-mp4 7e2107e8 78743560

+92 -17
+9 -14
server/internal/db/lexicon.go
··· 1 1 package db 2 2 3 3 import ( 4 - "strings" 5 4 "context" 5 + "errors" 6 6 "fmt" 7 + "strings" 7 8 "xcvr-backend/internal/types" 8 - "errors" 9 9 ) 10 10 11 11 func (s *Store) InitializeProfile(did string, handle string, ctx context.Context) error { ··· 19 19 ) VALUES ( 20 20 $1, $2, $3, $4, $5 21 21 ) ON CONFLICT (did) DO NOTHING 22 - `, did, handle, "wanderer", "just setting up my xcvr", 12517472) 22 + `, did, handle, "wanderer", "just setting up my xcvr", 3702605) 23 23 if err != nil { 24 24 return errors.New("i'm not sure what happened: " + err.Error()) 25 25 } ··· 38 38 UpdateAvatar bool 39 39 Mime *string 40 40 UpdateMime bool 41 - Color *uint32 41 + Color *uint64 42 42 UpdateColor bool 43 43 } 44 44 ··· 79 79 if idx == 2 { 80 80 return nil 81 81 } 82 - sql := fmt.Sprintf("UPDATE profiles SET %s WHERE did = $1", 82 + sql := fmt.Sprintf("UPDATE profiles SET %s WHERE did = $1", 83 83 strings.Join(setParts, ", ")) 84 84 _, err := s.pool.Exec(ctx, sql, args...) 85 85 if err != nil { ··· 100 100 `, did) 101 101 var p types.ProfileView 102 102 p.DID = did 103 - err := row.Scan(&p.DisplayName, 104 - &p.DefaultNick, 105 - &p.Status, 106 - &p.Avatar, 103 + err := row.Scan(&p.DisplayName, 104 + &p.DefaultNick, 105 + &p.Status, 106 + &p.Avatar, 107 107 &p.Color) 108 108 if err != nil { 109 109 return nil, errors.New("error scanning profile: " + err.Error()) 110 110 } 111 111 return &p, nil 112 112 } 113 - 114 - 115 - 116 - 117 -
+19
server/internal/handler/oauthHandlers.go
··· 9 9 "net/url" 10 10 "os" 11 11 "xcvr-backend/internal/atputils" 12 + "xcvr-backend/internal/lex" 12 13 "xcvr-backend/internal/oauth" 13 14 14 15 "github.com/gorilla/sessions" ··· 127 128 h.serverError(w, err) 128 129 return 129 130 } 131 + go func() { 132 + nick := "wanderer" 133 + status := "just setting up my xcvr" 134 + color := uint64(3602605) 135 + handle, err := h.db.ResolveDid(req.Did, context.Background()) 136 + if err != nil { 137 + h.logger.Println("i couldn't find the handle, so i couldn't create default profile record. gootbye") 138 + return 139 + } 140 + 141 + defaultprofilerecord := lex.ProfileRecord{ 142 + DisplayName: &handle, 143 + DefaultNick: &nick, 144 + Status: &status, 145 + Color: &color, 146 + } 147 + h.xrpc.CreateXCVRProfile(defaultprofilerecord, OauthSession, context.Background()) 148 + }() 130 149 131 150 session.Options = &sessions.Options{ 132 151 Path: "/",
+19
server/internal/handler/xcvrHandlers.go
··· 7 7 "net/http" 8 8 "unicode/utf16" 9 9 "xcvr-backend/internal/db" 10 + "xcvr-backend/internal/lex" 10 11 "xcvr-backend/internal/types" 11 12 ) 12 13 ··· 81 82 return 82 83 } 83 84 85 + //TODO switch order, only update db after we know the xrpc req went through correctly! 86 + 87 + session, _ := h.sessionStore.Get(r, "oauthsession") 88 + did, ok := session.Values["did"].(string) 89 + if !ok || did == "" { 90 + h.badRequest(w, errors.New("cannot beep, not authenticated")) 91 + } 92 + s, err := h.db.GetOauthSesson(did, r.Context()) 93 + profilerecord := lex.ProfileRecord{ 94 + DisplayName: p.DisplayName, 95 + DefaultNick: p.DefaultNick, 96 + Status: p.Status, 97 + Color: p.Color, 98 + } 99 + err = h.xrpc.UpdateXCVRProfile(profilerecord, s, r.Context()) 100 + if err != nil { 101 + h.logger.Deprintf("error updating profilerecord: %s", err.Error()) 102 + } 84 103 h.serveProfileView(did, handle, w, r) 85 104 } 86 105
+42
server/internal/oauth/xrpcclient.go
··· 9 9 "github.com/bluesky-social/indigo/lex/util" 10 10 "github.com/haileyok/atproto-oauth-golang" 11 11 "github.com/haileyok/atproto-oauth-golang/helpers" 12 + 12 13 "xcvr-backend/internal/db" 14 + "xcvr-backend/internal/lex" 13 15 "xcvr-backend/internal/log" 14 16 "xcvr-backend/internal/types" 15 17 ) ··· 67 69 } 68 70 return nil 69 71 } 72 + 73 + func (c *Client) CreateXCVRProfile(profile lex.ProfileRecord, s *types.Session, ctx context.Context) error { 74 + authargs, err := getOauthSessionAuthArgs(s) 75 + if err != nil { 76 + return errors.New("failed to get oauthsessionauthargs while making post: " + err.Error()) 77 + } 78 + rkey := "self" 79 + input := atproto.RepoCreateRecord_Input{ 80 + Collection: "org.xcvr.actor.profile", 81 + Repo: authargs.Did, 82 + Rkey: &rkey, 83 + Record: &util.LexiconTypeDecoder{Val: &profile}, 84 + } 85 + var out atproto.RepoCreateRecord_Output 86 + err = c.xrpccli.Do(ctx, authargs, "POST", "application/json", "com.atproto.repo.createRecord", nil, input, &out) 87 + if err != nil { 88 + return errors.New("oops! failed to create a profile: " + err.Error()) 89 + } 90 + return nil 91 + } 92 + 93 + func (c *Client) UpdateXCVRProfile(profile lex.ProfileRecord, s *types.Session, ctx context.Context) error { 94 + authargs, err := getOauthSessionAuthArgs(s) 95 + if err != nil { 96 + return errors.New("failed to get oauthsessionauthargs while making post: " + err.Error()) 97 + } 98 + rkey := "self" 99 + input := atproto.RepoPutRecord_Input{ 100 + Collection: "org.xcvr.actor.profile", 101 + Repo: authargs.Did, 102 + Rkey: rkey, 103 + Record: &util.LexiconTypeDecoder{Val: &profile}, 104 + } 105 + var out atproto.RepoPutRecord_Output 106 + err = c.xrpccli.Do(ctx, authargs, "POST", "application/json", "com.atproto.repo.createRecord", nil, input, &out) 107 + if err != nil { 108 + return errors.New("oops! failed to create a profile: " + err.Error()) 109 + } 110 + return nil 111 + }
+3 -3
server/internal/types/lexicons.go
··· 9 9 Status *string 10 10 AvatarCID *string 11 11 AvatarMIME *string 12 - Color *uint32 12 + Color *uint64 13 13 IndexedAt time.Time 14 14 } 15 15 16 16 type PostProfileRequest struct { 17 17 DisplayName *string `json:"displayName,omitempty"` 18 18 Status *string `json:"status,omitempty"` 19 - Color *uint32 `json:"color,omitempty"` 19 + Color *uint64 `json:"color,omitempty"` 20 20 Avatar *string `json:"avatar,omitempty"` 21 21 DefaultNick *string `json:"defaultNick,omitempty"` 22 22 } ··· 26 26 Handle string `json:"handle"` 27 27 DisplayName *string `json:"displayName,omitempty"` 28 28 Status *string `json:"status,omitempty"` 29 - Color *uint32 `json:"color,omitempty"` 29 + Color *uint64 `json:"color,omitempty"` 30 30 Avatar *string `json:"avatar,omitempty"` 31 31 DefaultNick *string `json:"defaultNick,omitempty"` 32 32 }