Fixed messages getting loaded multiple times. (#170)
* Implemented loading recent messages. * Fixed messages getting loaded multiple times.
This commit is contained in:
@@ -22,6 +22,8 @@ TwitchChannel::TwitchChannel(IrcManager &ircManager, const QString &channelName,
|
||||
{
|
||||
debug::Log("[TwitchChannel:{}] Opened", this->name);
|
||||
|
||||
this->dontAddMessages = true;
|
||||
|
||||
if (!this->isSpecial) {
|
||||
this->reloadChannelEmotes();
|
||||
}
|
||||
@@ -35,6 +37,10 @@ TwitchChannel::TwitchChannel(IrcManager &ircManager, const QString &channelName,
|
||||
this->roomIDchanged.connect([this]() {
|
||||
this->refreshLiveStatus(); //
|
||||
});
|
||||
|
||||
this->fetchMessages.connect([this] {
|
||||
this->fetchRecentMessages();
|
||||
});
|
||||
}
|
||||
|
||||
TwitchChannel::~TwitchChannel()
|
||||
@@ -57,6 +63,7 @@ void TwitchChannel::setRoomID(const QString &_roomID)
|
||||
{
|
||||
this->roomID = _roomID;
|
||||
this->roomIDchanged();
|
||||
this->fetchMessages.invoke();
|
||||
}
|
||||
|
||||
void TwitchChannel::reloadChannelEmotes()
|
||||
@@ -121,5 +128,24 @@ void TwitchChannel::refreshLiveStatus()
|
||||
});
|
||||
}
|
||||
|
||||
void TwitchChannel::fetchRecentMessages()
|
||||
{
|
||||
static QString genericURL =
|
||||
"https://tmi.twitch.tv/api/rooms/%1/recent_messages?client_id=" + getDefaultClientID();
|
||||
static auto readConnection = this->ircManager.getReadConnection();
|
||||
|
||||
util::twitch::get(genericURL.arg(roomID), QThread::currentThread(), [=](QJsonObject obj) {
|
||||
this->dontAddMessages = false;
|
||||
auto msgArray = obj.value("messages").toArray();
|
||||
if (msgArray.size())
|
||||
for (int i = 0; i < msgArray.size(); i++) {
|
||||
QByteArray content = msgArray[i].toString().toUtf8();
|
||||
auto msg = Communi::IrcMessage::fromData(content, readConnection);
|
||||
auto privMsg = static_cast<Communi::IrcPrivateMessage *>(msg);
|
||||
this->ircManager.privateMessageReceived(privMsg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace twitch
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -33,6 +33,8 @@ public:
|
||||
boost::signals2::signal<void()> roomIDchanged;
|
||||
boost::signals2::signal<void()> onlineStatusChanged;
|
||||
|
||||
pajlada::Signals::NoArgBoltSignal fetchMessages;
|
||||
|
||||
QString roomID;
|
||||
bool isLive;
|
||||
QString streamViewerCount;
|
||||
@@ -44,6 +46,8 @@ private:
|
||||
void setLive(bool newLiveStatus);
|
||||
void refreshLiveStatus();
|
||||
|
||||
void fetchRecentMessages();
|
||||
|
||||
IrcManager &ircManager;
|
||||
|
||||
bool isSpecial;
|
||||
|
||||
Reference in New Issue
Block a user