From af847649a5dccb57a636311dd1927042cc680be2 Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Thu, 2 Nov 2023 15:14:07 +0100 Subject: [PATCH 1/5] Add support for opening usercards by ID --- .../commands/CommandController.cpp | 3 ++- src/widgets/dialogs/UserInfoPopup.cpp | 21 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index 6f69cabf63e..80ec1636591 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -855,7 +855,8 @@ void CommandController::initialize(Settings &, Paths &paths) if (words.size() < 2) { channel->addMessage( - makeSystemMessage("Usage: /usercard [channel]")); + makeSystemMessage("Usage: /usercard [channel] or " + "/usercard # [channel]")); return ""; } diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index 2c48b134eef..ec0c2d72060 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -792,6 +792,14 @@ void UserInfoPopup::updateUserData() return; } + // Correct for when being opened with "id:" + if (this->userName_ != user.login) + { + this->userName_ = user.login; + + // Ensure recent messages are shown + this->updateLatestMessages(); + } this->userId_ = user.id; this->avatarUrl_ = user.profileImageUrl; @@ -909,8 +917,17 @@ void UserInfoPopup::updateUserData() [] {}); }; - getHelix()->getUserByName(this->userName_, onUserFetched, - onUserFetchFailed); + const QString idPrefix = "#"; + if (this->userName_.startsWith(idPrefix)) + { + getHelix()->getUserById(this->userName_.mid(idPrefix.size()), + onUserFetched, onUserFetchFailed); + } + else + { + getHelix()->getUserByName(this->userName_, onUserFetched, + onUserFetchFailed); + } this->ui_.block->setEnabled(false); this->ui_.ignoreHighlights->setEnabled(false); From 1c433ed1f9fc1882f85a285dc42efbabb97d4607 Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Thu, 2 Nov 2023 15:16:15 +0100 Subject: [PATCH 2/5] Changelog for usercard ID addition --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbe665295b7..e1e755d9ab9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Minor: The account switcher is now styled to match your theme. (#4817) - Minor: Add an invisible resize handle to the bottom of frameless user info popups and reply thread popups. (#4795) - Minor: The installer now checks for the VC Runtime version and shows more info when it's outdated. (#4847) +- Minor: The `/usercard` command now accepts user ids. (#4934) - Bugfix: Fixed an issue where certain emojis did not send to Twitch chat correctly. (#4840) - Bugfix: Fixed capitalized channel names in log inclusion list not being logged. (#4848) - Bugfix: Trimmed custom streamlink paths on all platforms making sure you don't accidentally add spaces at the beginning or end of its path. (#4834) From ba4151b774a73424980ab4e918076fa2fb40b2e7 Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Thu, 2 Nov 2023 18:21:14 +0100 Subject: [PATCH 3/5] Move #ID logic to setData to avoid calling updateLatestMessages multiple times --- src/widgets/dialogs/UserInfoPopup.cpp | 32 +++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index ec0c2d72060..84faaeb8f01 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -701,7 +701,18 @@ void UserInfoPopup::setData(const QString &name, const ChannelPtr &contextChannel, const ChannelPtr &openingChannel) { - this->userName_ = name; + const QString idPrefix = "#"; + bool isId = name.startsWith(idPrefix); + if (isId) + { + this->userId_ = name.mid(idPrefix.size()); + this->userName_ = ""; + } + else + { + this->userName_ = name; + } + this->channel_ = openingChannel; if (!contextChannel->isEmpty()) @@ -723,7 +734,11 @@ void UserInfoPopup::setData(const QString &name, this->userStateChanged_.invoke(); - this->updateLatestMessages(); + if (!isId) + { + this->updateLatestMessages(); + } + // If we're opening by ID, this will be called as soon as we get the information from twitch } void UserInfoPopup::updateLatestMessages() @@ -792,14 +807,14 @@ void UserInfoPopup::updateUserData() return; } - // Correct for when being opened with "id:" - if (this->userName_ != user.login) + // Correct for when being opened with ID + if (this->userName_.isEmpty()) { this->userName_ = user.login; - // Ensure recent messages are shown this->updateLatestMessages(); } + this->userId_ = user.id; this->avatarUrl_ = user.profileImageUrl; @@ -917,11 +932,10 @@ void UserInfoPopup::updateUserData() [] {}); }; - const QString idPrefix = "#"; - if (this->userName_.startsWith(idPrefix)) + if (!this->userId_.isEmpty()) { - getHelix()->getUserById(this->userName_.mid(idPrefix.size()), - onUserFetched, onUserFetchFailed); + getHelix()->getUserById(this->userId_, onUserFetched, + onUserFetchFailed); } else { From 0c4afbeb88f389eae522f6dbb8f294286ab485d9 Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Thu, 2 Nov 2023 18:47:13 +0100 Subject: [PATCH 4/5] Make idPrefix a QStringView Co-authored-by: nerix --- src/widgets/dialogs/UserInfoPopup.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index 84faaeb8f01..aaf0e449cbb 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -701,7 +701,7 @@ void UserInfoPopup::setData(const QString &name, const ChannelPtr &contextChannel, const ChannelPtr &openingChannel) { - const QString idPrefix = "#"; + const QStringView idPrefix = u"#"; bool isId = name.startsWith(idPrefix); if (isId) { From 3dfa34f55cfc41fb39c55d0da4010fd511482763 Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Sun, 5 Nov 2023 13:15:24 +0100 Subject: [PATCH 5/5] Switch to "id:" prefix from "#" --- src/controllers/commands/CommandController.cpp | 2 +- src/widgets/dialogs/UserInfoPopup.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index 80ec1636591..8174f5c043e 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -856,7 +856,7 @@ void CommandController::initialize(Settings &, Paths &paths) { channel->addMessage( makeSystemMessage("Usage: /usercard [channel] or " - "/usercard # [channel]")); + "/usercard id: [channel]")); return ""; } diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index aaf0e449cbb..4045ed33de2 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -701,7 +701,7 @@ void UserInfoPopup::setData(const QString &name, const ChannelPtr &contextChannel, const ChannelPtr &openingChannel) { - const QStringView idPrefix = u"#"; + const QStringView idPrefix = u"id:"; bool isId = name.startsWith(idPrefix); if (isId) {