forked from OpenGamers/abaddon
dont make requests for inaccessible channels
This commit is contained in:
@@ -512,6 +512,9 @@ void Abaddon::ActionChannelOpened(Snowflake id) {
|
|||||||
|
|
||||||
const auto channel = m_discord.GetChannel(id);
|
const auto channel = m_discord.GetChannel(id);
|
||||||
if (!channel.has_value()) return;
|
if (!channel.has_value()) return;
|
||||||
|
|
||||||
|
const bool can_access = channel->IsDM() || m_discord.HasChannelPermission(m_discord.GetUserData().ID, id, Permission::VIEW_CHANNEL);
|
||||||
|
|
||||||
if (channel->Type == ChannelType::GUILD_TEXT || channel->Type == ChannelType::GUILD_NEWS)
|
if (channel->Type == ChannelType::GUILD_TEXT || channel->Type == ChannelType::GUILD_NEWS)
|
||||||
m_main_window->set_title(std::string(APP_TITLE) + " - #" + *channel->Name);
|
m_main_window->set_title(std::string(APP_TITLE) + " - #" + *channel->Name);
|
||||||
else {
|
else {
|
||||||
@@ -527,23 +530,28 @@ void Abaddon::ActionChannelOpened(Snowflake id) {
|
|||||||
}
|
}
|
||||||
m_main_window->UpdateChatActiveChannel(id);
|
m_main_window->UpdateChatActiveChannel(id);
|
||||||
if (m_channels_requested.find(id) == m_channels_requested.end()) {
|
if (m_channels_requested.find(id) == m_channels_requested.end()) {
|
||||||
m_discord.FetchMessagesInChannel(id, [this, id](const std::vector<Message> &msgs) {
|
// dont fire requests we know will fail
|
||||||
m_main_window->UpdateChatWindowContents();
|
if (can_access) {
|
||||||
m_channels_requested.insert(id);
|
m_discord.FetchMessagesInChannel(id, [this, id](const std::vector<Message> &msgs) {
|
||||||
});
|
m_main_window->UpdateChatWindowContents();
|
||||||
|
m_channels_requested.insert(id);
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
m_main_window->UpdateChatWindowContents();
|
m_main_window->UpdateChatWindowContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel->IsThread()) {
|
if (can_access) {
|
||||||
m_discord.SendThreadLazyLoad(id);
|
if (channel->IsThread()) {
|
||||||
if (channel->ThreadMetadata->IsArchived)
|
m_discord.SendThreadLazyLoad(id);
|
||||||
m_main_window->GetChatWindow()->SetTopic("This thread is archived. Sending a message will unarchive it");
|
if (channel->ThreadMetadata->IsArchived)
|
||||||
} else if (channel->Type != ChannelType::DM && channel->Type != ChannelType::GROUP_DM && channel->GuildID.has_value()) {
|
m_main_window->GetChatWindow()->SetTopic("This thread is archived. Sending a message will unarchive it");
|
||||||
m_discord.SendLazyLoad(id);
|
} else if (channel->Type != ChannelType::DM && channel->Type != ChannelType::GROUP_DM && channel->GuildID.has_value()) {
|
||||||
|
m_discord.SendLazyLoad(id);
|
||||||
|
|
||||||
if (m_discord.IsVerificationRequired(*channel->GuildID))
|
if (m_discord.IsVerificationRequired(*channel->GuildID))
|
||||||
ShowGuildVerificationGateDialog(*channel->GuildID);
|
ShowGuildVerificationGateDialog(*channel->GuildID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,11 @@ bool ChannelData::NSFW() const {
|
|||||||
return IsNSFW.has_value() && *IsNSFW;
|
return IsNSFW.has_value() && *IsNSFW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ChannelData::IsDM() const noexcept {
|
||||||
|
return Type == ChannelType::DM ||
|
||||||
|
Type == ChannelType::GROUP_DM;
|
||||||
|
}
|
||||||
|
|
||||||
bool ChannelData::IsThread() const noexcept {
|
bool ChannelData::IsThread() const noexcept {
|
||||||
return Type == ChannelType::GUILD_PUBLIC_THREAD ||
|
return Type == ChannelType::GUILD_PUBLIC_THREAD ||
|
||||||
Type == ChannelType::GUILD_PRIVATE_THREAD ||
|
Type == ChannelType::GUILD_PRIVATE_THREAD ||
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ struct ChannelData {
|
|||||||
void update_from_json(const nlohmann::json &j);
|
void update_from_json(const nlohmann::json &j);
|
||||||
|
|
||||||
bool NSFW() const;
|
bool NSFW() const;
|
||||||
|
bool IsDM() const noexcept;
|
||||||
bool IsThread() const noexcept;
|
bool IsThread() const noexcept;
|
||||||
bool IsJoinedThread() const;
|
bool IsJoinedThread() const;
|
||||||
std::optional<PermissionOverwrite> GetOverwrite(Snowflake id) const;
|
std::optional<PermissionOverwrite> GetOverwrite(Snowflake id) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user