some concurrency additions (#2698)

This commit is contained in:
fourtf
2021-05-01 13:38:58 +02:00
committed by GitHub
parent 345bcdb963
commit 8b3f301c50
10 changed files with 84 additions and 54 deletions
+20 -10
View File
@@ -101,14 +101,17 @@ void TwitchAccount::loadBlocks()
getHelix()->loadBlocks(
getApp()->accounts->twitch.getCurrent()->userId_,
[this](std::vector<HelixBlock> blocks) {
std::lock_guard<std::mutex> lock(this->ignoresMutex_);
this->ignores_.clear();
auto ignores = this->ignores_.access();
auto userIds = this->ignoresUserIds_.access();
ignores->clear();
userIds->clear();
for (const HelixBlock &block : blocks)
{
TwitchUser blockedUser;
blockedUser.fromHelixBlock(block);
this->ignores_.insert(blockedUser);
ignores->insert(blockedUser);
userIds->insert(blockedUser.id);
}
},
[] {
@@ -125,9 +128,11 @@ void TwitchAccount::blockUser(QString userId, std::function<void()> onSuccess,
TwitchUser blockedUser;
blockedUser.id = userId;
{
std::lock_guard<std::mutex> lock(this->ignoresMutex_);
auto ignores = this->ignores_.access();
auto userIds = this->ignoresUserIds_.access();
this->ignores_.insert(blockedUser);
ignores->insert(blockedUser);
userIds->insert(blockedUser.id);
}
onSuccess();
},
@@ -143,9 +148,11 @@ void TwitchAccount::unblockUser(QString userId, std::function<void()> onSuccess,
TwitchUser ignoredUser;
ignoredUser.id = userId;
{
std::lock_guard<std::mutex> lock(this->ignoresMutex_);
auto ignores = this->ignores_.access();
auto userIds = this->ignoresUserIds_.access();
this->ignores_.erase(ignoredUser);
ignores->erase(ignoredUser);
userIds->erase(ignoredUser.id);
}
onSuccess();
},
@@ -169,11 +176,14 @@ void TwitchAccount::checkFollow(const QString targetUserID,
[] {});
}
std::set<TwitchUser> TwitchAccount::getBlocks() const
AccessGuard<const std::set<TwitchUser>> TwitchAccount::accessBlocks() const
{
std::lock_guard<std::mutex> lock(this->ignoresMutex_);
return this->ignores_.accessConst();
}
return this->ignores_;
AccessGuard<const std::set<QString>> TwitchAccount::accessBlockedUserIds() const
{
return this->ignoresUserIds_.accessConst();
}
void TwitchAccount::loadEmotes()
+4 -2
View File
@@ -106,7 +106,8 @@ public:
void checkFollow(const QString targetUserID,
std::function<void(FollowResult)> onFinished);
std::set<TwitchUser> getBlocks() const;
AccessGuard<const std::set<QString>> accessBlockedUserIds() const;
AccessGuard<const std::set<TwitchUser>> accessBlocks() const;
void loadEmotes();
void loadUserstateEmotes(QStringList emoteSetKeys);
@@ -128,7 +129,8 @@ private:
mutable std::mutex ignoresMutex_;
QElapsedTimer userstateEmotesTimer_;
std::set<TwitchUser> ignores_;
UniqueAccess<std::set<TwitchUser>> ignores_;
UniqueAccess<std::set<QString>> ignoresUserIds_;
// std::map<UserId, TwitchAccountEmoteData> emotes;
UniqueAccess<TwitchAccountEmoteData> emotes_;
+1
View File
@@ -720,6 +720,7 @@ void TwitchChannel::loadRecentMessages()
.arg(getSettings()->twitchMessageHistoryLimit);
NetworkRequest(url)
.concurrent()
.onSuccess([weak = weakOf<Channel>(this)](auto result) -> Outcome {
auto shared = weak.lock();
if (!shared)
+20 -20
View File
@@ -143,28 +143,28 @@ bool TwitchMessageBuilder::isIgnored() const
{
auto sourceUserID = this->tags.value("user-id").toString();
for (const auto &user : app->accounts->twitch.getCurrent()->getBlocks())
{
if (sourceUserID == user.id)
{
switch (static_cast<ShowIgnoredUsersMessages>(
getSettings()->showBlockedUsersMessages.getValue()))
{
case ShowIgnoredUsersMessages::IfModerator:
if (this->channel->isMod() ||
this->channel->isBroadcaster())
return false;
break;
case ShowIgnoredUsersMessages::IfBroadcaster:
if (this->channel->isBroadcaster())
return false;
break;
case ShowIgnoredUsersMessages::Never:
break;
}
auto blocks =
app->accounts->twitch.getCurrent()->accessBlockedUserIds();
return true;
if (auto it = blocks->find(sourceUserID); it != blocks->end())
{
switch (static_cast<ShowIgnoredUsersMessages>(
getSettings()->showBlockedUsersMessages.getValue()))
{
case ShowIgnoredUsersMessages::IfModerator:
if (this->channel->isMod() ||
this->channel->isBroadcaster())
return false;
break;
case ShowIgnoredUsersMessages::IfBroadcaster:
if (this->channel->isBroadcaster())
return false;
break;
case ShowIgnoredUsersMessages::Never:
break;
}
return true;
}
}