summaryrefslogtreecommitdiff
path: root/discord
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2020-09-10 23:57:36 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2020-09-10 23:57:36 -0400
commitb9fb7c536ae6ab46f15c355176edbd5d25db6669 (patch)
tree89d40423dbc35bd3b8ee4ffd2afa9a975fe0dca3 /discord
parent54a8244bfdd26656260b3c82391db2213f937ac7 (diff)
downloadabaddon-portaudio-b9fb7c536ae6ab46f15c355176edbd5d25db6669.tar.gz
abaddon-portaudio-b9fb7c536ae6ab46f15c355176edbd5d25db6669.zip
fix edited/deleted being reset on channel change
Diffstat (limited to 'discord')
-rw-r--r--discord/discord.cpp7
-rw-r--r--discord/message.cpp17
-rw-r--r--discord/message.hpp10
-rw-r--r--discord/store.cpp45
-rw-r--r--discord/store.hpp6
5 files changed, 82 insertions, 3 deletions
diff --git a/discord/discord.cpp b/discord/discord.cpp
index 470088b..cb997cf 100644
--- a/discord/discord.cpp
+++ b/discord/discord.cpp
@@ -373,6 +373,9 @@ void DiscordClient::HandleGatewayMessageCreate(const GatewayMessage &msg) {
void DiscordClient::HandleGatewayMessageDelete(const GatewayMessage &msg) {
MessageDeleteData data = msg.Data;
m_signal_message_delete.emit(data.ID, data.ChannelID);
+ auto *cur = m_store.GetMessage(data.ID);
+ if (cur != nullptr)
+ cur->SetDeleted();
}
void DiscordClient::HandleGatewayMessageUpdate(const GatewayMessage &msg) {
@@ -385,9 +388,7 @@ void DiscordClient::HandleGatewayMessageUpdate(const GatewayMessage &msg) {
return;
if (data.Content != current->Content) {
- auto copy = *current;
- copy.Content = data.Content;
- m_store.SetMessage(copy.ID, copy);
+ current->SetEdited(data.Content);
m_signal_message_update.emit(data.ID, data.ChannelID);
}
}
diff --git a/discord/message.cpp b/discord/message.cpp
index a622207..044c2e5 100644
--- a/discord/message.cpp
+++ b/discord/message.cpp
@@ -115,3 +115,20 @@ void Message::from_json_edited(const nlohmann::json &j) {
JS_O("type", Type);
JS_O("flags", Flags);
}
+
+void Message::SetDeleted() {
+ m_deleted = true;
+}
+
+void Message::SetEdited(std::string new_content) {
+ m_edited = true;
+ Content = new_content;
+}
+
+bool Message::IsDeleted() const {
+ return m_deleted;
+}
+
+bool Message::IsEdited() const {
+ return m_edited;
+}
diff --git a/discord/message.hpp b/discord/message.hpp
index de312de..2c8fc3d 100644
--- a/discord/message.hpp
+++ b/discord/message.hpp
@@ -147,4 +147,14 @@ struct Message {
friend void from_json(const nlohmann::json &j, Message &m);
void from_json_edited(const nlohmann::json &j); // for MESSAGE_UPDATE
+
+ // custom fields to track changes
+ void SetDeleted();
+ void SetEdited(std::string new_content);
+ bool IsDeleted() const;
+ bool IsEdited() const;
+
+private:
+ bool m_deleted = false;
+ bool m_edited = false;
};
diff --git a/discord/store.cpp b/discord/store.cpp
index 270f16c..fb0bec1 100644
--- a/discord/store.cpp
+++ b/discord/store.cpp
@@ -24,6 +24,13 @@ void Store::SetGuildMemberData(Snowflake guild_id, Snowflake user_id, const Guil
m_members[guild_id][user_id] = data;
}
+User *Store::GetUser(Snowflake id) {
+ auto it = m_users.find(id);
+ if (it == m_users.end())
+ return nullptr;
+ return &it->second;
+}
+
const User *Store::GetUser(Snowflake id) const {
auto it = m_users.find(id);
if (it == m_users.end())
@@ -31,6 +38,13 @@ const User *Store::GetUser(Snowflake id) const {
return &it->second;
}
+Channel *Store::GetChannel(Snowflake id) {
+ auto it = m_channels.find(id);
+ if (it == m_channels.end())
+ return nullptr;
+ return &it->second;
+}
+
const Channel *Store::GetChannel(Snowflake id) const {
auto it = m_channels.find(id);
if (it == m_channels.end())
@@ -38,6 +52,13 @@ const Channel *Store::GetChannel(Snowflake id) const {
return &it->second;
}
+Guild *Store::GetGuild(Snowflake id) {
+ auto it = m_guilds.find(id);
+ if (it == m_guilds.end())
+ return nullptr;
+ return &it->second;
+}
+
const Guild *Store::GetGuild(Snowflake id) const {
auto it = m_guilds.find(id);
if (it == m_guilds.end())
@@ -45,6 +66,13 @@ const Guild *Store::GetGuild(Snowflake id) const {
return &it->second;
}
+Role *Store::GetRole(Snowflake id) {
+ auto it = m_roles.find(id);
+ if (it == m_roles.end())
+ return nullptr;
+ return &it->second;
+}
+
const Role *Store::GetRole(Snowflake id) const {
auto it = m_roles.find(id);
if (it == m_roles.end())
@@ -52,6 +80,13 @@ const Role *Store::GetRole(Snowflake id) const {
return &it->second;
}
+Message *Store::GetMessage(Snowflake id) {
+ auto it = m_messages.find(id);
+ if (it == m_messages.end())
+ return nullptr;
+ return &it->second;
+}
+
const Message *Store::GetMessage(Snowflake id) const {
auto it = m_messages.find(id);
if (it == m_messages.end())
@@ -59,6 +94,16 @@ const Message *Store::GetMessage(Snowflake id) const {
return &it->second;
}
+GuildMember *Store::GetGuildMemberData(Snowflake guild_id, Snowflake user_id) {
+ auto git = m_members.find(guild_id);
+ if (git == m_members.end())
+ return nullptr;
+ auto mit = git->second.find(user_id);
+ if (mit == git->second.end())
+ return nullptr;
+ return &mit->second;
+}
+
const GuildMember *Store::GetGuildMemberData(Snowflake guild_id, Snowflake user_id) const {
auto git = m_members.find(guild_id);
if (git == m_members.end())
diff --git a/discord/store.hpp b/discord/store.hpp
index 398b725..45b1c41 100644
--- a/discord/store.hpp
+++ b/discord/store.hpp
@@ -16,6 +16,12 @@ public:
void SetMessage(Snowflake id, const Message &message);
void SetGuildMemberData(Snowflake guild_id, Snowflake user_id, const GuildMember &data);
+ User *GetUser(Snowflake id);
+ Channel *GetChannel(Snowflake id);
+ Guild *GetGuild(Snowflake id);
+ Role *GetRole(Snowflake id);
+ Message *GetMessage(Snowflake id);
+ GuildMember *GetGuildMemberData(Snowflake guild_id, Snowflake user_id);
const User *GetUser(Snowflake id) const;
const Channel *GetChannel(Snowflake id) const;
const Guild *GetGuild(Snowflake id) const;