diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-10-08 17:52:38 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-10-08 17:52:38 -0400 |
commit | fa1a007dc12208a90c278cb426c37c9a24079636 (patch) | |
tree | 94ce7cb7a88f6e5c3144ae5e46a5cdb776237970 /components | |
parent | abc0a7931e64cfe3db65dd85c26d0de1be1817a0 (diff) | |
download | abaddon-portaudio-fa1a007dc12208a90c278cb426c37c9a24079636.tar.gz abaddon-portaudio-fa1a007dc12208a90c278cb426c37c9a24079636.zip |
fix unchecked optionals
also discard exceptions in file cache futures
Diffstat (limited to 'components')
-rw-r--r-- | components/channels.cpp | 2 | ||||
-rw-r--r-- | components/chatlist.cpp | 14 | ||||
-rw-r--r-- | components/chatmessage.cpp | 29 | ||||
-rw-r--r-- | components/memberlist.cpp | 2 | ||||
-rw-r--r-- | components/ratelimitindicator.cpp | 1 |
5 files changed, 29 insertions, 19 deletions
diff --git a/components/channels.cpp b/components/channels.cpp index 98604d7..ac11a0c 100644 --- a/components/channels.cpp +++ b/components/channels.cpp @@ -227,7 +227,7 @@ void ChannelList::UpdateChannel(Snowflake id) { Gtk::TreeModel::iterator new_parent; if (channel->ParentID.has_value()) new_parent = GetIteratorForChannelFromID(*channel->ParentID); - else + else if (channel->GuildID.has_value()) new_parent = GetIteratorForGuildFromID(*channel->GuildID); if (new_parent && iter->parent() != new_parent) diff --git a/components/chatlist.cpp b/components/chatlist.cpp index 01f1629..96d8de2 100644 --- a/components/chatlist.cpp +++ b/components/chatlist.cpp @@ -139,7 +139,10 @@ void ChatList::ProcessNewMessage(const Message &data, bool prepend) { if (should_attach) { header = last_row; } else { - const auto guild_id = *discord.GetChannel(m_active_channel)->GuildID; + const auto chan = discord.GetChannel(m_active_channel); + Snowflake guild_id; + if (chan.has_value() && chan->GuildID.has_value()) + guild_id = *chan->GuildID; const auto user_id = data.Author.ID; const auto user = discord.GetUser(user_id); if (!user.has_value()) return; @@ -170,13 +173,14 @@ void ChatList::ProcessNewMessage(const Message &data, bool prepend) { if (!data.has_value()) return false; const auto channel = client.GetChannel(m_active_channel); - bool is_dm = channel.has_value() && (channel->Type == ChannelType::DM || channel->Type == ChannelType::GROUP_DM); - const bool has_manage = client.HasChannelPermission(client.GetUserData().ID, m_active_channel, Permission::MANAGE_MESSAGES); + bool has_manage = channel.has_value() && (channel->Type == ChannelType::DM || channel->Type == ChannelType::GROUP_DM); + if (!has_manage) + has_manage = client.HasChannelPermission(client.GetUserData().ID, m_active_channel, Permission::MANAGE_MESSAGES); m_menu_edit_message->set_visible(!m_use_pinned_menu); m_menu_reply_to->set_visible(!m_use_pinned_menu); - m_menu_unpin->set_visible((is_dm || has_manage) && data->IsPinned); - m_menu_pin->set_visible((is_dm || has_manage) && !data->IsPinned); + m_menu_unpin->set_visible(has_manage && data->IsPinned); + m_menu_pin->set_visible(has_manage && !data->IsPinned); if (data->IsDeleted()) { m_menu_delete_message->set_sensitive(false); diff --git a/components/chatmessage.cpp b/components/chatmessage.cpp index 88e3f2c..220ae89 100644 --- a/components/chatmessage.cpp +++ b/components/chatmessage.cpp @@ -692,7 +692,10 @@ Gtk::Widget *ChatMessageItemContainer::CreateReplyComponent(const Message &data) // which of course would not be an issue if i could figure out how to get fonts to work on this god-forsaken framework // oh well // but ill manually get colors for the user who is being replied to - lbl->set_markup(get_author_markup(referenced.Author.ID, *referenced.GuildID) + ": " + text); + if (referenced.GuildID.has_value()) + lbl->set_markup(get_author_markup(referenced.Author.ID, *referenced.GuildID) + ": " + text); + else + lbl->set_markup(get_author_markup(referenced.Author.ID) + ": " + text); } } else { lbl->set_markup("<i>reply unavailable</i>"); @@ -1163,19 +1166,21 @@ ChatMessageHeader::ChatMessageHeader(const Message &data) void ChatMessageHeader::UpdateNameColor() { const auto &discord = Abaddon::Get().GetDiscordClient(); - const auto guild_id = discord.GetChannel(ChannelID)->GuildID; - const auto role_id = discord.GetMemberHoistedRole(*guild_id, UserID, true); const auto user = discord.GetUser(UserID); if (!user.has_value()) return; - const auto role = discord.GetRole(role_id); - - std::string md; - if (role.has_value()) - md = "<span weight='bold' color='#" + IntToCSSColor(role->Color) + "'>" + user->GetEscapedName() + "</span>"; - else - md = "<span weight='bold'>" + user->GetEscapedName() + "</span>"; - - m_author.set_markup(md); + const auto chan = discord.GetChannel(ChannelID); + bool is_guild = chan.has_value() && chan->GuildID.has_value(); + if (is_guild) { + const auto role_id = discord.GetMemberHoistedRole(*chan->GuildID, UserID, true); + const auto role = discord.GetRole(role_id); + + std::string md; + if (role.has_value()) + m_author.set_markup("<span weight='bold' color='#" + IntToCSSColor(role->Color) + "'>" + user->GetEscapedName() + "</span>"); + else + m_author.set_markup("<span weight='bold'>" + user->GetEscapedName() + "</span>"); + } else + m_author.set_markup("<span weight='bold'>" + user->GetEscapedName() + "</span>"); } std::vector<Gtk::Widget *> ChatMessageHeader::GetChildContent() { diff --git a/components/memberlist.cpp b/components/memberlist.cpp index 804f443..ffc210b 100644 --- a/components/memberlist.cpp +++ b/components/memberlist.cpp @@ -94,7 +94,7 @@ void MemberList::SetActiveChannel(Snowflake id) { m_guild_id = Snowflake::Invalid; if (m_chan_id.IsValid()) { const auto chan = Abaddon::Get().GetDiscordClient().GetChannel(id); - if (chan.has_value()) m_guild_id = *chan->GuildID; + if (chan.has_value() && chan->GuildID.has_value()) m_guild_id = *chan->GuildID; } } diff --git a/components/ratelimitindicator.cpp b/components/ratelimitindicator.cpp index 708ab34..fe187db 100644 --- a/components/ratelimitindicator.cpp +++ b/components/ratelimitindicator.cpp @@ -106,6 +106,7 @@ bool RateLimitIndicator::UpdateIndicator() { void RateLimitIndicator::OnMessageCreate(const Message &message) { auto &discord = Abaddon::Get().GetDiscordClient(); if (message.Author.ID != discord.GetUserData().ID) return; + if (!message.GuildID.has_value()) return; const bool can_bypass = discord.HasAnyChannelPermission(discord.GetUserData().ID, m_active_channel, Permission::MANAGE_MESSAGES | Permission::MANAGE_CHANNELS); const auto rate_limit = GetRateLimit(); if (rate_limit > 0 && !can_bypass) { |