summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-08-16 02:47:08 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2021-08-16 02:47:08 -0400
commitd2f6bd08fc27c2e499ab1573604932448feef269 (patch)
tree5db862984c0fb1f505e9532dae970abe0a06d6de
parent66c7ecf2abd2b08e628667bc1d8c3e56a14aa732 (diff)
downloadabaddon-portaudio-d2f6bd08fc27c2e499ab1573604932448feef269.tar.gz
abaddon-portaudio-d2f6bd08fc27c2e499ab1573604932448feef269.zip
handle archiving via THREAD_UPDATE (sorta)
-rw-r--r--components/channels.cpp14
-rw-r--r--components/channels.hpp1
-rw-r--r--discord/discord.cpp14
-rw-r--r--discord/discord.hpp4
-rw-r--r--discord/objects.cpp4
-rw-r--r--discord/objects.hpp6
6 files changed, 39 insertions, 4 deletions
diff --git a/components/channels.cpp b/components/channels.cpp
index f8d0fb6..117e5a6 100644
--- a/components/channels.cpp
+++ b/components/channels.cpp
@@ -142,6 +142,7 @@ ChannelList::ChannelList()
discord.signal_channel_update().connect(sigc::mem_fun(*this, &ChannelList::UpdateChannel));
discord.signal_channel_create().connect(sigc::mem_fun(*this, &ChannelList::UpdateCreateChannel));
discord.signal_thread_delete().connect(sigc::mem_fun(*this, &ChannelList::OnThreadDelete));
+ discord.signal_thread_update().connect(sigc::mem_fun(*this, &ChannelList::OnThreadUpdate));
discord.signal_thread_list_sync().connect(sigc::mem_fun(*this, &ChannelList::OnThreadListSync));
discord.signal_added_to_thread().connect(sigc::mem_fun(*this, &ChannelList::OnThreadJoined));
discord.signal_removed_from_thread().connect(sigc::mem_fun(*this, &ChannelList::OnThreadRemoved));
@@ -291,14 +292,19 @@ void ChannelList::OnThreadJoined(Snowflake id) {
}
void ChannelList::OnThreadRemoved(Snowflake id) {
- if (GetIteratorForChannelFromID(id))
- DeleteThreadRow(id);
+ DeleteThreadRow(id);
}
void ChannelList::OnThreadDelete(const ThreadDeleteData &data) {
DeleteThreadRow(data.ID);
}
+// todo probably make the row stick around if its selected until the selection changes
+void ChannelList::OnThreadUpdate(const ThreadUpdateData &data) {
+ if (data.Thread.ThreadMetadata->IsArchived)
+ DeleteThreadRow(data.Thread.ID);
+}
+
void ChannelList::OnThreadListSync(const ThreadListSyncData &data) {
// get the threads in the guild
std::vector<Snowflake> threads;
@@ -317,7 +323,7 @@ void ChannelList::OnThreadListSync(const ThreadListSyncData &data) {
// delete all threads not present in the synced data
for (auto thread_id : threads) {
- if (std::find_if(data.Threads.begin(), data.Threads.end(), [thread_id](const auto& x) { return x.ID == thread_id; }) == data.Threads.end()) {
+ if (std::find_if(data.Threads.begin(), data.Threads.end(), [thread_id](const auto &x) { return x.ID == thread_id; }) == data.Threads.end()) {
auto iter = GetIteratorForChannelFromID(thread_id);
m_model->erase(iter);
}
@@ -336,7 +342,7 @@ void ChannelList::SetActiveChannel(Snowflake id) {
if (m_temporary_thread_row) {
const auto thread_id = static_cast<Snowflake>((*m_temporary_thread_row)[m_columns.m_id]);
const auto thread = Abaddon::Get().GetDiscordClient().GetChannel(thread_id);
- if (thread.has_value() && !thread->IsJoinedThread())
+ if (thread.has_value() && (!thread->IsJoinedThread() || thread->ThreadMetadata->IsArchived))
m_model->erase(m_temporary_thread_row);
m_temporary_thread_row = {};
}
diff --git a/components/channels.hpp b/components/channels.hpp
index 31857ec..506ad93 100644
--- a/components/channels.hpp
+++ b/components/channels.hpp
@@ -146,6 +146,7 @@ protected:
void OnThreadJoined(Snowflake id);
void OnThreadRemoved(Snowflake id);
void OnThreadDelete(const ThreadDeleteData &data);
+ void OnThreadUpdate(const ThreadUpdateData &data);
void OnThreadListSync(const ThreadListSyncData &data);
Gtk::TreeView m_view;
diff --git a/discord/discord.cpp b/discord/discord.cpp
index 0ef1202..c4276dc 100644
--- a/discord/discord.cpp
+++ b/discord/discord.cpp
@@ -1220,6 +1220,9 @@ void DiscordClient::HandleGatewayMessage(std::string str) {
case GatewayEvent::THREAD_MEMBER_UPDATE: {
HandleGatewayThreadMemberUpdate(m);
} break;
+ case GatewayEvent::THREAD_UPDATE: {
+ HandleGatewayThreadUpdate(m);
+ } break;
}
} break;
default:
@@ -1749,6 +1752,12 @@ void DiscordClient::HandleGatewayThreadMemberUpdate(const GatewayMessage &msg) {
m_signal_added_to_thread.emit(*data.Member.ThreadID);
}
+void DiscordClient::HandleGatewayThreadUpdate(const GatewayMessage &msg) {
+ ThreadUpdateData data = msg.Data;
+ m_store.SetChannel(data.Thread.ID, data.Thread);
+ m_signal_thread_update.emit(data);
+}
+
void DiscordClient::HandleGatewayReadySupplemental(const GatewayMessage &msg) {
ReadySupplementalData data = msg.Data;
for (const auto &p : data.MergedPresences.Friends) {
@@ -2116,6 +2125,7 @@ void DiscordClient::LoadEventMap() {
m_event_map["THREAD_LIST_SYNC"] = GatewayEvent::THREAD_LIST_SYNC;
m_event_map["THREAD_MEMBERS_UPDATE"] = GatewayEvent::THREAD_MEMBERS_UPDATE;
m_event_map["THREAD_MEMBER_UPDATE"] = GatewayEvent::THREAD_MEMBER_UPDATE;
+ m_event_map["THREAD_UPDATE"] = GatewayEvent::THREAD_UPDATE;
}
DiscordClient::type_signal_gateway_ready DiscordClient::signal_gateway_ready() {
@@ -2270,6 +2280,10 @@ DiscordClient::type_signal_thread_members_update DiscordClient::signal_thread_me
return m_signal_thread_members_update;
}
+DiscordClient::type_signal_thread_update DiscordClient::signal_thread_update() {
+ return m_signal_thread_update;
+}
+
DiscordClient::type_signal_added_to_thread DiscordClient::signal_added_to_thread() {
return m_signal_added_to_thread;
}
diff --git a/discord/discord.hpp b/discord/discord.hpp
index 952a5c4..a9dc62e 100644
--- a/discord/discord.hpp
+++ b/discord/discord.hpp
@@ -245,6 +245,7 @@ private:
void HandleGatewayThreadListSync(const GatewayMessage &msg);
void HandleGatewayThreadMembersUpdate(const GatewayMessage &msg);
void HandleGatewayThreadMemberUpdate(const GatewayMessage &msg);
+ void HandleGatewayThreadUpdate(const GatewayMessage &msg);
void HandleGatewayReadySupplemental(const GatewayMessage &msg);
void HandleGatewayReconnect(const GatewayMessage &msg);
void HandleGatewayInvalidSession(const GatewayMessage &msg);
@@ -340,6 +341,7 @@ public:
typedef sigc::signal<void, ThreadDeleteData> type_signal_thread_delete;
typedef sigc::signal<void, ThreadListSyncData> type_signal_thread_list_sync;
typedef sigc::signal<void, ThreadMembersUpdateData> type_signal_thread_members_update;
+ typedef sigc::signal<void, ThreadUpdateData> type_signal_thread_update;
// not discord dispatch events
typedef sigc::signal<void, Snowflake> type_signal_added_to_thread;
@@ -388,6 +390,7 @@ public:
type_signal_thread_delete signal_thread_delete();
type_signal_thread_list_sync signal_thread_list_sync();
type_signal_thread_members_update signal_thread_members_update();
+ type_signal_thread_update signal_thread_update();
type_signal_added_to_thread signal_added_to_thread();
type_signal_removed_from_thread signal_removed_from_thread();
type_signal_message_sent signal_message_sent();
@@ -432,6 +435,7 @@ protected:
type_signal_thread_delete m_signal_thread_delete;
type_signal_thread_list_sync m_signal_thread_list_sync;
type_signal_thread_members_update m_signal_thread_members_update;
+ type_signal_thread_update m_signal_thread_update;
type_signal_removed_from_thread m_signal_removed_from_thread;
type_signal_added_to_thread m_signal_added_to_thread;
type_signal_message_sent m_signal_message_sent;
diff --git a/discord/objects.cpp b/discord/objects.cpp
index 77d5286..fb713f4 100644
--- a/discord/objects.cpp
+++ b/discord/objects.cpp
@@ -507,3 +507,7 @@ void from_json(const nlohmann::json &j, ArchivedThreadsResponseData &m) {
void from_json(const nlohmann::json &j, ThreadMemberUpdateData &m) {
m.Member = j;
}
+
+void from_json(const nlohmann::json &j, ThreadUpdateData &m) {
+ m.Thread = j;
+}
diff --git a/discord/objects.hpp b/discord/objects.hpp
index 4e7de81..daaa9b2 100644
--- a/discord/objects.hpp
+++ b/discord/objects.hpp
@@ -714,3 +714,9 @@ struct ThreadMemberUpdateData {
friend void from_json(const nlohmann::json &j, ThreadMemberUpdateData &m);
};
+
+struct ThreadUpdateData {
+ ChannelData Thread;
+
+ friend void from_json(const nlohmann::json &j, ThreadUpdateData &m);
+};