refactor, update user mention handling
This commit is contained in:
@@ -863,7 +863,7 @@ Gtk::TreeModel::iterator ChannelList::CreateVoiceParticipantRow(const UserData &
|
||||
auto row = *m_model->append(parent);
|
||||
row[m_columns.m_type] = RenderType::VoiceParticipant;
|
||||
row[m_columns.m_id] = user.ID;
|
||||
row[m_columns.m_name] = user.GetEscapedName();
|
||||
row[m_columns.m_name] = user.GetDisplayNameEscaped();
|
||||
|
||||
const auto voice_state = Abaddon::Get().GetDiscordClient().GetVoiceState(user.ID);
|
||||
if (voice_state.has_value()) {
|
||||
|
@@ -234,23 +234,23 @@ void ChatMessageItemContainer::UpdateTextComponent(Gtk::TextView *tv) {
|
||||
} break;
|
||||
case MessageType::CHANNEL_NAME_CHANGE: {
|
||||
const auto author = Abaddon::Get().GetDiscordClient().GetUser(data->Author.ID);
|
||||
b->insert_markup(s, "<i><span color='#999999'>" + author->GetEscapedBoldName() + " changed the name to <b>" + Glib::Markup::escape_text(data->Content) + "</b></span></i>");
|
||||
b->insert_markup(s, "<i><span color='#999999'>" + author->GetDisplayNameEscapedBold() + " changed the name to <b>" + Glib::Markup::escape_text(data->Content) + "</b></span></i>");
|
||||
} break;
|
||||
case MessageType::CHANNEL_ICON_CHANGE: {
|
||||
const auto author = Abaddon::Get().GetDiscordClient().GetUser(data->Author.ID);
|
||||
b->insert_markup(s, "<i><span color='#999999'>" + author->GetEscapedBoldName() + " changed the channel icon</span></i>");
|
||||
b->insert_markup(s, "<i><span color='#999999'>" + author->GetDisplayNameEscapedBold() + " changed the channel icon</span></i>");
|
||||
} break;
|
||||
case MessageType::USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1:
|
||||
case MessageType::USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2:
|
||||
case MessageType::USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3: {
|
||||
const auto author = Abaddon::Get().GetDiscordClient().GetUser(data->Author.ID);
|
||||
const auto guild = Abaddon::Get().GetDiscordClient().GetGuild(*data->GuildID);
|
||||
b->insert_markup(s, "<i><span color='#999999'>" + author->GetEscapedBoldName() + " just boosted the server <b>" + Glib::Markup::escape_text(data->Content) + "</b> times! " +
|
||||
b->insert_markup(s, "<i><span color='#999999'>" + author->GetDisplayNameEscapedBold() + " just boosted the server <b>" + Glib::Markup::escape_text(data->Content) + "</b> times! " +
|
||||
Glib::Markup::escape_text(guild->Name) + " has achieved <b>Level " + std::to_string(static_cast<int>(data->Type) - 8) + "!</b></span></i>"); // oo cheeky me !!!
|
||||
} break;
|
||||
case MessageType::CHANNEL_FOLLOW_ADD: {
|
||||
const auto author = Abaddon::Get().GetDiscordClient().GetUser(data->Author.ID);
|
||||
b->insert_markup(s, "<i><span color='#999999'>" + author->GetEscapedBoldName() + " has added <b>" + Glib::Markup::escape_text(data->Content) + "</b> to this channel. Its most important updates will show up here.</span></i>");
|
||||
b->insert_markup(s, "<i><span color='#999999'>" + author->GetDisplayNameEscapedBold() + " has added <b>" + Glib::Markup::escape_text(data->Content) + "</b> to this channel. Its most important updates will show up here.</span></i>");
|
||||
} break;
|
||||
case MessageType::CALL: {
|
||||
b->insert_markup(s, "<span color='#999999'><i>[started a call]</i></span>");
|
||||
@@ -270,13 +270,13 @@ void ChatMessageItemContainer::UpdateTextComponent(Gtk::TextView *tv) {
|
||||
case MessageType::THREAD_CREATED: {
|
||||
const auto author = Abaddon::Get().GetDiscordClient().GetUser(data->Author.ID);
|
||||
if (data->MessageReference.has_value() && data->MessageReference->ChannelID.has_value()) {
|
||||
auto iter = b->insert_markup(s, "<i><span color='#999999'>" + author->GetEscapedBoldName() + " started a thread: </span></i>");
|
||||
auto iter = b->insert_markup(s, "<i><span color='#999999'>" + author->GetDisplayNameEscapedBold() + " started a thread: </span></i>");
|
||||
auto tag = b->create_tag();
|
||||
tag->property_weight() = Pango::WEIGHT_BOLD;
|
||||
m_channel_tagmap[tag] = *data->MessageReference->ChannelID;
|
||||
b->insert_with_tag(iter, data->Content, tag);
|
||||
} else {
|
||||
b->insert_markup(s, "<i><span color='#999999'>" + author->GetEscapedBoldName() + " started a thread: </span><b>" + Glib::Markup::escape_text(data->Content) + "</b></i>");
|
||||
b->insert_markup(s, "<i><span color='#999999'>" + author->GetDisplayNameEscapedBold() + " started a thread: </span><b>" + Glib::Markup::escape_text(data->Content) + "</b></i>");
|
||||
}
|
||||
} break;
|
||||
default: break;
|
||||
@@ -656,7 +656,7 @@ Gtk::Widget *ChatMessageItemContainer::CreateReplyComponent(const Message &data)
|
||||
if (role.has_value()) {
|
||||
const auto author = discord.GetUser(author_id);
|
||||
if (author.has_value()) {
|
||||
return "<b><span color=\"#" + IntToCSSColor(role->Color) + "\">" + author->GetEscapedString() + "</span></b>";
|
||||
return "<b><span color=\"#" + IntToCSSColor(role->Color) + "\">" + author->GetUsernameEscaped() + "</span></b>";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -664,7 +664,7 @@ Gtk::Widget *ChatMessageItemContainer::CreateReplyComponent(const Message &data)
|
||||
|
||||
const auto author = discord.GetUser(author_id);
|
||||
if (author.has_value()) {
|
||||
return author->GetEscapedBoldString<false>();
|
||||
return author->GetUsernameEscapedBold<false>();
|
||||
}
|
||||
|
||||
return "<b>Unknown User</b>";
|
||||
@@ -685,7 +685,7 @@ Gtk::Widget *ChatMessageItemContainer::CreateReplyComponent(const Message &data)
|
||||
Glib::Markup::escape_text(data.Interaction->Name) +
|
||||
"</span>");
|
||||
} else if (const auto user = discord.GetUser(data.Interaction->User.ID); user.has_value()) {
|
||||
lbl->set_markup(user->GetEscapedBoldString<false>());
|
||||
lbl->set_markup(user->GetUsernameEscapedBold<false>());
|
||||
} else {
|
||||
lbl->set_markup("<b>Unknown User</b>");
|
||||
}
|
||||
@@ -1043,7 +1043,7 @@ void ChatMessageHeader::UpdateName() {
|
||||
else
|
||||
m_author.set_markup("<span weight='bold'>" + name + "</span>");
|
||||
} else
|
||||
m_author.set_markup("<span weight='bold'>" + user->GetEscapedName() + "</span>");
|
||||
m_author.set_markup("<span weight='bold'>" + user->GetDisplayNameEscaped() + "</span>");
|
||||
}
|
||||
|
||||
std::vector<Gtk::Widget *> ChatMessageHeader::GetChildContent() {
|
||||
@@ -1069,7 +1069,7 @@ Glib::ustring ChatMessageHeader::GetEscapedDisplayName(const UserData &user, con
|
||||
if (member.has_value() && !member->Nickname.empty())
|
||||
return Glib::Markup::escape_text(member->Nickname);
|
||||
else
|
||||
return Glib::Markup::escape_text(user.GetEscapedName());
|
||||
return Glib::Markup::escape_text(user.GetDisplayNameEscaped());
|
||||
}
|
||||
|
||||
bool ChatMessageHeader::on_author_button_press(GdkEventButton *ev) {
|
||||
|
@@ -301,7 +301,7 @@ void ChatWindow::StartReplying(Snowflake message_id) {
|
||||
m_is_replying = true;
|
||||
m_input->StartReplying();
|
||||
if (author.has_value())
|
||||
m_input_indicator->SetCustomMarkup("Replying to " + author->GetEscapedBoldString<false>());
|
||||
m_input_indicator->SetCustomMarkup("Replying to " + author->GetUsernameEscapedBold<false>());
|
||||
else
|
||||
m_input_indicator->SetCustomMarkup("Replying...");
|
||||
}
|
||||
|
@@ -265,7 +265,7 @@ FriendsListFriendRow::FriendsListFriendRow(RelationshipType type, const UserData
|
||||
img->SetURL(data.GetAvatarURL("png", "32"));
|
||||
}
|
||||
|
||||
namelbl->set_markup(data.GetEscapedBoldName());
|
||||
namelbl->set_markup(data.GetDisplayNameEscapedBold());
|
||||
|
||||
UpdatePresenceLabel();
|
||||
|
||||
|
@@ -40,7 +40,7 @@ MemberListUserRow::MemberListUserRow(const std::optional<GuildData> &guild, cons
|
||||
// todo remove after migration complete
|
||||
std::string display;
|
||||
if (data.IsPomelo()) {
|
||||
display = data.GetName();
|
||||
display = data.GetDisplayName();
|
||||
} else {
|
||||
display = data.Username;
|
||||
if (Abaddon::Get().GetSettings().ShowMemberListDiscriminators) {
|
||||
|
@@ -62,7 +62,7 @@ FriendPickerDialogItem::FriendPickerDialogItem(Snowflake user_id)
|
||||
, m_layout(Gtk::ORIENTATION_HORIZONTAL) {
|
||||
auto user = *Abaddon::Get().GetDiscordClient().GetUser(user_id);
|
||||
|
||||
m_name.set_markup(user.GetEscapedBoldString<false>());
|
||||
m_name.set_markup(user.GetUsernameEscapedBold<false>());
|
||||
m_name.set_single_line_mode(true);
|
||||
|
||||
m_avatar.property_pixbuf() = Abaddon::Get().GetImageManager().GetPlaceholder(32);
|
||||
|
@@ -81,7 +81,7 @@ std::string UserData::GetMention() const {
|
||||
return "<@" + std::to_string(ID) + ">";
|
||||
}
|
||||
|
||||
std::string UserData::GetName() const {
|
||||
std::string UserData::GetDisplayName() const {
|
||||
if (IsPomelo() && GlobalName.has_value()) {
|
||||
return *GlobalName;
|
||||
}
|
||||
@@ -97,19 +97,19 @@ std::string UserData::GetUsername() const {
|
||||
return Username + "#" + Discriminator;
|
||||
}
|
||||
|
||||
std::string UserData::GetEscapedName() const {
|
||||
return Glib::Markup::escape_text(GetName());
|
||||
std::string UserData::GetDisplayNameEscaped() const {
|
||||
return Glib::Markup::escape_text(GetDisplayName());
|
||||
}
|
||||
|
||||
std::string UserData::GetEscapedBoldName() const {
|
||||
return "<b>" + Glib::Markup::escape_text(GetName()) + "</b>";
|
||||
std::string UserData::GetDisplayNameEscapedBold() const {
|
||||
return "<b>" + Glib::Markup::escape_text(GetDisplayName()) + "</b>";
|
||||
}
|
||||
|
||||
std::string UserData::GetEscapedString() const {
|
||||
std::string UserData::GetUsernameEscaped() const {
|
||||
if (IsPomelo()) {
|
||||
return GetEscapedName();
|
||||
return GetDisplayNameEscaped();
|
||||
}
|
||||
return Glib::Markup::escape_text(GetName()) + "#" + Discriminator;
|
||||
return Glib::Markup::escape_text(GetDisplayName()) + "#" + Discriminator;
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json &j, UserData &m) {
|
||||
|
@@ -79,16 +79,22 @@ struct UserData {
|
||||
[[nodiscard]] std::string GetDefaultAvatarURL() const;
|
||||
[[nodiscard]] Snowflake GetHoistedRole(Snowflake guild_id, bool with_color = false) const;
|
||||
[[nodiscard]] std::string GetMention() const;
|
||||
[[nodiscard]] std::string GetName() const;
|
||||
[[nodiscard]] std::string GetDisplayName() const;
|
||||
[[nodiscard]] std::string GetDisplayNameEscaped() const;
|
||||
[[nodiscard]] std::string GetDisplayNameEscapedBold() const;
|
||||
[[nodiscard]] std::string GetUsername() const;
|
||||
[[nodiscard]] std::string GetEscapedName() const;
|
||||
[[nodiscard]] std::string GetEscapedBoldName() const;
|
||||
[[nodiscard]] std::string GetEscapedString() const;
|
||||
[[nodiscard]] std::string GetUsernameEscaped() const;
|
||||
template<bool with_at>
|
||||
[[nodiscard]] inline std::string GetEscapedBoldString() const {
|
||||
if constexpr (with_at)
|
||||
return "<b>@" + Glib::Markup::escape_text(Username) + "</b>#" + Discriminator;
|
||||
else
|
||||
return "<b>" + Glib::Markup::escape_text(Username) + "</b>#" + Discriminator;
|
||||
[[nodiscard]] inline std::string GetUsernameEscapedBold() const {
|
||||
// stupid microoptimization (nanooptimization) that shouldnt exist
|
||||
if constexpr (with_at) {
|
||||
std::string r = "<b>@" + Glib::Markup::escape_text(Username) + "</b>";
|
||||
if (!IsPomelo()) r += "#" + Discriminator;
|
||||
return r;
|
||||
} else {
|
||||
std::string r = "<b>" + Glib::Markup::escape_text(Username) + "</b>";
|
||||
if (!IsPomelo()) r += "#" + Discriminator;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@@ -74,17 +74,17 @@ void HandleUserMentions(const Glib::RefPtr<Gtk::TextBuffer> &buf, Snowflake chan
|
||||
|
||||
if (channel->Type == ChannelType::DM || channel->Type == ChannelType::GROUP_DM || !channel->GuildID.has_value() || plain) {
|
||||
if (plain) {
|
||||
replacement = "@" + user->Username + "#" + user->Discriminator;
|
||||
replacement = "@" + user->GetUsername();
|
||||
} else {
|
||||
replacement = user->GetEscapedBoldString<true>();
|
||||
replacement = user->GetUsernameEscapedBold<true>();
|
||||
}
|
||||
} else {
|
||||
const auto role_id = user->GetHoistedRole(*channel->GuildID, true);
|
||||
const auto role = discord.GetRole(role_id);
|
||||
if (!role.has_value())
|
||||
replacement = user->GetEscapedBoldString<true>();
|
||||
replacement = user->GetUsernameEscapedBold<true>();
|
||||
else
|
||||
replacement = "<span color=\"#" + IntToCSSColor(role->Color) + "\">" + user->GetEscapedBoldString<true>() + "</span>";
|
||||
replacement = "<span color=\"#" + IntToCSSColor(role->Color) + "\">" + user->GetUsernameEscapedBold<true>() + "</span>";
|
||||
}
|
||||
|
||||
// regex returns byte positions and theres no straightforward way in the c++ bindings to deal with that :(
|
||||
|
@@ -38,7 +38,7 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
|
||||
Glib::ustring user_markup = "<b>Unknown User</b>";
|
||||
if (entry.UserID.has_value()) {
|
||||
if (auto user = discord.GetUser(*entry.UserID); user.has_value())
|
||||
user_markup = discord.GetUser(*entry.UserID)->GetEscapedBoldString<false>();
|
||||
user_markup = discord.GetUser(*entry.UserID)->GetUsernameEscapedBold<false>();
|
||||
}
|
||||
|
||||
// spaghetti moment
|
||||
@@ -177,7 +177,7 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
|
||||
const auto target_user = discord.GetUser(entry.TargetID);
|
||||
markup = user_markup +
|
||||
" kicked <b>" +
|
||||
target_user->GetEscapedString() +
|
||||
target_user->GetUsernameEscaped() +
|
||||
"</b>";
|
||||
} break;
|
||||
case AuditLogActionType::MEMBER_PRUNE: {
|
||||
@@ -193,21 +193,21 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
|
||||
const auto target_user = discord.GetUser(entry.TargetID);
|
||||
markup = user_markup +
|
||||
" banned <b>" +
|
||||
target_user->GetEscapedString() +
|
||||
target_user->GetUsernameEscaped() +
|
||||
"</b>";
|
||||
} break;
|
||||
case AuditLogActionType::MEMBER_BAN_REMOVE: {
|
||||
const auto target_user = discord.GetUser(entry.TargetID);
|
||||
markup = user_markup +
|
||||
" removed the ban for <b>" +
|
||||
target_user->GetEscapedString() +
|
||||
target_user->GetUsernameEscaped() +
|
||||
"</b>";
|
||||
} break;
|
||||
case AuditLogActionType::MEMBER_UPDATE: {
|
||||
const auto target_user = discord.GetUser(entry.TargetID);
|
||||
markup = user_markup +
|
||||
" updated <b>" +
|
||||
target_user->GetEscapedString() +
|
||||
target_user->GetUsernameEscaped() +
|
||||
"</b>";
|
||||
if (entry.Changes.has_value())
|
||||
for (const auto &change : *entry.Changes) {
|
||||
@@ -227,7 +227,7 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
|
||||
const auto target_user = discord.GetUser(entry.TargetID);
|
||||
markup = user_markup +
|
||||
" updated roles for <b>" +
|
||||
target_user->GetEscapedString() + "</b>";
|
||||
target_user->GetUsernameEscaped() + "</b>";
|
||||
if (entry.Changes.has_value())
|
||||
for (const auto &change : *entry.Changes) {
|
||||
if (change.Key == "$remove" && change.NewValue.has_value()) {
|
||||
@@ -262,7 +262,7 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
|
||||
const auto target_user = discord.GetUser(entry.TargetID);
|
||||
markup = user_markup +
|
||||
" added <b>" +
|
||||
target_user->GetEscapedString() +
|
||||
target_user->GetUsernameEscaped() +
|
||||
"</b> to the server";
|
||||
} break;
|
||||
case AuditLogActionType::ROLE_CREATE: {
|
||||
@@ -450,14 +450,14 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
|
||||
const auto target_user = discord.GetUser(entry.TargetID);
|
||||
markup = user_markup +
|
||||
" pinned a message by <b>" +
|
||||
target_user->GetEscapedString() +
|
||||
target_user->GetUsernameEscaped() +
|
||||
"</b>";
|
||||
} break;
|
||||
case AuditLogActionType::MESSAGE_UNPIN: {
|
||||
const auto target_user = discord.GetUser(entry.TargetID);
|
||||
markup = user_markup +
|
||||
" unpinned a message by <b>" +
|
||||
target_user->GetEscapedString() +
|
||||
target_user->GetUsernameEscaped() +
|
||||
"</b>";
|
||||
} break;
|
||||
case AuditLogActionType::STAGE_INSTANCE_CREATE: {
|
||||
|
@@ -150,9 +150,9 @@ void GuildSettingsMembersListItem::UpdateColor() {
|
||||
const auto user = *discord.GetUser(UserID);
|
||||
if (auto color_id = discord.GetMemberHoistedRole(GuildID, UserID, true); color_id.IsValid()) {
|
||||
auto role = *discord.GetRole(color_id);
|
||||
m_name.set_markup("<span color='#" + IntToCSSColor(role.Color) + "'>" + user.GetEscapedBoldString<false>() + "</span>");
|
||||
m_name.set_markup("<span color='#" + IntToCSSColor(role.Color) + "'>" + user.GetUsernameEscapedBold<false>() + "</span>");
|
||||
} else
|
||||
m_name.set_markup(user.GetEscapedBoldString<false>());
|
||||
m_name.set_markup(user.GetUsernameEscapedBold<false>());
|
||||
}
|
||||
|
||||
GuildSettingsMembersPaneInfo::GuildSettingsMembersPaneInfo(Snowflake guild_id)
|
||||
|
@@ -22,7 +22,7 @@ MutualFriendItem::MutualFriendItem(const UserData &user)
|
||||
img.LoadFromURL(user.GetAvatarURL("png", "32"), sigc::track_obj(cb, *this));
|
||||
}
|
||||
|
||||
m_name.set_markup(user.GetEscapedBoldString<false>());
|
||||
m_name.set_markup(user.GetUsernameEscapedBold<false>());
|
||||
|
||||
m_name.set_valign(Gtk::ALIGN_CENTER);
|
||||
add(m_avatar);
|
||||
|
@@ -64,7 +64,7 @@ ProfileWindow::ProfileWindow(Snowflake user_id)
|
||||
img.LoadFromURL(user.GetAvatarURL("png", "64"), sigc::track_obj(cb, *this));
|
||||
}
|
||||
|
||||
m_displayname.set_markup(user.GetEscapedName());
|
||||
m_displayname.set_markup(user.GetDisplayNameEscaped());
|
||||
m_username.set_label(user.GetUsername());
|
||||
|
||||
m_switcher.set_stack(m_stack);
|
||||
|
Reference in New Issue
Block a user