fix tab titles

This commit is contained in:
ouwou
2022-04-14 00:11:39 -04:00
parent d36fe4d0e9
commit 34f8af599d
3 changed files with 15 additions and 1 deletions

View File

@@ -70,7 +70,7 @@ void ChannelTabSwitcherHandy::ReplaceActiveTab(Snowflake id) {
const auto channel = discord.GetChannel(id);
if (!channel.has_value()) return;
hdy_tab_page_set_title(page, ("#" + *channel->Name).c_str());
hdy_tab_page_set_title(page, channel->GetDisplayName().c_str());
ClearPage(page);
m_pages[id] = page;

View File

@@ -92,6 +92,19 @@ std::string ChannelData::GetIconURL() const {
return "https://cdn.discordapp.com/channel-icons/" + std::to_string(ID) + "/" + *Icon + ".png";
}
std::string ChannelData::GetDisplayName() const {
if (Name.has_value()) {
return "#" + *Name;
} else {
const auto recipients = GetDMRecipients();
if (Type == ChannelType::DM && !recipients.empty())
return recipients[0].Username;
else if (Type == ChannelType::GROUP_DM)
return std::to_string(recipients.size()) + " members";
}
return "Unknown";
}
std::vector<Snowflake> ChannelData::GetChildIDs() const {
return Abaddon::Get().GetDiscordClient().GetChildChannelIDs(ID);
}

View File

@@ -102,6 +102,7 @@ struct ChannelData {
[[nodiscard]] bool IsText() const noexcept;
[[nodiscard]] bool HasIcon() const noexcept;
[[nodiscard]] std::string GetIconURL() const;
[[nodiscard]] std::string GetDisplayName() const;
[[nodiscard]] std::vector<Snowflake> GetChildIDs() const;
[[nodiscard]] std::optional<PermissionOverwrite> GetOverwrite(Snowflake id) const;
[[nodiscard]] std::vector<UserData> GetDMRecipients() const;