#pragma once // Spec: INV-posts 2.3 (ReplyAnchor, activeReply, replyAttachments, editingCommentId, pendingEditQuote), 1.4 (quote // insertion), 3.1 (feed cards share the same rules). The @State that SwiftUI keeps per screen and per CommentView: // which composer is open, the unsubmitted attachments, per comment edit state and the open editor objects. #include #include #include #include #include #include #include #include "screens/comments/CommentEditor.hpp" #include "model/UploadResponse.hpp" namespace dp { class DevPlaceApi; class CommentsSession { public: static constexpr const char* kPostAnchor = "@post"; static constexpr const char* kBottomAnchor = "@bottom"; struct RowState { bool isEditing = false; std::string editedText; float contentHeight = 0; }; CommentsSession(); ~CommentsSession(); // ---- reply composer (one at a time) ---- const std::optional& activeReply() const { return activeReply_; } bool isReplying(const std::string& anchor) const { return activeReply_ && *activeReply_ == anchor; } // beginReply(anchor): drop unsubmitted attachments, open the composer at `anchor`. void beginReply(const std::string& anchor); // cancelReply(): drop unsubmitted attachments, close. void cancelReply(); // Submit path: attachments are handed to the caller, the composer closes. Returns the attachments. std::vector takeAttachmentsAndClose(); const std::vector& attachments() const { return attachments_; } void setAttachments(std::vector list); // DELETE uploads/delete/ for each unsubmitted attachment, failures only logged. void discardAttachments(); // Increments on every beginReply so the composer fade-in restarts. int epoch() const { return epoch_; } // ---- comment editing ---- const std::optional& editingCommentId() const { return editingCommentId_; } RowState& row(const std::string& commentId); void beginEditing(const std::string& commentId, const std::string& content); void endEditing(const std::string& commentId); // Takes the quote waiting for the edit editor (pendingEditQuote consumption). std::optional takePendingEditQuote(); // ---- quote composer (FeedView.insertQuote, PostView.insertQuote) ---- bool isComposing() const { return activeReply_.has_value() || editingCommentId_.has_value(); } void insertQuote(const std::string& quote); // ---- editors: created on demand, dropped when a frame did not ask for them ---- CommentEditor& editor(const std::string& key); // Largest mention suggestion list height among the open editors. float mentionListHeight() const; void beginFrame(); void endFrame(); // Tests and shutdown. void reset(); private: std::optional activeReply_; std::optional editingCommentId_; std::optional pendingEditQuote_; std::vector attachments_; std::map rows_; std::map> editors_; std::vector> retired_; std::set touched_; int epoch_ = 0; }; } // namespace dp