Repos
C++
1.1 KB28 lines Opens in site
Directory
Raw
Download
#include "model/CommentTree.hpp"
namespace dp {
std::vector<Comment> CommentTree::updatingVote(const std::vector<Comment>& comments, const std::string& commentId, Vote vote) {
std::vector<Comment> out;
out.reserve(comments.size());
for (const auto& comment : comments) {
auto children = updatingVote(comment.children, commentId, vote);
if (comment.data.id == commentId) out.push_back(comment.applyingVote(vote, children));
else out.push_back(comment.replacingChildren(children));
}
return out;
}
std::vector<Comment> CommentTree::updatingReaction(const std::vector<Comment>& comments, const std::string& commentId,
const std::string& emoji) {
std::vector<Comment> out;
out.reserve(comments.size());
for (const auto& comment : comments) {
auto children = updatingReaction(comment.children, commentId, emoji);
if (comment.data.id == commentId) out.push_back(comment.replacingReactions(comment.reactions.toggling(emoji), children));
else out.push_back(comment.replacingChildren(children));
}
return out;
}
} // namespace dp