mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Remove "CompletionManager". Completion models are now stored in Channel
Chatters list is now updated every 5 minutes
This commit is contained in:
parent
ad12a818b2
commit
d9bd39e8a4
|
@ -114,7 +114,6 @@ SOURCES += \
|
|||
src/singletons/accountmanager.cpp \
|
||||
src/singletons/channelmanager.cpp \
|
||||
src/singletons/commandmanager.cpp \
|
||||
src/singletons/completionmanager.cpp \
|
||||
src/singletons/emotemanager.cpp \
|
||||
src/singletons/fontmanager.cpp \
|
||||
src/singletons/helper/completionmodel.cpp \
|
||||
|
@ -208,7 +207,6 @@ HEADERS += \
|
|||
src/singletons/accountmanager.hpp \
|
||||
src/singletons/channelmanager.hpp \
|
||||
src/singletons/commandmanager.hpp \
|
||||
src/singletons/completionmanager.hpp \
|
||||
src/singletons/emotemanager.hpp \
|
||||
src/singletons/fontmanager.hpp \
|
||||
src/singletons/helper/chatterinosetting.hpp \
|
||||
|
|
|
@ -20,6 +20,7 @@ namespace chatterino {
|
|||
|
||||
Channel::Channel(const QString &_name)
|
||||
: name(_name)
|
||||
, completionModel(this->name)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "messages/image.hpp"
|
||||
#include "messages/limitedqueue.hpp"
|
||||
#include "messages/message.hpp"
|
||||
#include "singletons/helper/completionmodel.hpp"
|
||||
#include "util/concurrentmap.hpp"
|
||||
|
||||
#include <QMap>
|
||||
|
@ -64,6 +65,8 @@ public:
|
|||
|
||||
static std::shared_ptr<Channel> getEmpty();
|
||||
|
||||
singletons::CompletionModel completionModel;
|
||||
|
||||
protected:
|
||||
virtual void onConnected();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
#include "singletons/completionmanager.hpp"
|
||||
#include "common.hpp"
|
||||
#include "debug/log.hpp"
|
||||
#include "singletons/channelmanager.hpp"
|
||||
#include "singletons/emotemanager.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
namespace singletons {
|
||||
|
||||
CompletionManager &CompletionManager::getInstance()
|
||||
{
|
||||
static CompletionManager instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
CompletionModel *CompletionManager::createModel(const QString &channelName)
|
||||
{
|
||||
auto it = this->models.find(channelName);
|
||||
if (it != this->models.end()) {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
CompletionModel *ret = new CompletionModel(channelName);
|
||||
this->models[channelName] = ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace singletons
|
||||
} // namespace chatterino
|
|
@ -1,26 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QVector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "helper/completionmodel.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
namespace singletons {
|
||||
class CompletionManager
|
||||
{
|
||||
CompletionManager() = default;
|
||||
|
||||
public:
|
||||
static CompletionManager &getInstance();
|
||||
|
||||
CompletionModel *createModel(const QString &channelName);
|
||||
|
||||
private:
|
||||
std::map<QString, CompletionModel *> models;
|
||||
};
|
||||
|
||||
} // namespace singletons
|
||||
} // namespace chatterino
|
|
@ -3,13 +3,13 @@
|
|||
#include "common.hpp"
|
||||
#include "debug/log.hpp"
|
||||
#include "singletons/channelmanager.hpp"
|
||||
#include "singletons/completionmanager.hpp"
|
||||
#include "singletons/emotemanager.hpp"
|
||||
|
||||
#include <QtAlgorithms>
|
||||
|
||||
namespace chatterino {
|
||||
namespace singletons {
|
||||
|
||||
CompletionModel::CompletionModel(const QString &_channelName)
|
||||
: channelName(_channelName)
|
||||
{
|
||||
|
@ -94,5 +94,6 @@ void CompletionModel::addUser(const QString &str)
|
|||
// Always add a space at the end of completions
|
||||
this->emotes.insert(this->createUser(str + " "));
|
||||
}
|
||||
|
||||
} // namespace singletons
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <set>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
#include <QAbstractListModel>
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
namespace chatterino {
|
||||
namespace singletons {
|
||||
|
||||
class CompletionModel : public QAbstractListModel
|
||||
{
|
||||
public:
|
||||
|
@ -50,17 +51,23 @@ private:
|
|||
if (this->isEmote) {
|
||||
if (that.isEmote) {
|
||||
int k = QString::compare(this->str, that.str, Qt::CaseInsensitive);
|
||||
if (k == 0) return this->str > that.str;
|
||||
else return k < 0;
|
||||
if (k == 0) {
|
||||
return this->str > that.str;
|
||||
} else {
|
||||
return k < 0;
|
||||
}
|
||||
} else
|
||||
return true;
|
||||
} else {
|
||||
if (that.isEmote)
|
||||
return false;
|
||||
else {
|
||||
int k = QString::compare(this->str, that.str, Qt::CaseInsensitive);;
|
||||
if (k == 0) return this->str > that.str;
|
||||
else return k < 0;
|
||||
int k = QString::compare(this->str, that.str, Qt::CaseInsensitive);
|
||||
if (k == 0) {
|
||||
return this->str > that.str;
|
||||
} else {
|
||||
return k < 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,5 +88,6 @@ private:
|
|||
|
||||
QString channelName;
|
||||
};
|
||||
|
||||
} // namespace singletons
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "widgets/helper/resizingtextedit.hpp"
|
||||
#include "common.hpp"
|
||||
#include "singletons/completionmanager.hpp"
|
||||
#include "singletons/helper/completionmodel.hpp"
|
||||
|
||||
ResizingTextEdit::ResizingTextEdit()
|
||||
{
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
#include "widgets/helper/splitinput.hpp"
|
||||
#include "singletons/commandmanager.hpp"
|
||||
#include "singletons/completionmanager.hpp"
|
||||
#include "singletons/ircmanager.hpp"
|
||||
#include "singletons/settingsmanager.hpp"
|
||||
#include "singletons/thememanager.hpp"
|
||||
#include "util/layoutcreator.hpp"
|
||||
#include "util/urlfetch.hpp"
|
||||
#include "widgets/notebook.hpp"
|
||||
#include "widgets/split.hpp"
|
||||
#include "widgets/splitcontainer.hpp"
|
||||
#include "util/urlfetch.hpp"
|
||||
|
||||
#include <QCompleter>
|
||||
#include <QPainter>
|
||||
|
@ -22,26 +21,14 @@ SplitInput::SplitInput(Split *_chatWidget)
|
|||
{
|
||||
this->initLayout();
|
||||
|
||||
// auto completion
|
||||
auto completer = new QCompleter(
|
||||
singletons::CompletionManager::getInstance().createModel(this->chatWidget->channelName));
|
||||
auto cc = singletons::CompletionManager::getInstance().createModel(this->chatWidget->channelName);
|
||||
cc->refresh();
|
||||
|
||||
|
||||
static QStringList jsonLabels = {"moderators", "staff", "admins", "global_mods", "viewers"};
|
||||
util::twitch::get("https://tmi.twitch.tv/group/user/" + this->chatWidget->channelName + "/chatters", this,
|
||||
[cc](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())
|
||||
cc->addUser(v.toString());
|
||||
}
|
||||
});
|
||||
|
||||
auto completer = new QCompleter(&this->chatWidget->getChannel()->completionModel);
|
||||
this->ui.textEdit->setCompleter(completer);
|
||||
|
||||
this->chatWidget->channelChanged.connect([this] {
|
||||
auto completer = new QCompleter(&this->chatWidget->getChannel()->completionModel);
|
||||
this->ui.textEdit->setCompleter(completer);
|
||||
});
|
||||
|
||||
// misc
|
||||
this->installKeyPressedEvent();
|
||||
this->themeRefreshEvent();
|
||||
|
|
Loading…
Reference in a new issue