backend for xcvr appview
2
fork

Configure Feed

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

clean up new oauth impl a bit

+149 -184
+16 -9
server/internal/db/db.go
··· 5 5 "errors" 6 6 "fmt" 7 7 "os" 8 + "rvcx/internal/atputils" 8 9 "rvcx/internal/types" 9 10 "time" 10 11 ··· 44 45 } 45 46 46 47 func (s *Store) ResolveHandle(handle string, ctx context.Context) (string, error) { 47 - rows, err := s.pool.Query(ctx, ` 48 + row := s.pool.QueryRow(ctx, ` 48 49 SELECT 49 50 h.did 50 51 FROM did_handles h 51 52 WHERE h.handle = $1 52 53 LIMIT 1 53 54 `, handle) 55 + var did string 56 + err := row.Scan(&did) 54 57 if err != nil { 55 58 return "", err 56 - } 57 - defer rows.Close() 58 - var did string 59 - for rows.Next() { 60 - err := rows.Scan(&did) 61 - if err != nil { 62 - return "", err 63 - } 64 59 } 65 60 return did, nil 66 61 } ··· 73 68 return "", errors.New("error scanning row for handle: " + err.Error()) 74 69 } 75 70 return handle, nil 71 + } 72 + 73 + func (s *Store) FullResolveDid(did string, ctx context.Context) (string, error) { 74 + hdl, err := s.ResolveDid(did, ctx) 75 + if err == nil { 76 + return hdl, nil 77 + } 78 + hdl, err = atputils.TryLookupDid(ctx, did) 79 + if err != nil { 80 + return "", errors.New("couldn't resolve: " + err.Error()) 81 + } 82 + return hdl, nil 76 83 } 77 84 78 85 func (s *Store) StoreDidHandle(did string, handle string, ctx context.Context) error {
+6 -6
server/internal/handler/handler.go
··· 28 28 h := &Handler{db, sessionStore, mux, logger, oauthserv, model, recordmanager} 29 29 // lrc handlers 30 30 mux.HandleFunc("GET /lrc/{user}/{rkey}/ws", h.WithCORS(h.acceptWebsocket)) 31 - mux.HandleFunc("DELETE /lrc/{user}/{rkey}/ws", h.deleteChannel) 32 - mux.HandleFunc("POST /lrc/channel", h.postChannel) 33 - mux.HandleFunc("POST /lrc/message", h.postMessage) 31 + mux.HandleFunc("DELETE /lrc/{user}/{rkey}/ws", h.oauthMiddleware(h.deleteChannel)) 32 + mux.HandleFunc("POST /lrc/channel", h.oauthMiddleware(h.postChannel)) 33 + mux.HandleFunc("POST /lrc/message", h.oauthMiddleware(h.postMessage)) 34 34 mux.HandleFunc("POST /lrc/mymessage", h.postMyMessage) 35 35 // xcvr handlers 36 - mux.HandleFunc("POST /xcvr/profile", h.postProfile) 37 - mux.HandleFunc("POST /xcvr/beep", h.beep) 36 + mux.HandleFunc("POST /xcvr/profile", h.oauthMiddleware(h.postProfile)) 37 + mux.HandleFunc("POST /xcvr/beep", h.oauthMiddleware(h.beep)) 38 38 // lexicon handlers 39 39 mux.HandleFunc("GET /xrpc/org.xcvr.feed.getChannels", h.WithCORS(h.getChannels)) 40 40 mux.HandleFunc("GET /xrpc/org.xcvr.lrc.getMessages", h.WithCORS(h.getMessages)) ··· 49 49 // oauth handlers 50 50 mux.HandleFunc(oauthJWKSPath(), h.WithCORS(h.serveJWKS)) 51 51 mux.HandleFunc("POST /oauth/login", h.oauthLogin) 52 - mux.HandleFunc("POST /oauth/logout", h.oauthLogout) 52 + mux.HandleFunc("POST /oauth/logout", h.oauthMiddleware(h.oauthLogout)) 53 53 mux.HandleFunc("GET /oauth/whoami", h.getSession) 54 54 mux.HandleFunc(oauthCallbackPath(), h.WithCORS(h.oauthCallback)) 55 55 return h
+16 -28
server/internal/handler/lrcHandlers.go
··· 5 5 "encoding/json" 6 6 "errors" 7 7 "fmt" 8 + atoauth "github.com/bluesky-social/indigo/atproto/auth/oauth" 8 9 "net/http" 9 10 "os" 10 11 "rvcx/internal/atputils" ··· 25 26 f(w, r) 26 27 } 27 28 28 - func (h *Handler) postChannel(w http.ResponseWriter, r *http.Request) { 29 + func (h *Handler) postChannel(cs *atoauth.ClientSession, w http.ResponseWriter, r *http.Request) { 29 30 cr, err := h.parseChannelRequest(r) 30 31 if err != nil { 31 32 h.badRequest(w, err) 32 33 return 33 34 } 34 - session, _ := h.sessionStore.Get(r, "oauthsession") 35 - id, ok := session.Values["id"].(string) 36 - var uri, did string 37 - if !ok { 35 + var did, uri string 36 + if cs == nil { 38 37 did, uri, err = h.rm.PostMyChannel(r.Context(), cr) 39 38 } else { 40 - udid, ok := session.Values["did"].(string) 41 - if !ok { 42 - h.badRequest(w, errors.New("user session has no did?")) 43 - return 44 - } 45 - did, uri, err = h.rm.PostChannel(id, udid, r.Context(), cr) 39 + did, uri, err = h.rm.PostChannel(cs, r.Context(), cr) 46 40 } 47 41 if err != nil { 48 42 h.serverError(w, err) ··· 81 75 return &mr, nil 82 76 } 83 77 84 - func (h *Handler) postMessage(w http.ResponseWriter, r *http.Request) { 78 + func (h *Handler) postMessage(cs *atoauth.ClientSession, w http.ResponseWriter, r *http.Request) { 85 79 pmr, err := h.parseMessageRequest(r) 86 80 if err != nil { 87 81 h.badRequest(w, errors.New("failed to parse message request: "+err.Error())) 88 82 return 89 83 } 90 - session, _ := h.sessionStore.Get(r, "oauthsession") 91 - id, ok := session.Values["id"].(string) 92 - if !ok { 84 + if cs == nil { 93 85 err = h.rm.PostMyMessage(r.Context(), pmr) 94 86 } else { 95 - did, ok := session.Values["did"].(string) 96 - if !ok { 97 - h.badRequest(w, errors.New("has sid but doesn't have sdid!")) 98 - } 99 - err = h.rm.PostMessage(id, did, r.Context(), pmr) 87 + err = h.rm.PostMessage(cs, r.Context(), pmr) 100 88 } 101 89 if err != nil { 102 90 h.serverError(w, errors.New("error posting message: "+err.Error())) ··· 118 106 w.Write(nil) 119 107 } 120 108 121 - func (h *Handler) deleteChannel(w http.ResponseWriter, r *http.Request) { 122 - did, handle, err := h.findDidAndHandle(r) 123 - if err != nil { 109 + func (h *Handler) deleteChannel(cs *atoauth.ClientSession, w http.ResponseWriter, r *http.Request) { 110 + if cs == nil { 124 111 h.logger.Deprintln("tried to anonymously delete") 125 112 return 126 113 } 127 114 rkey := r.PathValue("rkey") 128 115 user := r.PathValue("user") 129 - if did != user && handle != os.Getenv("ADMIN_HANDLE") { 130 - h.logger.Deprintln("tried to delete not logged in") 131 - return 116 + var err error 117 + if cs.Data.AccountDID.String() == user { 118 + err = h.rm.DeleteChannel(cs, rkey, r.Context()) 119 + } else if cs.Data.AccountDID.String() == os.Getenv("ADMIN_DID") { 120 + uri := fmt.Sprintf("at://%s/org.xcvr.feed.channel/%s", user, rkey) 121 + err = h.rm.AcceptChannelDelete(uri, r.Context()) 132 122 } 133 - uri := fmt.Sprintf("at://%s/org.xcvr.feed.channel/%s", user, rkey) 134 - err = h.db.DeleteChannel(uri, r.Context()) 135 123 if err != nil { 136 124 h.logger.Deprintln("failed to delete") 137 125 return
+37 -45
server/internal/handler/oauthHandlers.go
··· 6 6 "fmt" 7 7 "net/http" 8 8 "os" 9 - "rvcx/internal/atputils" 10 9 "rvcx/internal/oauth" 11 10 "strings" 12 11 12 + atoauth "github.com/bluesky-social/indigo/atproto/auth/oauth" 13 + "github.com/bluesky-social/indigo/atproto/syntax" 13 14 "github.com/gorilla/sessions" 14 15 ) 15 16 ··· 54 55 return 55 56 } 56 57 session, _ := h.sessionStore.Get(r, "oauthsession") 57 - if err != nil { 58 - h.serverError(w, err) 59 - return 60 - } 61 58 62 59 session.Options = &sessions.Options{ 63 60 Path: "/", ··· 87 84 } 88 85 89 86 func (h *Handler) getSession(w http.ResponseWriter, r *http.Request) { 90 - did, handle, err := h.findDidAndHandle(r) 91 - if err != nil { 92 - h.handleFindDidAndHandleError(w, err) 87 + s, _ := h.sessionStore.Get(r, "oauthsession") 88 + did, ok := s.Values["did"].(string) 89 + if !ok { 90 + h.notFound(w, errors.New("couldn't find profile")) 93 91 return 94 92 } 95 - h.serveProfileView(did, handle, w, r) 96 - } 97 - 98 - func (h *Handler) findDidAndHandle(r *http.Request) (string, string, error) { 99 - session, _ := h.sessionStore.Get(r, "oauthsession") 100 - did, ok := session.Values["did"].(string) 101 - if !ok || did == "" { 102 - return "", "", errors.New("not authenticated") 103 - } 104 - handle, err := h.db.ResolveDid(did, r.Context()) 93 + handle, err := h.db.FullResolveDid(did, r.Context()) 105 94 if err != nil { 106 - handle, err = atputils.GetHandleFromDid(r.Context(), did) 107 - if err != nil { 108 - return "", "", errors.New("error resolving handle" + err.Error()) 109 - } 110 - h.logger.Deprintln("storing...") 111 - err = h.db.StoreDidHandle(did, handle, r.Context()) 112 - if err != nil { 113 - h.logger.Deprintln("error storing did_handle in findDidAndHandle: " + err.Error()) 114 - } 115 - } 116 - return did, handle, nil 117 - } 118 - 119 - func (h *Handler) handleFindDidAndHandleError(w http.ResponseWriter, err error) { 120 - if err != nil { 121 - if err.Error() == "not authenticated" { 122 - http.Error(w, "not authenticated", http.StatusUnauthorized) 123 - return 124 - } 125 - h.serverError(w, err) 95 + h.notFound(w, errors.New("coudln't resolve did: "+err.Error())) 126 96 return 127 97 } 128 - h.logger.Deprintln("handling nil error?") 98 + h.serveProfileView(did, handle, w, r) 129 99 } 130 100 131 - func (h *Handler) oauthLogout(w http.ResponseWriter, r *http.Request) { 132 - s, _ := h.sessionStore.Get(r, "oauthsession") 133 - id, ok := s.Values["id"].(string) 134 - did, bok := s.Values["did"].(string) 135 - if ok && bok { 101 + func (h *Handler) oauthLogout(cs *atoauth.ClientSession, w http.ResponseWriter, r *http.Request) { 102 + if cs != nil { 136 103 h.logger.Deprintln("deleting session to log out!") 137 - err := h.rm.DeleteSession(did, id, r.Context()) 104 + err := h.db.DeleteSession(r.Context(), cs.Data.AccountDID, cs.Data.SessionID) 138 105 if err != nil { 139 106 h.serverError(w, errors.New("couldn't log out: "+err.Error())) 140 107 return 141 108 } 142 109 h.logger.Deprintln("deleted session to log out!") 143 110 } 111 + 112 + s, _ := h.sessionStore.Get(r, "oauthsession") 144 113 s.Values = make(map[any]any) 145 114 s.Options.MaxAge = -1 146 115 h.logger.Deprintln("saving cookie to log out!") ··· 152 121 h.logger.Deprintln("saved cookie to log out!") 153 122 http.Redirect(w, r, "/", http.StatusSeeOther) 154 123 } 124 + 125 + func (h *Handler) oauthMiddleware(f func(cs *atoauth.ClientSession, w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) { 126 + return func(w http.ResponseWriter, r *http.Request) { 127 + s, _ := h.sessionStore.Get(r, "oauthsession") 128 + id, ok := s.Values["id"].(string) 129 + did, bok := s.Values["did"].(string) 130 + if !ok || !bok { 131 + f(nil, w, r) 132 + return 133 + } 134 + sdid, err := syntax.ParseDID(did) 135 + if err != nil { 136 + f(nil, w, r) 137 + return 138 + } 139 + cs, err := h.oauth.ResumeSession(r.Context(), sdid, id) 140 + if err != nil { 141 + f(nil, w, r) 142 + return 143 + } 144 + f(cs, w, r) 145 + } 146 + }
+15 -18
server/internal/handler/xcvrHandlers.go
··· 3 3 import ( 4 4 "encoding/json" 5 5 "errors" 6 + atoauth "github.com/bluesky-social/indigo/atproto/auth/oauth" 6 7 "net/http" 7 8 "rvcx/internal/types" 8 9 ) 9 10 10 - func (h *Handler) postProfile(w http.ResponseWriter, r *http.Request) { 11 - did, handle, err := h.findDidAndHandle(r) 12 - if err != nil { 13 - h.handleFindDidAndHandleError(w, err) 11 + func (h *Handler) postProfile(cs *atoauth.ClientSession, w http.ResponseWriter, r *http.Request) { 12 + if cs == nil { 13 + h.badRequest(w, errors.New("must be logged in!")) 14 14 return 15 15 } 16 16 var p types.PostProfileRequest 17 17 decoder := json.NewDecoder(r.Body) 18 - err = decoder.Decode(&p) 18 + err := decoder.Decode(&p) 19 19 if err != nil { 20 20 h.badRequest(w, errors.New("error decoding post profile request: "+err.Error())) 21 21 return 22 22 } 23 - s, _ := h.sessionStore.Get(r, "oauthsession") 24 - id, ok := s.Values["id"].(string) 25 - if !ok { 26 - h.badRequest(w, errors.New("must be logged in!")) 27 - return 23 + err = h.rm.PostProfile(cs, r.Context(), &p) 24 + if err != nil { 25 + h.serverError(w, errors.New("erroring in postprofile flow: "+err.Error())) 28 26 } 29 - err = h.rm.PostProfile(did, id, r.Context(), &p) 27 + did := cs.Data.AccountDID.String() 28 + handle, err := h.db.FullResolveDid(did, r.Context()) 30 29 if err != nil { 31 - h.serverError(w, errors.New("erroring in postprofile flow: "+err.Error())) 30 + h.serverError(w, errors.New("error couldn't resolve did? "+err.Error())) 31 + return 32 32 } 33 33 h.serveProfileView(did, handle, w, r) 34 34 } 35 35 36 - func (h *Handler) beep(w http.ResponseWriter, r *http.Request) { 37 - s, _ := h.sessionStore.Get(r, "oauthsession") 38 - id, ok := s.Values["id"].(string) 39 - did, bok := s.Values["did"].(string) 40 - if !ok || !bok { 36 + func (h *Handler) beep(cs *atoauth.ClientSession, w http.ResponseWriter, r *http.Request) { 37 + if cs == nil { 41 38 h.badRequest(w, errors.New("must be logged in!")) 42 39 return 43 40 } 44 - err := h.rm.Beep(did, id, r.Context()) 41 + err := h.rm.Beep(cs, r.Context()) 45 42 if err != nil { 46 43 h.badRequest(w, err) 47 44 return
+33 -10
server/internal/oauth/oauthclient.go
··· 47 47 return nil, errors.New("failed to parse: " + err.Error()) 48 48 } 49 49 var getOut atproto.RepoGetRecord_Output 50 - err = c.Get(ctx, nsid, nil, &getOut) 50 + body := map[string]any{ 51 + "collection": "org.xcvr.actor.profile", 52 + "repo": *c.AccountDID, 53 + "rkey": "self", 54 + } 55 + err = c.Get(ctx, nsid, body, &getOut) 51 56 if err == nil { 52 57 if getOut.Cid != nil { 53 58 var jsonBytes []byte ··· 63 68 return &pro, nil 64 69 } 65 70 } 66 - body := map[string]any{ 67 - "collection": "org.xcvr.actor.profile", 68 - "repo": *c.AccountDID, 69 - "rkey": "self", 70 - "record": profile, 71 - } 71 + body["record"] = profile 72 72 var out atproto.RepoCreateRecord_Output 73 73 err = c.Post(ctx, "com.atproto.repo.createRecord", body, out) 74 74 if err != nil { ··· 81 81 func CreateXCVRChannel(cs *oauth.ClientSession, channel *lex.ChannelRecord, ctx context.Context) (uri string, cid string, err error) { 82 82 c := cs.APIClient() 83 83 body := map[string]any{ 84 - "collection": "org.xcvr.actor.profile", 84 + "collection": "org.xcvr.feed.channel", 85 85 "repo": *c.AccountDID, 86 86 "record": channel, 87 87 } 88 88 var out atproto.RepoCreateRecord_Output 89 89 err = c.Post(ctx, "com.atproto.repo.createRecord", body, out) 90 90 if err != nil { 91 - err = errors.New("oops! failed to create a profile: " + err.Error()) 91 + err = errors.New("oops! failed to create a channel: " + err.Error()) 92 92 return 93 93 } 94 94 uri = out.Uri ··· 96 96 return 97 97 } 98 98 99 + func DeleteXCVRChannel(cs *oauth.ClientSession, rkey string, ctx context.Context) error { 100 + c := cs.APIClient() 101 + var getOut atproto.RepoGetRecord_Output 102 + body := map[string]any{ 103 + "collection": "org.xcvr.feed.channel", 104 + "repo": *c.AccountDID, 105 + "rkey": rkey, 106 + } 107 + err := c.Get(ctx, "com.atproto.repo.getRecord", body, &getOut) 108 + if err != nil { 109 + return err 110 + } 111 + if getOut.Cid == nil { 112 + return nil 113 + } 114 + body["swapRecord"] = getOut.Cid 115 + err = c.Post(ctx, "com.atproto.repo.deleteRecord", body, nil) 116 + if err != nil { 117 + return err 118 + } 119 + return nil 120 + } 121 + 99 122 func CreateXCVRMessage(cs *oauth.ClientSession, message *lex.MessageRecord, ctx context.Context) (uri string, cid string, err error) { 100 123 c := cs.APIClient() 101 124 body := map[string]any{ 102 - "collection": "org.xcvr.actor.profile", 125 + "collection": "org.xcvr.lrc.message", 103 126 "repo": *c.AccountDID, 104 127 "record": message, 105 128 }
+3 -12
server/internal/recordmanager/beep.go
··· 2 2 3 3 import ( 4 4 "context" 5 - "errors" 6 - "github.com/bluesky-social/indigo/atproto/syntax" 5 + atoauth "github.com/bluesky-social/indigo/atproto/auth/oauth" 7 6 "rvcx/internal/oauth" 8 7 ) 9 8 10 - func (rm *RecordManager) Beep(id string, did string, ctx context.Context) error { 11 - sdid, err := syntax.ParseDID(did) 12 - if err != nil { 13 - return errors.New("aaaa bbeeeebpp : " + err.Error()) 14 - } 15 - client, err := rm.service.ResumeSession(ctx, sdid, id) 16 - if err != nil { 17 - return err 18 - } 19 - return oauth.MakeBskyPost(client, "beep_", ctx) 9 + func (rm *RecordManager) Beep(cs *atoauth.ClientSession, ctx context.Context) error { 10 + return oauth.MakeBskyPost(cs, "beep_", ctx) 20 11 }
+15 -13
server/internal/recordmanager/channel.go
··· 3 3 import ( 4 4 "context" 5 5 "errors" 6 + "fmt" 7 + atoauth "github.com/bluesky-social/indigo/atproto/auth/oauth" 6 8 "github.com/bluesky-social/indigo/atproto/syntax" 7 9 "rvcx/internal/atputils" 8 10 "rvcx/internal/lex" ··· 47 49 return rm.postchannelflow(rm.createMyChannel(), ctx, pcr) 48 50 } 49 51 50 - func (rm *RecordManager) PostChannel(sessionId string, udid string, ctx context.Context, pcr *types.PostChannelRequest) (did string, uri string, err error) { 51 - return rm.postchannelflow(rm.createChannel(sessionId, udid), ctx, pcr) 52 + func (rm *RecordManager) PostChannel(cs *atoauth.ClientSession, ctx context.Context, pcr *types.PostChannelRequest) (did string, uri string, err error) { 53 + return rm.postchannelflow(rm.createChannel(cs), ctx, pcr) 54 + } 55 + 56 + func (rm *RecordManager) DeleteChannel(cs *atoauth.ClientSession, rkey string, ctx context.Context) error { 57 + err := oauth.DeleteXCVRChannel(cs, rkey, ctx) 58 + if err != nil { 59 + return errors.New("failed to delete channel: " + err.Error()) 60 + } 61 + return rm.AcceptChannelDelete(fmt.Sprintf("at://%s/org.xcvr.feed.channel/%s", cs.Data.AccountDID.String(), rkey), ctx) 52 62 } 53 63 54 64 func (rm *RecordManager) postchannelflow(f func(*lex.ChannelRecord, *time.Time, context.Context) (*types.Channel, error), ctx context.Context, pcr *types.PostChannelRequest) (did string, uri string, err error) { ··· 93 103 return rm.broadcaster.UpdateChannel(c) 94 104 } 95 105 96 - func (rm *RecordManager) createChannel(sessionId string, did string) func(*lex.ChannelRecord, *time.Time, context.Context) (*types.Channel, error) { 106 + func (rm *RecordManager) createChannel(cs *atoauth.ClientSession) func(*lex.ChannelRecord, *time.Time, context.Context) (*types.Channel, error) { 97 107 return func(lcr *lex.ChannelRecord, now *time.Time, ctx context.Context) (*types.Channel, error) { 98 - sdid, err := syntax.ParseDID(did) 99 - if err != nil { 100 - return nil, err 101 - } 102 - client, err := rm.service.ResumeSession(ctx, sdid, sessionId) 103 - if err != nil { 104 - return nil, errors.New("couldn't get client") 105 - } 106 - uri, cid, err := oauth.CreateXCVRChannel(client, lcr, ctx) 108 + uri, cid, err := oauth.CreateXCVRChannel(cs, lcr, ctx) 107 109 if err != nil { 108 110 return nil, errors.New("something bad probs happened when posting a channel " + err.Error()) 109 111 } 110 112 channel := types.Channel{ 111 113 URI: uri, 112 114 CID: cid, 113 - DID: did, 115 + DID: cs.Data.AccountDID.String(), 114 116 Host: lcr.Host, 115 117 Title: lcr.Title, 116 118 Topic: lcr.Topic,
+6 -13
server/internal/recordmanager/message.go
··· 3 3 import ( 4 4 "context" 5 5 "errors" 6 + atoauth "github.com/bluesky-social/indigo/atproto/auth/oauth" 6 7 "github.com/bluesky-social/indigo/atproto/syntax" 7 8 "github.com/rachel-mp4/lrcd" 8 9 "os" ··· 69 70 return nil 70 71 } 71 72 72 - func (rm *RecordManager) PostMessage(sessionId string, udid string, ctx context.Context, pmr *types.PostMessageRequest) error { 73 + func (rm *RecordManager) PostMessage(cs *atoauth.ClientSession, ctx context.Context, pmr *types.PostMessageRequest) error { 73 74 rm.log.Deprintln("validate") 74 75 lmr, now, _, _, err := rm.validateMessage(pmr, ctx) 75 76 if err != nil { 76 77 return errors.New("failed to validate message: " + err.Error()) 77 78 } 78 79 rm.log.Deprintln("create") 79 - m, err := rm.createMessage(udid, sessionId, lmr, now, ctx) 80 + m, err := rm.createMessage(cs, lmr, now, ctx) 80 81 if err != nil { 81 82 return errors.New("failed to create message: " + err.Error()) 82 83 } ··· 155 156 return message, nil 156 157 } 157 158 158 - func (rm *RecordManager) createMessage(did string, sessionID string, lmr *lex.MessageRecord, now *time.Time, ctx context.Context) (*types.Message, error) { 159 - sdid, err := syntax.ParseDID(did) 160 - if err != nil { 161 - return nil, errors.New(" error: " + err.Error()) 162 - } 163 - client, err := rm.service.ResumeSession(ctx, sdid, sessionID) 164 - if err != nil { 165 - return nil, errors.New("failed to get client: " + err.Error()) 166 - } 167 - uri, cid, err := oauth.CreateXCVRMessage(client, lmr, ctx) 159 + func (rm *RecordManager) createMessage(cs *atoauth.ClientSession, lmr *lex.MessageRecord, now *time.Time, ctx context.Context) (*types.Message, error) { 160 + uri, cid, err := oauth.CreateXCVRMessage(cs, lmr, ctx) 168 161 if err != nil { 169 162 return nil, errors.New("couldn't add to user repo: " + err.Error()) 170 163 } ··· 175 168 } 176 169 message := &types.Message{ 177 170 URI: uri, 178 - DID: did, 171 + DID: cs.Data.AccountDID.String(), 179 172 CID: cid, 180 173 SignetURI: lmr.SignetURI, 181 174 Body: lmr.Body,
+2 -11
server/internal/recordmanager/profile.go
··· 10 10 "rvcx/internal/types" 11 11 12 12 atoauth "github.com/bluesky-social/indigo/atproto/auth/oauth" 13 - "github.com/bluesky-social/indigo/atproto/syntax" 14 13 ) 15 14 16 15 func (rm *RecordManager) AcceptProfile(p lex.ProfileRecord, did string, ctx context.Context) error { ··· 73 72 74 73 } 75 74 76 - func (rm *RecordManager) PostProfile(did string, sessionID string, ctx context.Context, p *types.PostProfileRequest) error { 77 - sdid, err := syntax.ParseDID(did) 78 - if err != nil { 79 - return errors.New("bad: " + err.Error()) 80 - } 81 - pu, err := rm.validateProfile(did, p) 75 + func (rm *RecordManager) PostProfile(cs *atoauth.ClientSession, ctx context.Context, p *types.PostProfileRequest) error { 76 + pu, err := rm.validateProfile(cs.Data.AccountDID.String(), p) 82 77 if err != nil { 83 78 return errors.New("couldn't validate profile: " + err.Error()) 84 - } 85 - cs, err := rm.service.ResumeSession(ctx, sdid, sessionID) 86 - if err != nil { 87 - return errors.New("couldn't resume session: " + err.Error()) 88 79 } 89 80 err = rm.updateProfile(cs, p.DisplayName, p.DefaultNick, p.Status, p.Color, ctx) 90 81 if err != nil {
-19
server/internal/recordmanager/session.go
··· 1 - package recordmanager 2 - 3 - import ( 4 - "context" 5 - "errors" 6 - "github.com/bluesky-social/indigo/atproto/syntax" 7 - ) 8 - 9 - func (rm *RecordManager) DeleteSession(did string, sessionID string, ctx context.Context) error { 10 - sdid, err := syntax.ParseDID(did) 11 - if err != nil { 12 - return errors.New("beep boop : " + err.Error()) 13 - } 14 - err = rm.db.DeleteSession(ctx, sdid, sessionID) 15 - if err != nil { 16 - return errors.New("failed to delete session: " + err.Error()) 17 - } 18 - return nil 19 - }