#pragma once // Spec: models.md Comment (+ Model Updates). Wire is a wrapper: comment, author, my_vote, votes, attachments, // children (recursive, depth capped by ModelLimits::kMaxCommentDepth), reactions. #include #include #include #include #include "core/Date.hpp" #include "core/Json.hpp" #include "model/Attachment.hpp" #include "model/Reactions.hpp" #include "model/User.hpp" #include "model/Vote.hpp" namespace dp { struct Comment { struct Data { std::string id; std::string userId; std::string content; std::optional parentId; std::string targetType; // raw string std::string targetId; Date createdAt{}; static Data fromJson(const Json& j); }; struct Votes { std::int64_t up = 0; std::int64_t down = 0; static Votes fromJson(const Json& j); }; Data data; User author; Vote myVote; Votes votes; std::vector attachments; std::vector children; Reactions reactions; static Comment fromJson(const Json& j) { return fromJson(j, 0); } static Comment fromJson(const Json& j, std::size_t depth); std::string id() const { return "comment:" + data.id; } std::int64_t voteCount() const { return votes.up - votes.down; } Comment replacingReactions(const Reactions& newReactions, const std::vector& newChildren) const; Comment replacingChildren(const std::vector& newChildren) const; // Moves the viewer's vote: undoes the old one, applies the new one on the counters. Comment applyingVote(Vote newVote, const std::vector& newChildren) const; }; } // namespace dp