diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-02-07 15:03:03 -0500 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-02-07 15:03:03 -0500 |
commit | c1303bd289013a504b529f8f19444f12e4884040 (patch) | |
tree | 9318ba0b3b660264cba5c4a467b6f79cf80188e0 /src/discord/channel.cpp | |
parent | ea04035f0db8fa990dd7ca8dd1a64f56bceb82e2 (diff) | |
parent | 4dd0eb24c40a7276dea4fc349d885f4277795dcb (diff) | |
download | abaddon-portaudio-c1303bd289013a504b529f8f19444f12e4884040.tar.gz abaddon-portaudio-c1303bd289013a504b529f8f19444f12e4884040.zip |
Merge branch 'master' into voice
Diffstat (limited to 'src/discord/channel.cpp')
-rw-r--r-- | src/discord/channel.cpp | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/src/discord/channel.cpp b/src/discord/channel.cpp index 498b2e5..4b1d909 100644 --- a/src/discord/channel.cpp +++ b/src/discord/channel.cpp @@ -1,4 +1,3 @@ -#include "abaddon.hpp" #include "channel.hpp" void from_json(const nlohmann::json &j, ThreadMetadataData &m) { @@ -84,6 +83,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 +105,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<Snowflake> ChannelData::GetChildIDs() const { @@ -139,6 +141,25 @@ std::vector<UserData> 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; } |