forked from OpenGamers/abaddon
add temporary row for non-joined threads
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user