Fixed messages getting loaded multiple times. (#170)

* Implemented loading recent messages.

* Fixed messages getting loaded multiple times.
This commit is contained in:
Cranken
2017-12-28 00:03:52 +01:00
committed by fourtf
parent 2cdc404eb4
commit cb75c2a725
6 changed files with 41 additions and 25 deletions
+4 -21
View File
@@ -204,7 +204,6 @@ void IrcManager::joinChannel(const QString &channelName)
this->readConnection->sendRaw("JOIN #" + channelName);
this->writeConnection->sendRaw("JOIN #" + channelName);
}
this->dontParse.append(channelName);
this->connectionMutex.unlock();
}
@@ -224,10 +223,9 @@ void IrcManager::partChannel(const QString &channelName)
void IrcManager::privateMessageReceived(Communi::IrcPrivateMessage *message)
{
this->onPrivateMessage.invoke(message);
QString channel = message->target().mid(1);
auto c = this->channelManager.getTwitchChannel(channel);
auto c = this->channelManager.getTwitchChannel(message->target().mid(1));
if (!c || this->dontParse.contains(channel)) {
if (!c) {
return;
}
@@ -288,7 +286,6 @@ void IrcManager::handleRoomStateMessage(Communi::IrcMessage *message)
channelManager.getTwitchChannel(channel)->setRoomID(roomID);
this->resources.loadChannelData(roomID);
this->fetchRecentMessages(roomID, channel);
}
}
@@ -523,23 +520,9 @@ void IrcManager::onDisconnected()
});
}
void IrcManager::fetchRecentMessages(QString &roomID, QString &channel)
Communi::IrcConnection *IrcManager::getReadConnection()
{
static QString genericURL =
"https://tmi.twitch.tv/api/rooms/%1/recent_messages?client_id=" + getDefaultClientID();
util::twitch::get(genericURL.arg(roomID), this, [=](QJsonObject obj) {
this->dontParse.removeAll(channel);
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, this->readConnection.get());
auto privMsg = static_cast<Communi::IrcPrivateMessage *>(msg);
privateMessageReceived(privMsg);
}
});
return this->readConnection.get();
}
} // namespace chatterino