mimic discord group dm naming scheme (closes #133)
This commit is contained in:
@@ -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)
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user