coyote/models.h

84 lines
2.1 KiB
C
Raw Normal View History

2023-11-22 08:39:24 +00:00
#pragma once
#include <string>
#include <vector>
2023-11-23 06:05:17 +00:00
#include <memory>
2023-11-22 08:39:24 +00:00
#include <nlohmann/json_fwd.hpp>
#include "blankie/serializer.h"
enum PostSortingMethod {
Posts = 0,
PostsAndReplies,
2023-11-23 12:20:49 +00:00
MediaOnly,
2023-11-22 08:39:24 +00:00
};
struct Emoji {
std::string shortcode;
std::string url;
};
struct AccountField {
std::string name;
blankie::html::HTMLString value_html;
time_t verified_at; // negative is not verified
};
struct Account {
std::string id;
std::string username;
2023-11-23 06:05:17 +00:00
std::string server;
bool same_server;
2023-11-22 08:39:24 +00:00
std::string display_name;
time_t created_at;
blankie::html::HTMLString note_html;
std::string avatar;
2023-11-23 08:49:27 +00:00
std::string avatar_static;
2023-11-22 08:39:24 +00:00
std::string header;
uint64_t followers_count;
uint64_t following_count;
uint64_t statuses_count;
std::vector<Emoji> emojis;
std::vector<AccountField> fields;
2023-11-23 06:05:17 +00:00
constexpr std::string acct(bool always_show_domain = true) const {
std::string res = this->username;
if (always_show_domain || !this->same_server) {
res += '@';
res += this->server;
}
return res;
}
};
2023-11-23 12:20:49 +00:00
struct Media {
std::string type;
std::string url;
std::optional<std::string> preview_url;
std::optional<std::string> remote_url;
std::optional<std::string> description;
};
2023-11-23 06:05:17 +00:00
struct Post {
std::string id;
time_t created_at;
std::optional<std::string> in_reply_to_id;
std::optional<std::string> in_reply_to_account_id;
bool sensitive;
std::string spoiler_text;
uint64_t replies_count;
uint64_t reblogs_count;
uint64_t favorites_count;
time_t edited_at; // negative is not edited
blankie::html::HTMLString content;
std::unique_ptr<Post> reblog;
Account account;
2023-11-23 12:20:49 +00:00
std::vector<Media> media_attachments;
2023-11-23 06:05:17 +00:00
std::vector<Emoji> emojis;
2023-11-22 08:39:24 +00:00
};
void from_json(const nlohmann::json& j, Emoji& emoji);
void from_json(const nlohmann::json& j, AccountField& field);
void from_json(const nlohmann::json& j, Account& account);
2023-11-23 12:20:49 +00:00
void from_json(const nlohmann::json& j, Media& media);
2023-11-23 06:05:17 +00:00
void from_json(const nlohmann::json& j, Post& post);