mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Make "recent_messages" network request safe in case the channel is closed when the request finished
This commit is contained in:
parent
b5c7c8ff26
commit
1422201570
1 changed files with 8 additions and 9 deletions
|
@ -29,8 +29,7 @@
|
|||
|
||||
namespace chatterino {
|
||||
namespace {
|
||||
auto parseRecentMessages(const QJsonObject &jsonRoot,
|
||||
TwitchChannel &channel)
|
||||
auto parseRecentMessages(const QJsonObject &jsonRoot, ChannelPtr channel)
|
||||
{
|
||||
QJsonArray jsonMessages = jsonRoot.value("messages").toArray();
|
||||
std::vector<MessagePtr> messages;
|
||||
|
@ -46,7 +45,7 @@ namespace {
|
|||
assert(privMsg);
|
||||
|
||||
MessageParseArgs args;
|
||||
TwitchMessageBuilder builder(&channel, privMsg, args);
|
||||
TwitchMessageBuilder builder(channel.get(), privMsg, args);
|
||||
if (!builder.isIgnored()) {
|
||||
messages.push_back(builder.build());
|
||||
}
|
||||
|
@ -546,13 +545,13 @@ void TwitchChannel::loadRecentMessages()
|
|||
// can't be concurrent right now due to SignalVector
|
||||
// request.setExecuteConcurrently(true);
|
||||
|
||||
request.onSuccess([that = this](auto result) -> Outcome {
|
||||
auto messages = parseRecentMessages(result.parseJson(), *that);
|
||||
request.onSuccess([weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
||||
auto shared = weak.lock();
|
||||
if (!shared) return Failure;
|
||||
|
||||
// postToThread([that, weak = weakOf<Channel>(that),
|
||||
// messages = std::move(messages)]() mutable {
|
||||
that->addMessagesAtStart(messages);
|
||||
// });
|
||||
auto messages = parseRecentMessages(result.parseJson(), shared);
|
||||
|
||||
shared->addMessagesAtStart(messages);
|
||||
|
||||
return Success;
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue