summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-08-05 03:32:53 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2021-08-05 03:32:53 -0400
commit41a63df1b108a9520a8dfcb862f108b42f9a1bb1 (patch)
treeb9eae63b43a9dd418fe7d7b3b7c8562fd92ec7ab
parent40897ece3ced8bfc051708a8d85f413f330631a9 (diff)
downloadabaddon-portaudio-41a63df1b108a9520a8dfcb862f108b42f9a1bb1.tar.gz
abaddon-portaudio-41a63df1b108a9520a8dfcb862f108b42f9a1bb1.zip
add temporary row for non-joined threads
-rw-r--r--components/channels.cpp21
-rw-r--r--components/channels.hpp3
-rw-r--r--discord/channel.cpp10
-rw-r--r--discord/channel.hpp2
-rw-r--r--discord/discord.cpp6
-rw-r--r--discord/discord.hpp5
6 files changed, 43 insertions, 4 deletions
diff --git a/components/channels.cpp b/components/channels.cpp
index f12d56a..b96b2e6 100644
--- a/components/channels.cpp
+++ b/components/channels.cpp
@@ -292,6 +292,7 @@ void ChannelList::OnThreadMembersUpdate(const ThreadMembersUpdateData &data) {
}
void ChannelList::UpdateCreateThread(const ChannelData &channel) {
+ if (GetIteratorForChannelFromID(channel.ID)) return; // dont do anything if already exists
auto parent_row = GetIteratorForChannelFromID(*channel.ParentID);
if (parent_row)
CreateThreadRow(parent_row->children(), channel);
@@ -303,13 +304,31 @@ void ChannelList::UpdateDeleteThread(Snowflake id) {
m_model->erase(iter);
}
+// create a temporary channel row for non-joined threads
+// and delete them when the active channel switches off of them if still not joined
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())
+ m_model->erase(m_temporary_thread_row);
+ m_temporary_thread_row = {};
+ }
+
const auto channel_iter = GetIteratorForChannelFromID(id);
if (channel_iter) {
m_view.expand_to_path(m_model->get_path(channel_iter));
m_view.get_selection()->select(channel_iter);
- } else
+ } else {
m_view.get_selection()->unselect_all();
+ // SetActiveChannel should probably just take the channel object
+ const auto channel = Abaddon::Get().GetDiscordClient().GetChannel(id);
+ if (!channel.has_value() || !channel->IsThread()) return;
+ auto parent_iter = GetIteratorForChannelFromID(*channel->ParentID);
+ if (!parent_iter) return;
+ m_temporary_thread_row = CreateThreadRow(parent_iter->children(), *channel);
+ m_view.get_selection()->select(m_temporary_thread_row);
+ }
}
Gtk::TreeModel::iterator ChannelList::AddGuild(const GuildData &guild) {
diff --git a/components/channels.hpp b/components/channels.hpp
index 24c7170..fce3546 100644
--- a/components/channels.hpp
+++ b/components/channels.hpp
@@ -197,6 +197,9 @@ protected:
void OnMessageCreate(const Message &msg);
Gtk::TreeModel::Path m_path_for_menu;
+ // cant be recovered through selection
+ Gtk::TreeModel::iterator m_temporary_thread_row;
+
Gtk::Menu m_menu_guild;
Gtk::MenuItem m_menu_guild_copy_id;
Gtk::MenuItem m_menu_guild_settings;
diff --git a/discord/channel.cpp b/discord/channel.cpp
index 685cc72..f78e0cd 100644
--- a/discord/channel.cpp
+++ b/discord/channel.cpp
@@ -63,6 +63,16 @@ bool ChannelData::NSFW() const {
return IsNSFW.has_value() && *IsNSFW;
}
+bool ChannelData::IsThread() const noexcept {
+ return Type == ChannelType::GUILD_PUBLIC_THREAD ||
+ Type == ChannelType::GUILD_PRIVATE_THREAD ||
+ Type == ChannelType::GUILD_NEWS_THREAD;
+}
+
+bool ChannelData::IsJoinedThread() const {
+ return Abaddon::Get().GetDiscordClient().IsThreadJoined(ID);
+}
+
std::optional<PermissionOverwrite> ChannelData::GetOverwrite(Snowflake id) const {
return Abaddon::Get().GetDiscordClient().GetPermissionOverwrite(ID, id);
}
diff --git a/discord/channel.hpp b/discord/channel.hpp
index 606686d..942d555 100644
--- a/discord/channel.hpp
+++ b/discord/channel.hpp
@@ -85,6 +85,8 @@ struct ChannelData {
void update_from_json(const nlohmann::json &j);
bool NSFW() const;
+ bool IsThread() const noexcept;
+ bool IsJoinedThread() const;
std::optional<PermissionOverwrite> GetOverwrite(Snowflake id) const;
std::vector<UserData> GetDMRecipients() const;
};
diff --git a/discord/discord.cpp b/discord/discord.cpp
index 49684ae..5a7c07e 100644
--- a/discord/discord.cpp
+++ b/discord/discord.cpp
@@ -253,6 +253,10 @@ std::vector<ChannelData> DiscordClient::GetPublicThreads(Snowflake channel_id) c
return m_store.GetThreads(channel_id);
}
+bool DiscordClient::IsThreadJoined(Snowflake thread_id) const {
+ return std::find(m_joined_threads.begin(), m_joined_threads.end(), thread_id) != m_joined_threads.end();
+}
+
bool DiscordClient::HasGuildPermission(Snowflake user_id, Snowflake guild_id, Permission perm) const {
const auto base = ComputePermissions(user_id, guild_id);
return (base & perm) == perm;
@@ -1250,6 +1254,7 @@ void DiscordClient::ProcessNewGuild(GuildData &guild) {
if (guild.Threads.has_value()) {
for (auto &c : *guild.Threads) {
+ m_joined_threads.push_back(c.ID);
c.GuildID = guild.ID;
m_store.SetChannel(c.ID, c);
}
@@ -1668,6 +1673,7 @@ void DiscordClient::HandleGatewayRelationshipAdd(const GatewayMessage &msg) {
void DiscordClient::HandleGatewayThreadCreate(const GatewayMessage &msg) {
ThreadCreateData data = msg.Data;
m_store.SetChannel(data.Channel.ID, data.Channel);
+ m_joined_threads.push_back(data.Channel.ID);
m_signal_thread_create.emit(data.Channel);
}
diff --git a/discord/discord.hpp b/discord/discord.hpp
index fa4b4c3..a589702 100644
--- a/discord/discord.hpp
+++ b/discord/discord.hpp
@@ -88,6 +88,7 @@ public:
std::set<Snowflake> GetChannelsInGuild(Snowflake id) const;
std::vector<ChannelData> GetPublicThreads(Snowflake channel_id) const;
+ bool IsThreadJoined(Snowflake thread_id) const;
bool HasGuildPermission(Snowflake user_id, Snowflake guild_id, Permission perm) const;
bool HasAnyChannelPermission(Snowflake user_id, Snowflake channel_id, Permission perm) const;
@@ -261,13 +262,11 @@ private:
void AddUserToGuild(Snowflake user_id, Snowflake guild_id);
std::map<Snowflake, std::set<Snowflake>> m_guild_to_users;
-
std::map<Snowflake, std::set<Snowflake>> m_guild_to_channels;
std::map<Snowflake, GuildApplicationData> m_guild_join_requests;
-
std::map<Snowflake, PresenceStatus> m_user_to_status;
-
std::map<Snowflake, RelationshipType> m_user_relationships;
+ std::vector<Snowflake> m_joined_threads;
UserData m_user_data;
UserSettings m_user_settings;