2017-07-09 17:58:59 +02:00
|
|
|
#include "completionmanager.hpp"
|
2017-12-17 17:49:32 +01:00
|
|
|
#include "channelmanager.hpp"
|
2017-07-23 14:16:13 +02:00
|
|
|
#include "common.hpp"
|
2017-12-17 03:06:39 +01:00
|
|
|
#include "debug/log.hpp"
|
2017-07-23 14:16:13 +02:00
|
|
|
#include "emotemanager.hpp"
|
2017-07-09 17:58:59 +02:00
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2017-12-17 17:49:32 +01:00
|
|
|
CompletionModel::CompletionModel(const QString &_channelName)
|
2017-12-17 03:06:39 +01:00
|
|
|
: channelName(_channelName)
|
2017-08-01 00:10:02 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-12-17 03:06:39 +01:00
|
|
|
void CompletionModel::refresh()
|
2017-07-09 17:58:59 +02:00
|
|
|
{
|
2017-12-17 03:06:39 +01:00
|
|
|
// debug::Log("[CompletionModel:{}] Refreshing...]", this->channelName);
|
2017-07-23 14:16:13 +02:00
|
|
|
|
2017-12-17 02:18:13 +01:00
|
|
|
auto &emoteManager = EmoteManager::getInstance();
|
2017-12-17 03:06:39 +01:00
|
|
|
this->emotes.clear();
|
2017-12-17 02:18:13 +01:00
|
|
|
|
2017-12-17 03:06:39 +01:00
|
|
|
// User-specific: Twitch Emotes
|
|
|
|
// TODO: Fix this so it properly updates with the proper api. oauth token needs proper scope
|
2017-12-17 02:18:13 +01:00
|
|
|
for (const auto &m : emoteManager.twitchAccountEmotes) {
|
2017-07-23 14:16:13 +02:00
|
|
|
for (const auto &emoteName : m.second.emoteCodes) {
|
2017-12-17 03:06:39 +01:00
|
|
|
this->addString(emoteName);
|
2017-07-23 14:16:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-17 03:06:39 +01:00
|
|
|
// Global: BTTV Global Emotes
|
2017-12-17 02:18:13 +01:00
|
|
|
std::vector<std::string> &bttvGlobalEmoteCodes = emoteManager.bttvGlobalEmoteCodes;
|
2017-07-23 14:16:13 +02:00
|
|
|
for (const auto &m : bttvGlobalEmoteCodes) {
|
2017-12-17 03:06:39 +01:00
|
|
|
this->addString(m);
|
2017-07-23 14:16:13 +02:00
|
|
|
}
|
|
|
|
|
2017-12-17 03:06:39 +01:00
|
|
|
// Global: FFZ Global Emotes
|
2017-12-17 02:18:13 +01:00
|
|
|
std::vector<std::string> &ffzGlobalEmoteCodes = emoteManager.ffzGlobalEmoteCodes;
|
2017-07-23 14:16:13 +02:00
|
|
|
for (const auto &m : ffzGlobalEmoteCodes) {
|
2017-12-17 03:06:39 +01:00
|
|
|
this->addString(m);
|
2017-07-23 14:16:13 +02:00
|
|
|
}
|
|
|
|
|
2017-12-17 03:06:39 +01:00
|
|
|
// Channel-specific: BTTV Channel Emotes
|
2017-07-23 14:16:13 +02:00
|
|
|
std::vector<std::string> &bttvChannelEmoteCodes =
|
2017-12-17 17:49:32 +01:00
|
|
|
emoteManager.bttvChannelEmoteCodes[this->channelName.toStdString()];
|
2017-07-23 14:16:13 +02:00
|
|
|
for (const auto &m : bttvChannelEmoteCodes) {
|
2017-12-17 03:06:39 +01:00
|
|
|
this->addString(m);
|
2017-07-23 14:16:13 +02:00
|
|
|
}
|
|
|
|
|
2017-12-17 03:06:39 +01:00
|
|
|
// Channel-specific: FFZ Channel Emotes
|
|
|
|
std::vector<std::string> &ffzChannelEmoteCodes =
|
2017-12-17 17:49:32 +01:00
|
|
|
emoteManager.ffzChannelEmoteCodes[this->channelName.toStdString()];
|
2017-07-23 14:16:13 +02:00
|
|
|
for (const auto &m : ffzChannelEmoteCodes) {
|
2017-12-17 03:06:39 +01:00
|
|
|
this->addString(m);
|
2017-08-01 00:10:02 +02:00
|
|
|
}
|
|
|
|
|
2017-12-17 03:06:39 +01:00
|
|
|
// Global: Emojis
|
2017-12-17 02:18:13 +01:00
|
|
|
const auto &emojiShortCodes = emoteManager.emojiShortCodes;
|
2017-08-01 00:10:02 +02:00
|
|
|
for (const auto &m : emojiShortCodes) {
|
2017-12-17 03:06:39 +01:00
|
|
|
this->addString(":" + m + ":");
|
2017-07-23 14:16:13 +02:00
|
|
|
}
|
2017-12-17 03:06:39 +01:00
|
|
|
|
2017-12-17 17:49:32 +01:00
|
|
|
// Channel-specific: Usernames
|
|
|
|
auto *channelManager = ChannelManager::instance;
|
|
|
|
auto c = channelManager->getTwitchChannel(this->channelName);
|
|
|
|
if (!c) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto usernames = c->getUsernamesForCompletions();
|
|
|
|
for (const auto &username : usernames) {
|
|
|
|
this->addString(username);
|
|
|
|
this->addString('@' + username);
|
|
|
|
}
|
2017-12-17 03:06:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompletionModel::addString(const std::string &str)
|
|
|
|
{
|
|
|
|
// Always add a space at the end of completions
|
|
|
|
this->emotes.push_back(qS(str) + " ");
|
|
|
|
}
|
|
|
|
|
2017-12-17 17:49:32 +01:00
|
|
|
void CompletionModel::addString(const QString &str)
|
|
|
|
{
|
|
|
|
// Always add a space at the end of completions
|
|
|
|
this->emotes.push_back(str + " ");
|
|
|
|
}
|
|
|
|
|
2017-12-17 03:06:39 +01:00
|
|
|
CompletionModel *CompletionManager::createModel(const std::string &channelName)
|
|
|
|
{
|
|
|
|
auto it = this->models.find(channelName);
|
|
|
|
if (it != this->models.end()) {
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2017-12-17 17:49:32 +01:00
|
|
|
CompletionModel *ret = new CompletionModel(qS(channelName));
|
2017-12-17 03:06:39 +01:00
|
|
|
this->models[channelName] = ret;
|
|
|
|
|
|
|
|
return ret;
|
2017-07-09 17:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|