From fea6db3394d0283d28b7e03b74c34b0296b9b59f Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 21 Jan 2023 01:02:14 -0500 Subject: mimic discord group dm naming scheme (closes #133) --- src/components/channels.cpp | 12 ++---------- src/discord/channel.cpp | 40 +++++++++++++++++++++++++++++++--------- src/discord/channel.hpp | 1 + 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/components/channels.cpp b/src/components/channels.cpp index 497c021..88e5a71 100644 --- a/src/components/channels.cpp +++ b/src/components/channels.cpp @@ -759,14 +759,10 @@ void ChannelList::AddPrivateChannels() { auto row = *iter; row[m_columns.m_type] = RenderType::DM; row[m_columns.m_id] = dm_id; + row[m_columns.m_name] = Glib::Markup::escape_text(dm->GetDisplayName()); row[m_columns.m_sort] = static_cast(-(dm->LastMessageID.has_value() ? *dm->LastMessageID : dm_id)); row[m_columns.m_icon] = img.GetPlaceholder(DMIconSize); - if (dm->Type == ChannelType::DM && top_recipient.has_value()) - row[m_columns.m_name] = Glib::Markup::escape_text(top_recipient->Username); - else if (dm->Type == ChannelType::GROUP_DM) - row[m_columns.m_name] = std::to_string(recipients.size()) + " members"; - if (dm->HasIcon()) { const auto cb = [this, iter](const Glib::RefPtr &pb) { if (iter) @@ -796,14 +792,10 @@ void ChannelList::UpdateCreateDMChannel(const ChannelData &dm) { auto row = *iter; row[m_columns.m_type] = RenderType::DM; row[m_columns.m_id] = dm.ID; + row[m_columns.m_name] = Glib::Markup::escape_text(dm.GetDisplayName()); row[m_columns.m_sort] = static_cast(-(dm.LastMessageID.has_value() ? *dm.LastMessageID : dm.ID)); row[m_columns.m_icon] = img.GetPlaceholder(DMIconSize); - if (dm.Type == ChannelType::DM && top_recipient.has_value()) - row[m_columns.m_name] = Glib::Markup::escape_text(top_recipient->Username); - else if (dm.Type == ChannelType::GROUP_DM) - row[m_columns.m_name] = std::to_string(recipients.size()) + " members"; - if (top_recipient.has_value()) { const auto cb = [this, iter](const Glib::RefPtr &pb) { if (iter) diff --git a/src/discord/channel.cpp b/src/discord/channel.cpp index 498b2e5..1806201 100644 --- a/src/discord/channel.cpp +++ b/src/discord/channel.cpp @@ -84,6 +84,10 @@ bool ChannelData::IsCategory() const noexcept { return Type == ChannelType::GUILD_CATEGORY; } +bool ChannelData::IsText() const noexcept { + return Type == ChannelType::GUILD_TEXT || Type == ChannelType::GUILD_NEWS; +} + bool ChannelData::HasIcon() const noexcept { return Icon.has_value(); } @@ -102,15 +106,14 @@ std::string ChannelData::GetIconURL() const { std::string ChannelData::GetDisplayName() const { if (Name.has_value()) { - return "#" + *Name; + if (IsDM()) { + return *Name; + } else { + 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 GetRecipientsDisplay(); } - return "Unknown"; } std::vector ChannelData::GetChildIDs() const { @@ -139,6 +142,25 @@ std::vector ChannelData::GetDMRecipients() const { return {}; } -bool ChannelData::IsText() const noexcept { - return Type == ChannelType::GUILD_TEXT || Type == ChannelType::GUILD_NEWS; + +std::string ChannelData::GetRecipientsDisplay() const { + const auto self_id = Abaddon::Get().GetDiscordClient().GetUserData().ID; + const auto recipients = GetDMRecipients(); + + if (Type == ChannelType::DM && !recipients.empty()) { + return recipients[0].Username; + } + + Glib::ustring r; + for (size_t i = 0; i < recipients.size(); i++) { + const auto &recipient = recipients[i]; + r += recipient.Username; + if (i < recipients.size() - 1) { + r += ", "; + } + } + + if (r.empty()) r = "Unnamed"; + + return r; } diff --git a/src/discord/channel.hpp b/src/discord/channel.hpp index 77cf029..df944ec 100644 --- a/src/discord/channel.hpp +++ b/src/discord/channel.hpp @@ -106,4 +106,5 @@ struct ChannelData { [[nodiscard]] std::vector GetChildIDs() const; [[nodiscard]] std::optional GetOverwrite(Snowflake id) const; [[nodiscard]] std::vector GetDMRecipients() const; + [[nodiscard]] std::string GetRecipientsDisplay() const; }; -- cgit v1.2.3