mirror-chatterino2/src/completionmanager.cpp

79 lines
2.2 KiB
C++
Raw Normal View History

#include "completionmanager.hpp"
#include "common.hpp"
#include "emotemanager.hpp"
namespace chatterino {
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)
{
CompletionModel *ret = new CompletionModel();
2017-12-17 02:18:13 +01:00
auto &emoteManager = EmoteManager::getInstance();
this->updateModel(ret, channelName);
2017-12-17 02:18:13 +01:00
emoteManager.bttvGlobalEmoteCodes.updated.connect([=]() {
this->updateModel(ret, channelName); //
});
2017-12-17 02:18:13 +01:00
emoteManager.ffzGlobalEmoteCodes.updated.connect([=]() {
this->updateModel(ret, channelName); //
});
2017-12-17 02:18:13 +01:00
emoteManager.bttvChannelEmoteCodes[channelName].updated.connect([=]() {
this->updateModel(ret, channelName); //
});
2017-12-17 02:18:13 +01:00
emoteManager.ffzChannelEmoteCodes[channelName].updated.connect([=]() {
this->updateModel(ret, channelName); //
});
return ret;
}
void CompletionManager::updateModel(CompletionModel *model, const std::string &channelName)
{
2017-12-17 02:18:13 +01:00
auto &emoteManager = EmoteManager::getInstance();
model->emotes.clear();
2017-12-17 02:18:13 +01:00
for (const auto &m : emoteManager.twitchAccountEmotes) {
for (const auto &emoteName : m.second.emoteCodes) {
model->addString(emoteName);
}
}
2017-12-17 02:18:13 +01:00
std::vector<std::string> &bttvGlobalEmoteCodes = emoteManager.bttvGlobalEmoteCodes;
for (const auto &m : bttvGlobalEmoteCodes) {
model->addString(m);
}
2017-12-17 02:18:13 +01:00
std::vector<std::string> &ffzGlobalEmoteCodes = emoteManager.ffzGlobalEmoteCodes;
for (const auto &m : ffzGlobalEmoteCodes) {
model->addString(m);
}
std::vector<std::string> &bttvChannelEmoteCodes =
2017-12-17 02:18:13 +01:00
emoteManager.bttvChannelEmoteCodes[channelName];
for (const auto &m : bttvChannelEmoteCodes) {
model->addString(m);
}
2017-12-17 02:18:13 +01:00
std::vector<std::string> &ffzChannelEmoteCodes = emoteManager.ffzChannelEmoteCodes[channelName];
for (const auto &m : ffzChannelEmoteCodes) {
model->addString(m);
}
2017-12-17 02:18:13 +01:00
const auto &emojiShortCodes = emoteManager.emojiShortCodes;
for (const auto &m : emojiShortCodes) {
model->addString(":" + m + ":");
}
}
} // namespace chatterino