Skip to content
Repos

DevPlaceApp

C++ 694 B33 lines Opens in site

Directory Raw Download

#pragma once
// Spec: models.md Message. Wire wrapper: message, sender, is_mine, attachments.
#include <string>
#include <vector>

#include "core/Date.hpp"
#include "core/Json.hpp"
#include "model/Attachment.hpp"
#include "model/User.hpp"

namespace dp {

struct Message {
  struct Data {
    std::string id;
    std::string senderId;
    std::string receiverId;
    std::string content;
    bool read = false;
    Date createdAt{};
    static Data fromJson(const Json& j);
  };

  Data data;
  User sender;
  bool isMine = false;
  std::vector<Attachment> attachments;

  static Message fromJson(const Json& j);
  std::string id() const { return "message:" + data.id; }
};

}  // namespace dp
20.9ms