mirror-chatterino2/src/singletons/helper/completionmodel.cpp

92 lines
3 KiB
C++
Raw Normal View History

2017-12-31 00:50:07 +01:00
#include "completionmodel.hpp"
#include "common.hpp"
#include "debug/log.hpp"
#include "singletons/channelmanager.hpp"
#include "singletons/completionmanager.hpp"
#include "singletons/emotemanager.hpp"
namespace chatterino {
2017-12-31 22:58:35 +01:00
namespace singletons {
2017-12-31 00:50:07 +01:00
CompletionModel::CompletionModel(const QString &_channelName)
: channelName(_channelName)
{
}
void CompletionModel::refresh()
{
// debug::Log("[CompletionModel:{}] Refreshing...]", this->channelName);
2017-12-31 22:58:35 +01:00
auto &emoteManager = singletons::EmoteManager::getInstance();
2017-12-31 00:50:07 +01:00
this->emotes.clear();
// User-specific: Twitch Emotes
// TODO: Fix this so it properly updates with the proper api. oauth token needs proper scope
for (const auto &m : emoteManager.twitchAccountEmotes) {
for (const auto &emoteName : m.second.emoteCodes) {
this->addString(emoteName);
}
}
// Global: BTTV Global Emotes
std::vector<std::string> &bttvGlobalEmoteCodes = emoteManager.bttvGlobalEmoteCodes;
for (const auto &m : bttvGlobalEmoteCodes) {
this->addString(m);
}
// Global: FFZ Global Emotes
std::vector<std::string> &ffzGlobalEmoteCodes = emoteManager.ffzGlobalEmoteCodes;
for (const auto &m : ffzGlobalEmoteCodes) {
this->addString(m);
}
// Channel-specific: BTTV Channel Emotes
std::vector<std::string> &bttvChannelEmoteCodes =
emoteManager.bttvChannelEmoteCodes[this->channelName.toStdString()];
for (const auto &m : bttvChannelEmoteCodes) {
this->addString(m);
}
// Channel-specific: FFZ Channel Emotes
std::vector<std::string> &ffzChannelEmoteCodes =
emoteManager.ffzChannelEmoteCodes[this->channelName.toStdString()];
for (const auto &m : ffzChannelEmoteCodes) {
this->addString(m);
}
// Global: Emojis
const auto &emojiShortCodes = emoteManager.emojiShortCodes;
for (const auto &m : emojiShortCodes) {
this->addString(":" + m + ":");
}
// Channel-specific: Usernames
2018-02-05 15:11:50 +01:00
// fourtf: only works with twitch chat
// auto c = singletons::ChannelManager::getInstance().getTwitchChannel(this->channelName);
// auto usernames = c->getUsernamesForCompletions();
// for (const auto &name : usernames) {
// assert(!name.displayName.isEmpty());
// this->addString(name.displayName);
// this->addString('@' + name.displayName);
2017-12-31 00:50:07 +01:00
2018-02-05 15:11:50 +01:00
// if (!name.localizedName.isEmpty()) {
// this->addString(name.localizedName);
// this->addString('@' + name.localizedName);
// }
// }
2017-12-31 00:50:07 +01:00
}
void CompletionModel::addString(const std::string &str)
{
// Always add a space at the end of completions
this->emotes.push_back(qS(str) + " ");
}
void CompletionModel::addString(const QString &str)
{
// Always add a space at the end of completions
this->emotes.push_back(str + " ");
}
2018-02-05 15:11:50 +01:00
} // namespace singletons
} // namespace chatterino