Remove "CompletionManager". Completion models are now stored in Channel
Chatters list is now updated every 5 minutes
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
namespace chatterino {
|
||||
namespace providers {
|
||||
namespace twitch {
|
||||
|
||||
TwitchChannel::TwitchChannel(const QString &channelName, Communi::IrcConnection *_readConnection)
|
||||
: Channel(channelName)
|
||||
, bttvChannelEmotes(new util::EmoteMap)
|
||||
@@ -47,6 +48,27 @@ TwitchChannel::TwitchChannel(const QString &channelName, Communi::IrcConnection
|
||||
|
||||
this->messageSuffix.append(' ');
|
||||
this->messageSuffix.append(QChar(0x206D));
|
||||
|
||||
static QStringList jsonLabels = {"moderators", "staff", "admins", "global_mods", "viewers"};
|
||||
auto refreshChatters = [=](QJsonObject obj) {
|
||||
QJsonObject chattersObj = obj.value("chatters").toObject();
|
||||
for (int i = 0; i < jsonLabels.size(); i++) {
|
||||
foreach (const QJsonValue &v, chattersObj.value(jsonLabels.at(i)).toArray()) {
|
||||
this->completionModel.addUser(v.toString());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
auto doRefreshChatters = [=]() {
|
||||
util::twitch::get("https://tmi.twitch.tv/group/user/" + this->name + "/chatters",
|
||||
QThread::currentThread(), refreshChatters);
|
||||
};
|
||||
|
||||
doRefreshChatters();
|
||||
|
||||
this->chattersListTimer = new QTimer;
|
||||
QObject::connect(this->chattersListTimer, &QTimer::timeout, doRefreshChatters);
|
||||
this->chattersListTimer->start(5 * 60 * 1000);
|
||||
}
|
||||
|
||||
TwitchChannel::~TwitchChannel()
|
||||
@@ -55,6 +77,9 @@ TwitchChannel::~TwitchChannel()
|
||||
|
||||
this->liveStatusTimer->stop();
|
||||
this->liveStatusTimer->deleteLater();
|
||||
|
||||
this->chattersListTimer->stop();
|
||||
this->chattersListTimer->deleteLater();
|
||||
}
|
||||
|
||||
bool TwitchChannel::isEmpty() const
|
||||
@@ -104,7 +129,7 @@ void TwitchChannel::sendMessage(const QString &message)
|
||||
parsedMessage.append(this->messageSuffix);
|
||||
|
||||
this->lastSentMessage = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->lastSentMessage = parsedMessage;
|
||||
|
||||
@@ -11,10 +11,13 @@
|
||||
namespace chatterino {
|
||||
namespace providers {
|
||||
namespace twitch {
|
||||
|
||||
class TwitchServer;
|
||||
|
||||
class TwitchChannel final : public Channel
|
||||
{
|
||||
QTimer *liveStatusTimer;
|
||||
QTimer *chattersListTimer;
|
||||
|
||||
public:
|
||||
~TwitchChannel();
|
||||
@@ -69,6 +72,7 @@ private:
|
||||
|
||||
friend class TwitchServer;
|
||||
};
|
||||
|
||||
} // namespace twitch
|
||||
} // namespace providers
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "providers/twitch/twitchmessagebuilder.hpp"
|
||||
#include "singletons/accountmanager.hpp"
|
||||
#include "util/posttothread.hpp"
|
||||
#include "singletons/completionmanager.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
@@ -84,8 +83,8 @@ void TwitchServer::privateMessageReceived(IrcPrivateMessage *message)
|
||||
|
||||
TwitchMessageBuilder builder(chan.get(), message, args);
|
||||
|
||||
auto cm = singletons::CompletionManager::getInstance().createModel(chan->name);
|
||||
cm->addUser(message->nick());
|
||||
// XXX: Thread-safety
|
||||
chan->completionModel.addUser(message->nick());
|
||||
|
||||
if (!builder.isIgnored()) {
|
||||
messages::MessagePtr _message = builder.build();
|
||||
|
||||
Reference in New Issue
Block a user