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

handler: use separate collection for comments instead of embedding

+21 -14
+21 -14
internal/handler/handler.go
··· 736 736 ThreadID string `json:"threadId"` 737 737 QuotedText string `json:"quotedText"` 738 738 Text string `json:"text"` 739 + ReplyTo string `json:"replyTo,omitempty"` // parent comment URI for threading 739 740 } 740 741 if err := json.NewDecoder(r.Body).Decode(&req); err != nil { 741 742 http.Error(w, "Invalid request", http.StatusBadRequest) ··· 764 765 ownerDID = req.OwnerDID 765 766 } 766 767 768 + // Verify document exists (but don't fetch full content) 767 769 ownerClient, err := h.xrpcClient(ownerUserID) 768 770 if err != nil { 769 771 http.Error(w, "Failed to connect to owner PDS", http.StatusInternalServerError) 770 772 return 771 773 } 772 - 773 - value, _, err := ownerClient.GetRecord(ownerDID, collectionDocument, rKey) 774 + _, _, err = ownerClient.GetRecord(ownerDID, model.CollectionDocument, rKey) 774 775 if err != nil { 775 776 log.Printf("CommentCreate: GetRecord: %v", err) 776 777 http.Error(w, "Document not found", http.StatusNotFound) 777 778 return 778 779 } 779 - var doc model.Document 780 - if err := json.Unmarshal(value, &doc); err != nil { 781 - http.Error(w, "Failed to parse document", http.StatusInternalServerError) 782 - return 783 - } 784 780 785 781 authorHandle, _ := atproto.ResolveHandleFromDID(session.DID) 786 782 ··· 789 785 threadID = randomID() 790 786 } 791 787 792 - comment := model.EmbeddedComment{ 793 - ID: randomID(), 788 + // Create standalone comment record 789 + comment := model.CommentRecord{ 794 790 ThreadID: threadID, 791 + DocRKey: rKey, 792 + DocOwnerDID: ownerDID, 795 793 QuotedText: req.QuotedText, 796 794 Text: req.Text, 797 795 Author: session.DID, 798 796 AuthorHandle: authorHandle, 799 797 CreatedAt: time.Now().UTC().Format(time.RFC3339), 798 + ReplyTo: req.ReplyTo, 799 + Resolved: false, 800 800 } 801 - doc.Comments = append(doc.Comments, comment) 802 801 803 - if _, _, err := ownerClient.PutDocument(rKey, &doc); err != nil { 804 - log.Printf("CommentCreate: PutDocument: %v", err) 805 - http.Error(w, "Failed to save comment", http.StatusInternalServerError) 802 + // Create as separate record in app.diffdown.comment collection 803 + uri, _, err := ownerClient.CreateRecord(model.CollectionComment, comment) 804 + if err != nil { 805 + log.Printf("CommentCreate: CreateRecord: %v", err) 806 + http.Error(w, "Failed to create comment", http.StatusInternalServerError) 806 807 return 807 808 } 808 809 809 - h.jsonResponse(w, comment, http.StatusCreated) 810 + // Return response with URI for potential reply linking 811 + response := struct { 812 + model.CommentRecord 813 + URI string `json:"uri"` 814 + }{CommentRecord: comment, URI: uri} 815 + 816 + h.jsonResponse(w, response, http.StatusCreated) 810 817 } 811 818 812 819 func (h *Handler) CommentList(w http.ResponseWriter, r *http.Request) {