fix: request more historical messages on wake (#5018)
This commit is contained in:
@@ -103,10 +103,11 @@ TwitchChannel::TwitchChannel(const QString &name)
|
||||
// We can safely ignore this signal connection this has no external dependencies - once the signal
|
||||
// is destroyed, it will no longer be able to fire
|
||||
std::ignore = this->joined.connect([this]() {
|
||||
if (this->disconnectedAt_.has_value())
|
||||
if (this->disconnected_)
|
||||
{
|
||||
this->loadRecentMessagesReconnect();
|
||||
this->disconnectedAt_ = std::nullopt;
|
||||
this->lastConnectedAt_ = std::chrono::system_clock::now();
|
||||
this->disconnected_ = false;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -731,6 +732,8 @@ void TwitchChannel::setRoomId(const QString &id)
|
||||
*this->roomID_.access() = id;
|
||||
this->roomIdChanged();
|
||||
this->loadRecentMessages();
|
||||
this->disconnected_ = false;
|
||||
this->lastConnectedAt_ = std::chrono::system_clock::now();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1105,7 +1108,15 @@ bool TwitchChannel::setLive(bool newLiveStatus)
|
||||
return true;
|
||||
}
|
||||
|
||||
void TwitchChannel::markDisconnectedNow()
|
||||
void TwitchChannel::markConnected()
|
||||
{
|
||||
if (this->lastConnectedAt_.has_value() && !this->disconnected_)
|
||||
{
|
||||
this->lastConnectedAt_ = std::chrono::system_clock::now();
|
||||
}
|
||||
}
|
||||
|
||||
void TwitchChannel::markDisconnected()
|
||||
{
|
||||
if (this->roomId().isEmpty())
|
||||
{
|
||||
@@ -1113,14 +1124,7 @@ void TwitchChannel::markDisconnectedNow()
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->disconnectedAt_.has_value())
|
||||
{
|
||||
// don't overwrite prior timestamp since
|
||||
// a reconnection hasn't happened yet
|
||||
return;
|
||||
}
|
||||
|
||||
this->disconnectedAt_ = std::chrono::system_clock::now();
|
||||
this->disconnected_ = true;
|
||||
}
|
||||
|
||||
void TwitchChannel::loadRecentMessages()
|
||||
@@ -1194,14 +1198,14 @@ void TwitchChannel::loadRecentMessagesReconnect()
|
||||
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
int limit = getSettings()->twitchMessageHistoryLimit.getValue();
|
||||
if (this->disconnectedAt_.has_value())
|
||||
if (this->lastConnectedAt_.has_value())
|
||||
{
|
||||
// calculate how many messages could have occured
|
||||
// while we were not connected to the channel
|
||||
// assuming a maximum of 10 messages per second
|
||||
const auto secondsSinceDisconnect =
|
||||
std::chrono::duration_cast<std::chrono::seconds>(
|
||||
now - this->disconnectedAt_.value())
|
||||
now - this->lastConnectedAt_.value())
|
||||
.count();
|
||||
limit =
|
||||
std::min(static_cast<int>(secondsSinceDisconnect + 1) * 10, limit);
|
||||
@@ -1233,7 +1237,7 @@ void TwitchChannel::loadRecentMessagesReconnect()
|
||||
|
||||
tc->loadingRecentMessages_.clear();
|
||||
},
|
||||
limit, this->disconnectedAt_, now, true);
|
||||
limit, this->lastConnectedAt_, now, true);
|
||||
}
|
||||
|
||||
void TwitchChannel::refreshPubSub()
|
||||
|
||||
@@ -137,10 +137,14 @@ public:
|
||||
SharedAccessGuard<const StreamStatus> accessStreamStatus() const;
|
||||
|
||||
/**
|
||||
* Records the current timestamp the channel was disconnected.
|
||||
* This can be used to calculate the time spent disconnected after a successful reconnect
|
||||
* Records that the channel is no longer joined.
|
||||
*/
|
||||
void markDisconnectedNow();
|
||||
void markDisconnected();
|
||||
|
||||
/**
|
||||
* Records that the channel's read connection is healthy.
|
||||
*/
|
||||
void markConnected();
|
||||
|
||||
// Emotes
|
||||
std::optional<EmotePtr> bttvEmote(const EmoteName &name) const;
|
||||
@@ -364,8 +368,9 @@ private:
|
||||
int chatterCount_{};
|
||||
UniqueAccess<StreamStatus> streamStatus_;
|
||||
UniqueAccess<RoomModes> roomModes_;
|
||||
bool disconnected_{};
|
||||
std::optional<std::chrono::time_point<std::chrono::system_clock>>
|
||||
disconnectedAt_{};
|
||||
lastConnectedAt_{};
|
||||
std::atomic_flag loadingRecentMessages_ = ATOMIC_FLAG_INIT;
|
||||
std::unordered_map<QString, std::weak_ptr<MessageThread>> threads_;
|
||||
|
||||
|
||||
@@ -220,6 +220,7 @@ void TwitchIrcServer::readConnectionMessageReceived(
|
||||
{
|
||||
this->addGlobalSystemMessage(
|
||||
"Twitch Servers requested us to reconnect, reconnecting");
|
||||
this->markChannelsConnected();
|
||||
this->connect();
|
||||
}
|
||||
else if (command == "GLOBALUSERSTATE")
|
||||
|
||||
Reference in New Issue
Block a user