Atproto-backed clone of meetinghouse.cc. atlas.whiteley.io
atproto
0
fork

Configure Feed

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

Adds PDS sync for previously-placed pins

+58 -6
+47 -2
handlers/atproto.go
··· 8 8 "time" 9 9 10 10 "github.com/bluesky-social/indigo/api/atproto" 11 + "github.com/bluesky-social/indigo/atproto/atclient" 11 12 "github.com/bluesky-social/indigo/atproto/syntax" 12 13 "github.com/bluesky-social/indigo/lex/util" 13 14 ) 14 15 15 - func (s *Server) PutPinRecord(session models.Session, pin models.Pin) string { 16 + func (s *Server) PutPinRecord(session models.Session, pin models.Pin) (string, error) { 16 17 client, _ := s.OAuth.ResumeSession(context.Background(), *session.DID, session.SessionID) 17 18 at := client.APIClient() 18 19 ··· 38 39 39 40 if err := at.Post(context.Background(), "com.atproto.repo.createRecord", pinRecord, &response); err != nil { 40 41 slog.Error("PutRecord request failed", "err", err) 42 + return "", err 41 43 42 44 } 43 45 44 46 pinURI := response.Uri.String() 45 47 slog.Info("Atproto createRecord request successful", "pinURI", pinURI) 46 48 47 - return pinURI 49 + return pinURI, nil 48 50 } 49 51 50 52 func (s *Server) DeletePinRecord(session models.Session) { ··· 65 67 66 68 slog.Info("Atproto createRecord request successful", "DID", session.DID.String()) 67 69 } 70 + 71 + func (s *Server) SyncUserPin(did string, client *atclient.APIClient, name string, handle string, avatar string) { 72 + var pinRecord struct { 73 + Uri string `json:"uri"` 74 + Pin models.AtlasPinRecord `json:"value"` 75 + } 76 + request := map[string]any{ 77 + "repo": did, 78 + "collection": "io.whiteley.ATlas.pin", 79 + "rkey": "self", 80 + } 81 + 82 + if err := client.Get(context.Background(), "com.atproto.repo.getRecord", request, &pinRecord); err != nil { 83 + slog.Error("Failed to get pin record: ", "err", err) 84 + } 85 + 86 + slog.Info("Pin record found for user, syncing", "did", did, "record", pinRecord) 87 + 88 + if pinRecord.Uri == "" { 89 + slog.Info(`No pin found on PDS for user`, "DID", did) 90 + return 91 + } 92 + 93 + longitude, _ := strconv.ParseFloat(pinRecord.Pin.Longitude, 64) 94 + latitude, _ := strconv.ParseFloat(pinRecord.Pin.Latitude, 64) 95 + 96 + pin := models.Pin{ 97 + Did: pinRecord.Pin.Did, 98 + Uri: pinRecord.Uri, 99 + PlacedAt: pinRecord.Pin.PlacedAt, 100 + Longitude: longitude, 101 + Latitude: latitude, 102 + Name: name, 103 + Handle: handle, 104 + Description: pinRecord.Pin.Description, 105 + Website: *pinRecord.Pin.Website, 106 + Avatar: avatar, 107 + } 108 + 109 + if err := s.Repository.SavePin(context.Background(), pin); err != nil { 110 + slog.Error("Failed to save sync'd Pin: ", "err", err) 111 + } 112 + }
+2
handlers/auth.go
··· 109 109 return 110 110 } 111 111 112 + s.SyncUserPin(userDID, c, getProfile.DisplayName, getSession.Handle, getProfile.Avatar) 113 + 112 114 slog.Info("Successful login", "did", userDID) 113 115 http.Redirect(w, r, "/", http.StatusFound) 114 116 }
+9 -4
handlers/pin.go
··· 47 47 slog.Warn("Validation failed for pin", "err", err) 48 48 response.Error = fmt.Sprintf("Pin validation failed: %s", err) 49 49 } else { 50 - uri := s.PutPinRecord(session, *pin) 51 - pin.Uri = uri 50 + uri, err := s.PutPinRecord(session, *pin) 51 + 52 + if err != nil { 53 + response.Error = fmt.Sprintf("Failed to push pin to Atproto: %s", err) 54 + } else { 55 + pin.Uri = uri 52 56 53 - s.Repository.SavePin(r.Context(), *pin) 54 - response.PinData = pin 57 + s.Repository.SavePin(r.Context(), *pin) 58 + response.PinData = pin 59 + } 55 60 } 56 61 57 62 w.Header().Set("Content-Type", "application/json")