mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-19 20:11:59 +03:00
display replies
This commit is contained in:
@@ -120,7 +120,7 @@ void DiscordClient::FetchMessagesInChannel(Snowflake id, std::function<void(cons
|
||||
nlohmann::json::parse(r.text).get_to(msgs);
|
||||
|
||||
m_store.BeginTransaction();
|
||||
for (const auto &msg : msgs) {
|
||||
for (auto &msg : msgs) {
|
||||
StoreMessageData(msg);
|
||||
AddMessageToChannel(msg.ID, id);
|
||||
AddUserToGuild(msg.Author.ID, *msg.GuildID);
|
||||
@@ -143,7 +143,7 @@ void DiscordClient::FetchMessagesInChannelBefore(Snowflake channel_id, Snowflake
|
||||
nlohmann::json::parse(r.text).get_to(msgs);
|
||||
|
||||
m_store.BeginTransaction();
|
||||
for (const auto &msg : msgs) {
|
||||
for (auto &msg : msgs) {
|
||||
StoreMessageData(msg);
|
||||
AddMessageToChannel(msg.ID, channel_id);
|
||||
AddUserToGuild(msg.Author.ID, *msg.GuildID);
|
||||
@@ -1045,7 +1045,11 @@ bool DiscordClient::CheckCode(const cpr::Response &r) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void DiscordClient::StoreMessageData(const Message &msg) {
|
||||
void DiscordClient::StoreMessageData(Message &msg) {
|
||||
const auto chan = m_store.GetChannel(msg.ChannelID);
|
||||
if (chan.has_value() && chan->GuildID.has_value())
|
||||
msg.GuildID = *chan->GuildID;
|
||||
|
||||
m_store.SetMessage(msg.ID, msg);
|
||||
m_store.SetUser(msg.Author.ID, msg.Author);
|
||||
if (msg.Reactions.has_value())
|
||||
@@ -1058,6 +1062,10 @@ void DiscordClient::StoreMessageData(const Message &msg) {
|
||||
|
||||
for (const auto &user : msg.Mentions)
|
||||
m_store.SetUser(user.ID, user);
|
||||
|
||||
if (msg.ReferencedMessage.has_value() && msg.MessageReference.has_value() && msg.MessageReference->ChannelID.has_value())
|
||||
if (msg.ReferencedMessage.value() != nullptr)
|
||||
StoreMessageData(**msg.ReferencedMessage);
|
||||
}
|
||||
|
||||
void DiscordClient::LoadEventMap() {
|
||||
|
||||
@@ -156,7 +156,7 @@ private:
|
||||
|
||||
bool CheckCode(const cpr::Response &r);
|
||||
|
||||
void StoreMessageData(const Message &msg);
|
||||
void StoreMessageData(Message &msg);
|
||||
|
||||
std::string m_token;
|
||||
|
||||
|
||||
@@ -211,6 +211,12 @@ void from_json(const nlohmann::json &j, Message &m) {
|
||||
JS_O("message_reference", m.MessageReference);
|
||||
JS_O("flags", m.Flags);
|
||||
JS_O("stickers", m.Stickers);
|
||||
if (j.contains("referenced_message")) {
|
||||
if (!j.at("referenced_message").is_null()) {
|
||||
m.ReferencedMessage = std::make_shared<Message>(j.at("referenced_message").get<Message>());
|
||||
} else
|
||||
m.ReferencedMessage = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Message::from_json_edited(const nlohmann::json &j) {
|
||||
|
||||
@@ -188,6 +188,7 @@ struct Message {
|
||||
std::optional<MessageReferenceData> MessageReference;
|
||||
std::optional<MessageFlags> Flags = MessageFlags::NONE;
|
||||
std::optional<std::vector<Sticker>> Stickers;
|
||||
std::optional<std::shared_ptr<Message>> ReferencedMessage; // has_value && null means deleted
|
||||
|
||||
friend void from_json(const nlohmann::json &j, Message &m);
|
||||
void from_json_edited(const nlohmann::json &j); // for MESSAGE_UPDATE
|
||||
|
||||
@@ -496,6 +496,14 @@ std::optional<Message> Store::GetMessage(Snowflake id) const {
|
||||
|
||||
Reset(m_get_msg_stmt);
|
||||
|
||||
if (ret.MessageReference.has_value() && ret.MessageReference->MessageID.has_value()) {
|
||||
auto ref = GetMessage(*ret.MessageReference->MessageID);
|
||||
if (ref.has_value())
|
||||
ret.ReferencedMessage = std::make_unique<Message>(std::move(*ref));
|
||||
else
|
||||
ret.ReferencedMessage = nullptr;
|
||||
}
|
||||
|
||||
return std::optional<Message>(std::move(ret));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user