Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash that could occur if closing the usercard quickly after blocking #4711

Merged
merged 4 commits into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Bugfix: Fix visual glitches with smooth scrolling. (#4501)
- Bugfix: Fixed pings firing for the "Your username" highlight when not signed in. (#4698)
- Bugfix: Fixed partially broken filters on Qt 6 builds. (#4702)
- Bugfix: Fixed crash that could occurr when closing the usercard too quickly after blocking or unblocking a user. (#4711)
- Dev: Added command to set Qt's logging filter/rules at runtime (`/c2-set-logging-rules`). (#4637)
- Dev: Added the ability to see & load custom themes from the Themes directory. No stable promises are made of this feature, changes might be made that breaks custom themes without notice. (#4570)
- Dev: Added test cases for emote and tab completion. (#4644)
Expand All @@ -30,6 +31,7 @@
- Dev: Added `sccache` in Windows CI. (#4678)
- Dev: Moved preprocessor Git and date definitions to executables only. (#4681)
- Dev: Refactored tests to be able to use `ctest` and run in debug builds. (#4700)
- Dev: Added the ability to use an alternate linker using the `-DUSE_ALTERNATE_LINKER=...` CMake parameter. (#4711)

## 2.4.4

Expand Down
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ elseif (CCACHE_PROGRAM)
set(_compiler_launcher ${CCACHE_PROGRAM})
endif ()


# Alternate linker code taken from heavyai/heavydb
# https://github.com/heavyai/heavydb/blob/0517d99b467806f6af7b4c969e351368a667497d/CMakeLists.txt#L87-L103
macro(set_alternate_linker linker)
find_program(LINKER_EXECUTABLE ld.${USE_ALTERNATE_LINKER} ${USE_ALTERNATE_LINKER})
if(LINKER_EXECUTABLE)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 12.0.0)
add_link_options("-ld-path=${USE_ALTERNATE_LINKER}")
else()
add_link_options("-fuse-ld=${USE_ALTERNATE_LINKER}")
endif()
else()
set(USE_ALTERNATE_LINKER "" CACHE STRING "Use alternate linker" FORCE)
endif()
endmacro()

set(USE_ALTERNATE_LINKER "" CACHE STRING "Use alternate linker. Leave empty for system default; alternatives are 'gold', 'lld', 'bfd', 'mold'")
if(NOT "${USE_ALTERNATE_LINKER}" STREQUAL "")
set_alternate_linker(${USE_ALTERNATE_LINKER})
endif()

if (_compiler_launcher)
set(CMAKE_CXX_COMPILER_LAUNCHER "${_compiler_launcher}" CACHE STRING "CXX compiler launcher")
message(STATUS "Using ${_compiler_launcher} for speeding up build")
Expand Down
6 changes: 4 additions & 2 deletions mocks/include/mocks/Helix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ class Helix : public IHelix
(override));

MOCK_METHOD(void, blockUser,
(QString targetUserId, std::function<void()> successCallback,
(QString targetUserId, const QObject *caller,
std::function<void()> successCallback,
HelixFailureCallback failureCallback),
(override));

MOCK_METHOD(void, unblockUser,
(QString targetUserId, std::function<void()> successCallback,
(QString targetUserId, const QObject *caller,
std::function<void()> successCallback,
HelixFailureCallback failureCallback),
(override));

Expand Down
4 changes: 2 additions & 2 deletions src/controllers/commands/CommandController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ void CommandController::initialize(Settings &, Paths &paths)
target,
[currentUser, channel, target](const HelixUser &targetUser) {
getApp()->accounts->twitch.getCurrent()->blockUser(
targetUser.id,
targetUser.id, nullptr,
[channel, target, targetUser] {
channel->addMessage(makeSystemMessage(
QString("You successfully blocked user %1")
Expand Down Expand Up @@ -703,7 +703,7 @@ void CommandController::initialize(Settings &, Paths &paths)
target,
[currentUser, channel, target](const auto &targetUser) {
getApp()->accounts->twitch.getCurrent()->unblockUser(
targetUser.id,
targetUser.id, nullptr,
[channel, target, targetUser] {
channel->addMessage(makeSystemMessage(
QString("You successfully unblocked user %1")
Expand Down
10 changes: 6 additions & 4 deletions src/providers/twitch/TwitchAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,12 @@ void TwitchAccount::loadBlocks()
});
}

void TwitchAccount::blockUser(QString userId, std::function<void()> onSuccess,
void TwitchAccount::blockUser(QString userId, const QObject *caller,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: the parameter 'userId' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

Suggested change
void TwitchAccount::blockUser(QString userId, const QObject *caller,
void TwitchAccount::blockUser(const QString& userId, const QObject *caller,

src/providers/twitch/TwitchAccount.hpp:74:

-     void blockUser(QString userId, const QObject *caller,
+     void blockUser(const QString& userId, const QObject *caller,

std::function<void()> onSuccess,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: the parameter 'onSuccess' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

Suggested change
std::function<void()> onSuccess,
const std::function<void()>& onSuccess,

src/providers/twitch/TwitchAccount.hpp:75:

-                    std::function<void()> onSuccess,
+                    const std::function<void()>& onSuccess,

std::function<void()> onFailure)
{
getHelix()->blockUser(
userId,
userId, caller,
[this, userId, onSuccess] {
TwitchUser blockedUser;
blockedUser.id = userId;
Expand All @@ -141,11 +142,12 @@ void TwitchAccount::blockUser(QString userId, std::function<void()> onSuccess,
std::move(onFailure));
}

void TwitchAccount::unblockUser(QString userId, std::function<void()> onSuccess,
void TwitchAccount::unblockUser(QString userId, const QObject *caller,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: the parameter 'userId' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

Suggested change
void TwitchAccount::unblockUser(QString userId, const QObject *caller,
void TwitchAccount::unblockUser(const QString& userId, const QObject *caller,

src/providers/twitch/TwitchAccount.hpp:77:

-     void unblockUser(QString userId, const QObject *caller,
+     void unblockUser(const QString& userId, const QObject *caller,

std::function<void()> onSuccess,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: the parameter 'onSuccess' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

Suggested change
std::function<void()> onSuccess,
const std::function<void()>& onSuccess,

src/providers/twitch/TwitchAccount.hpp:78:

-                      std::function<void()> onSuccess,
+                      const std::function<void()>& onSuccess,

std::function<void()> onFailure)
{
getHelix()->unblockUser(
userId,
userId, caller,
[this, userId, onSuccess] {
TwitchUser ignoredUser;
ignoredUser.id = userId;
Expand Down
7 changes: 5 additions & 2 deletions src/providers/twitch/TwitchAccount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <QColor>
#include <QElapsedTimer>
#include <QObject>
#include <QString>
#include <rapidjson/document.h>

Expand Down Expand Up @@ -71,9 +72,11 @@ class TwitchAccount : public Account
bool isAnon() const;

void loadBlocks();
void blockUser(QString userId, std::function<void()> onSuccess,
void blockUser(QString userId, const QObject *caller,
std::function<void()> onSuccess,
std::function<void()> onFailure);
void unblockUser(QString userId, std::function<void()> onSuccess,
void unblockUser(QString userId, const QObject *caller,
std::function<void()> onSuccess,
std::function<void()> onFailure);

SharedAccessGuard<const std::set<QString>> accessBlockedUserIds() const;
Expand Down
6 changes: 4 additions & 2 deletions src/providers/twitch/api/Helix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,14 +541,15 @@ void Helix::loadBlocks(QString userId,
.execute();
}

void Helix::blockUser(QString targetUserId,
void Helix::blockUser(QString targetUserId, const QObject *caller,
std::function<void()> successCallback,
HelixFailureCallback failureCallback)
{
QUrlQuery urlQuery;
urlQuery.addQueryItem("target_user_id", targetUserId);

this->makePut("users/blocks", urlQuery)
.caller(caller)
.onSuccess([successCallback](auto /*result*/) -> Outcome {
successCallback();
return Success;
Expand All @@ -560,14 +561,15 @@ void Helix::blockUser(QString targetUserId,
.execute();
}

void Helix::unblockUser(QString targetUserId,
void Helix::unblockUser(QString targetUserId, const QObject *caller,
std::function<void()> successCallback,
HelixFailureCallback failureCallback)
{
QUrlQuery urlQuery;
urlQuery.addQueryItem("target_user_id", targetUserId);

this->makeDelete("users/blocks", urlQuery)
.caller(caller)
.onSuccess([successCallback](auto /*result*/) -> Outcome {
successCallback();
return Success;
Expand Down
9 changes: 5 additions & 4 deletions src/providers/twitch/api/Helix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,12 +805,12 @@ class IHelix
HelixFailureCallback failureCallback) = 0;

// https://dev.twitch.tv/docs/api/reference#block-user
virtual void blockUser(QString targetUserId,
virtual void blockUser(QString targetUserId, const QObject *caller,
std::function<void()> successCallback,
HelixFailureCallback failureCallback) = 0;

// https://dev.twitch.tv/docs/api/reference#unblock-user
virtual void unblockUser(QString targetUserId,
virtual void unblockUser(QString targetUserId, const QObject *caller,
std::function<void()> successCallback,
HelixFailureCallback failureCallback) = 0;

Expand Down Expand Up @@ -1118,11 +1118,12 @@ class Helix final : public IHelix
HelixFailureCallback failureCallback) final;

// https://dev.twitch.tv/docs/api/reference#block-user
void blockUser(QString targetUserId, std::function<void()> successCallback,
void blockUser(QString targetUserId, const QObject *caller,
std::function<void()> successCallback,
HelixFailureCallback failureCallback) final;

// https://dev.twitch.tv/docs/api/reference#unblock-user
void unblockUser(QString targetUserId,
void unblockUser(QString targetUserId, const QObject *caller,
std::function<void()> successCallback,
HelixFailureCallback failureCallback) final;

Expand Down
5 changes: 3 additions & 2 deletions src/widgets/dialogs/UserInfoPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <QDesktopServices>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QPointer>

const QString TEXT_FOLLOWERS("Followers: %1");
const QString TEXT_CREATED("Created: %1");
Expand Down Expand Up @@ -593,7 +594,7 @@ void UserInfoPopup::installEvents()
this->ui_.block->setEnabled(false);

getApp()->accounts->twitch.getCurrent()->unblockUser(
this->userId_,
this->userId_, this,
[this, reenableBlockCheckbox, currentUser] {
this->channel_->addMessage(makeSystemMessage(
QString("You successfully unblocked user %1")
Expand All @@ -620,7 +621,7 @@ void UserInfoPopup::installEvents()
this->ui_.block->setEnabled(false);

getApp()->accounts->twitch.getCurrent()->blockUser(
this->userId_,
this->userId_, this,
[this, reenableBlockCheckbox, currentUser] {
this->channel_->addMessage(makeSystemMessage(
QString("You successfully blocked user %1")
Expand Down