summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/components/channels.cpp12
-rw-r--r--src/discord/channel.cpp40
-rw-r--r--src/discord/channel.hpp1
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<int64_t>(-(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<Gdk::Pixbuf> &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<int64_t>(-(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<Gdk::Pixbuf> &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<Snowflake> ChannelData::GetChildIDs() const {
@@ -139,6 +142,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;
}
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<Snowflake> GetChildIDs() const;
[[nodiscard]] std::optional<PermissionOverwrite> GetOverwrite(Snowflake id) const;
[[nodiscard]] std::vector<UserData> GetDMRecipients() const;
+ [[nodiscard]] std::string GetRecipientsDisplay() const;
};