diff options
-rw-r--r-- | src/components/chatinputindicator.cpp | 14 | ||||
-rw-r--r-- | src/components/chatinputindicator.hpp | 1 | ||||
-rw-r--r-- | src/discord/user.cpp | 7 | ||||
-rw-r--r-- | src/discord/user.hpp | 1 |
4 files changed, 19 insertions, 4 deletions
diff --git a/src/components/chatinputindicator.cpp b/src/components/chatinputindicator.cpp index 13315c6..0611e71 100644 --- a/src/components/chatinputindicator.cpp +++ b/src/components/chatinputindicator.cpp @@ -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..."); } diff --git a/src/components/chatinputindicator.hpp b/src/components/chatinputindicator.hpp index 40c966e..5688393 100644 --- a/src/components/chatinputindicator.hpp +++ b/src/components/chatinputindicator.hpp @@ -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] }; diff --git a/src/discord/user.cpp b/src/discord/user.cpp index 0f89fe2..f43284f 100644 --- a/src/discord/user.cpp +++ b/src/discord/user.cpp @@ -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()); } diff --git a/src/discord/user.hpp b/src/discord/user.hpp index 29de62a..8b2a2c4 100644 --- a/src/discord/user.hpp +++ b/src/discord/user.hpp @@ -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; |