Diffdown is a real-time collaborative Markdown editor/previewer built on the AT Protocol diffdown.com

xrpc: add ListComments and UpdateComment methods

+26 -4
+26 -4
internal/atproto/xrpc/client.go
··· 292 292 return nil 293 293 } 294 294 295 - const collectionDocument = "com.diffdown.document" 296 - 297 295 // GetDocument fetches a document by its rkey. 298 296 func (c *Client) GetDocument(rkey string) (*model.Document, error) { 299 - value, _, err := c.GetRecord(c.session.DID, collectionDocument, rkey) 297 + value, _, err := c.GetRecord(c.session.DID, model.CollectionDocument, rkey) 300 298 if err != nil { 301 299 return nil, err 302 300 } ··· 311 309 312 310 // PutDocument creates or updates a document. 313 311 func (c *Client) PutDocument(rkey string, doc *model.Document) (string, string, error) { 314 - return c.PutRecord(collectionDocument, rkey, doc) 312 + return c.PutRecord(model.CollectionDocument, rkey, doc) 313 + } 314 + 315 + // ListComments lists all comment records for a given document. 316 + func (c *Client) ListComments(did, docRKey string, limit int, cursor string) ([]Record, string, error) { 317 + records, nextCursor, err := c.ListRecords(did, model.CollectionComment, limit, cursor) 318 + if err != nil { 319 + return nil, "", err 320 + } 321 + var filtered []Record 322 + for _, r := range records { 323 + var comment model.CommentRecord 324 + if err := json.Unmarshal(r.Value, &comment); err != nil { 325 + continue 326 + } 327 + if comment.DocRKey == docRKey { 328 + filtered = append(filtered, r) 329 + } 330 + } 331 + return filtered, nextCursor, nil 332 + } 333 + 334 + // UpdateComment updates an existing comment record (e.g., for resolution toggle). 335 + func (c *Client) UpdateComment(rkey string, record interface{}) (uri, cid string, err error) { 336 + return c.PutRecord(model.CollectionComment, rkey, record) 315 337 }