mimic discord group dm naming scheme (closes #133)

This commit is contained in:
ouwou
2023-01-21 01:02:14 -05:00
parent dc7047265f
commit fea6db3394
3 changed files with 34 additions and 19 deletions

View File

@@ -759,14 +759,10 @@ void ChannelList::AddPrivateChannels() {
auto row = *iter; auto row = *iter;
row[m_columns.m_type] = RenderType::DM; row[m_columns.m_type] = RenderType::DM;
row[m_columns.m_id] = dm_id; 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_sort] = static_cast<int64_t>(-(dm->LastMessageID.has_value() ? *dm->LastMessageID : dm_id));
row[m_columns.m_icon] = img.GetPlaceholder(DMIconSize); 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()) { if (dm->HasIcon()) {
const auto cb = [this, iter](const Glib::RefPtr<Gdk::Pixbuf> &pb) { const auto cb = [this, iter](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
if (iter) if (iter)
@@ -796,14 +792,10 @@ void ChannelList::UpdateCreateDMChannel(const ChannelData &dm) {
auto row = *iter; auto row = *iter;
row[m_columns.m_type] = RenderType::DM; row[m_columns.m_type] = RenderType::DM;
row[m_columns.m_id] = dm.ID; 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_sort] = static_cast<int64_t>(-(dm.LastMessageID.has_value() ? *dm.LastMessageID : dm.ID));
row[m_columns.m_icon] = img.GetPlaceholder(DMIconSize); 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()) { if (top_recipient.has_value()) {
const auto cb = [this, iter](const Glib::RefPtr<Gdk::Pixbuf> &pb) { const auto cb = [this, iter](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
if (iter) if (iter)

View File

@@ -84,6 +84,10 @@ bool ChannelData::IsCategory() const noexcept {
return Type == ChannelType::GUILD_CATEGORY; return Type == ChannelType::GUILD_CATEGORY;
} }
bool ChannelData::IsText() const noexcept {
return Type == ChannelType::GUILD_TEXT || Type == ChannelType::GUILD_NEWS;
}
bool ChannelData::HasIcon() const noexcept { bool ChannelData::HasIcon() const noexcept {
return Icon.has_value(); return Icon.has_value();
} }
@@ -102,15 +106,14 @@ std::string ChannelData::GetIconURL() const {
std::string ChannelData::GetDisplayName() const { std::string ChannelData::GetDisplayName() const {
if (Name.has_value()) { if (Name.has_value()) {
return "#" + *Name; if (IsDM()) {
return *Name;
} else {
return "#" + *Name;
}
} else { } else {
const auto recipients = GetDMRecipients(); return GetRecipientsDisplay();
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 { std::vector<Snowflake> ChannelData::GetChildIDs() const {
@@ -139,6 +142,25 @@ std::vector<UserData> ChannelData::GetDMRecipients() const {
return {}; 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;
} }

View File

@@ -106,4 +106,5 @@ struct ChannelData {
[[nodiscard]] std::vector<Snowflake> GetChildIDs() const; [[nodiscard]] std::vector<Snowflake> GetChildIDs() const;
[[nodiscard]] std::optional<PermissionOverwrite> GetOverwrite(Snowflake id) const; [[nodiscard]] std::optional<PermissionOverwrite> GetOverwrite(Snowflake id) const;
[[nodiscard]] std::vector<UserData> GetDMRecipients() const; [[nodiscard]] std::vector<UserData> GetDMRecipients() const;
[[nodiscard]] std::string GetRecipientsDisplay() const;
}; };