use display name in typing indicator
This commit is contained in:
@@ -54,6 +54,12 @@ void ChatInputIndicator::AddUser(Snowflake channel_id, const UserData &user, int
|
||||
|
||||
void ChatInputIndicator::SetActiveChannel(Snowflake id) {
|
||||
m_active_channel = id;
|
||||
const auto channel = Abaddon::Get().GetDiscordClient().GetChannel(id);
|
||||
if (channel.has_value()) {
|
||||
m_active_guild = channel->GuildID;
|
||||
} else {
|
||||
m_active_guild = std::nullopt;
|
||||
}
|
||||
ComputeTypingString();
|
||||
}
|
||||
|
||||
@@ -105,14 +111,14 @@ void ChatInputIndicator::ComputeTypingString() {
|
||||
if (typers.empty()) {
|
||||
SetTypingString("");
|
||||
} else if (typers.size() == 1) {
|
||||
SetTypingString(typers[0].Username + " is typing...");
|
||||
SetTypingString(typers[0].GetDisplayName(m_active_guild) + " is typing...");
|
||||
} else if (typers.size() == 2) {
|
||||
SetTypingString(typers[0].Username + " and " + typers[1].Username + " are typing...");
|
||||
SetTypingString(typers[0].GetDisplayName(m_active_guild) + " and " + typers[1].GetDisplayName(m_active_guild) + " are typing...");
|
||||
} else if (typers.size() > 2 && typers.size() <= MaxUsersInIndicator) {
|
||||
Glib::ustring str;
|
||||
for (size_t i = 0; i < typers.size() - 1; i++)
|
||||
str += typers[i].Username + ", ";
|
||||
SetTypingString(str + "and " + typers[typers.size() - 1].Username + " are typing...");
|
||||
str += typers[i].GetDisplayName(m_active_guild) + ", ";
|
||||
SetTypingString(str + "and " + typers[typers.size() - 1].GetDisplayName(m_active_guild) + " are typing...");
|
||||
} else { // size() > MaxUsersInIndicator
|
||||
SetTypingString("Several people are typing...");
|
||||
}
|
||||
|
@@ -23,5 +23,6 @@ private:
|
||||
Glib::ustring m_custom_markup;
|
||||
|
||||
Snowflake m_active_channel;
|
||||
std::optional<Snowflake> m_active_guild;
|
||||
std::unordered_map<Snowflake, std::unordered_map<Snowflake, sigc::connection>> m_typers; // channel id -> [user id -> connection]
|
||||
};
|
||||
|
@@ -97,6 +97,13 @@ std::string UserData::GetDisplayName(Snowflake guild_id) const {
|
||||
return GetDisplayName();
|
||||
}
|
||||
|
||||
std::string UserData::GetDisplayName(const std::optional<Snowflake> &guild_id) const {
|
||||
if (guild_id.has_value()) {
|
||||
return GetDisplayName(*guild_id);
|
||||
}
|
||||
return GetDisplayName();
|
||||
}
|
||||
|
||||
std::string UserData::GetDisplayNameEscaped() const {
|
||||
return Glib::Markup::escape_text(GetDisplayName());
|
||||
}
|
||||
|
@@ -81,6 +81,7 @@ struct UserData {
|
||||
[[nodiscard]] std::string GetMention() const;
|
||||
[[nodiscard]] std::string GetDisplayName() const;
|
||||
[[nodiscard]] std::string GetDisplayName(Snowflake guild_id) const;
|
||||
[[nodiscard]] std::string GetDisplayName(const std::optional<Snowflake> &guild_id) const;
|
||||
[[nodiscard]] std::string GetDisplayNameEscaped() const;
|
||||
[[nodiscard]] std::string GetDisplayNameEscaped(Snowflake guild_id) const;
|
||||
[[nodiscard]] std::string GetDisplayNameEscapedBold() const;
|
||||
|
Reference in New Issue
Block a user