2017-07-09 17:58:59 +02:00
|
|
|
#include "completionmanager.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 03:06:39 +01:00
|
|
|
CompletionModel::CompletionModel(const std::string &_channelName)
|
|
|
|
: 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 03:06:39 +01:00
|
|
|
emoteManager.bttvChannelEmoteCodes[this->channelName];
|
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 =
|
|
|
|
emoteManager.ffzChannelEmoteCodes[this->channelName];
|
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
|
|
|
|
|
|
|
// TODO: Add Channel-specific: Usernames
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompletionModel::addString(const std::string &str)
|
|
|
|
{
|
|
|
|
// Always add a space at the end of completions
|
|
|
|
this->emotes.push_back(qS(str) + " ");
|
|
|
|
}
|
|
|
|
|
|
|
|
CompletionModel *CompletionManager::createModel(const std::string &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;
|
2017-07-09 17:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|