coyote/models.h

124 lines
3.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;
2023-11-24 09:04:49 +00:00
bool bot;
2023-11-22 08:39:24 +00:00
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;
int64_t followers_count;
2023-11-22 08:39:24 +00:00
uint64_t following_count;
uint64_t statuses_count;
std::vector<Emoji> emojis;
std::vector<AccountField> fields;
2023-11-23 06:05:17 +00:00
2023-11-25 04:50:49 +00:00
inline std::string acct(bool always_show_domain = true) const {
2023-11-23 06:05:17 +00:00
std::string res = this->username;
if (always_show_domain || !this->same_server) {
res += '@';
res += this->server;
}
return res;
}
};
2023-12-02 13:50:33 +00:00
struct Size {
uint64_t width;
uint64_t height;
};
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;
2023-12-02 13:50:33 +00:00
std::optional<Size> size;
std::optional<Size> preview_size;
2023-11-23 12:20:49 +00:00
std::optional<std::string> description;
};
2023-11-24 06:37:26 +00:00
struct PollOption {
std::string title;
uint64_t votes_count;
};
struct Poll {
time_t expires_at; // negative if none
2023-11-24 06:37:26 +00:00
bool expired;
int64_t voters_count; // negative if unknown
uint64_t votes_count;
2023-11-24 06:37:26 +00:00
std::vector<PollOption> options;
std::vector<Emoji> emojis;
};
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-24 06:37:26 +00:00
std::optional<Poll> poll;
2023-11-22 08:39:24 +00:00
};
2023-11-23 23:46:47 +00:00
struct PostContext {
std::vector<Post> ancestors;
std::vector<Post> descendants;
};
2023-11-24 12:46:00 +00:00
struct Instance {
std::string title;
std::string description;
std::string thumbnail;
std::string contact_email;
Account contact_account;
std::vector<std::string> rules;
};
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-12-02 13:50:33 +00:00
void from_json(const nlohmann::json& j, Size& size);
2023-11-23 12:20:49 +00:00
void from_json(const nlohmann::json& j, Media& media);
2023-11-24 06:37:26 +00:00
void from_json(const nlohmann::json& j, PollOption& option);
void from_json(const nlohmann::json& j, Poll& poll);
2023-11-23 06:05:17 +00:00
void from_json(const nlohmann::json& j, Post& post);
2023-11-23 23:46:47 +00:00
void from_json(const nlohmann::json& j, PostContext& context);
2023-11-24 12:46:00 +00:00
void from_json(const nlohmann::json& j, Instance& instance);