Skip to content
Repos

DevPlaceApp

C++ 3.0 KB79 lines Opens in site

Directory Raw Download

#pragma once
// Spec: INV-posts 2 (PostView + ViewModel). Post detail: body, attachments, poll, reactions, votes, comments tree,
// edit and delete of own content, replies, deep link scroll to a comment. FR-POST-01.
#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "model/PostDetail.hpp"
#include "model/TargetType.hpp"
#include "screens/PostDestination.hpp"
#include "screens/comments/CommentsSession.hpp"
#include "screens/post/ScrollDriver.hpp"
#include "ui/Navigation.hpp"

namespace dp {

class PostScreen : public ui::Screen {
 public:
  explicit PostScreen(PostDestination destination);
  ~PostScreen() override;

  ui::ViewPtr body() override;
  std::string title() const override;
  TitleMode titleMode() const override { return TitleMode::Inline; }
  ui::ViewPtr toolbarTrailing() override;
  void onAppear() override;
  void onDisappear() override;
  bool busy() const override;

  // PostVM.swift
  void load();
  void reload();
  void deletePost();
  void deleteComment(const std::string& commentId);
  void editComment(const std::string& commentId, const std::string& content);
  // done(true) when created and reloaded.
  void submitComment(TargetType targetType, const std::string& targetId, const std::optional<std::string>& parentId,
                     const std::string& content, const std::vector<UploadResponse>& attachments, std::function<void(bool)> done);
  void upvoteForeignPost();
  void doubleTapComment(const std::string& commentId);
  void reactToPost(const std::string& emoji);
  void reactToComment(const std::string& commentId, const std::string& emoji);

  const std::optional<PostDetail>& detail() const { return detail_; }
  bool isReloading() const { return reloading_; }
  CommentsSession& session() { return session_; }
  // Anchor id of a comment (Comment.id) to scroll to once loaded.
  void scrollToComment(const std::string& commentId);

 private:
  ui::ViewPtr content(const PostDetail& detail);
  ui::ViewPtr postBody(const PostDetail& detail);
  ui::ViewPtr commentsSection(const PostDetail& detail);
  ui::ViewPtr bottomCommentSection(const PostDetail& detail);
  ui::ViewPtr composer(const PostDetail& detail, const std::string& anchor, const std::string& placeholder);
  void submitReplyToPost(const std::string& postId, const std::string& content);
  void submitReplyToComment(const std::string& commentId, const std::string& targetType, const std::string& targetId, const std::string& content);
  void presentEdit();
  void runScrollToComment();
  void followMentionList();
  void fetchDetail(std::function<void(bool)> done);
  void afterMutation(std::function<void(bool)> done);

  PostDestination destination_;
  std::optional<PostDetail> detail_;
  CommentsSession session_;
  ScrollDriver scroll_{"post-scroll"};
  bool reloading_ = false;
  int inflight_ = 0;
  std::optional<std::string> pendingScroll_;
  bool scrollArmed_ = false;
  int scrollTries_ = 0;
  float lastMentionHeight_ = 0;
  bool followPending_ = false;
  std::shared_ptr<bool> alive_ = std::make_shared<bool>(true);
};

}  // namespace dp
37.1ms