Added autocompletion in /whispers for Twitch emotes, Global Bttv/Ffz emotes and emojis (#2999)

This commit is contained in:
Paweł 2021-07-17 14:35:27 +02:00 committed by GitHub
parent 461443dbe5
commit 74c5cca890
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 93 additions and 88 deletions

View file

@ -2,6 +2,7 @@
## Unversioned
- Minor: Added autocompletion in /whispers for Twitch emotes, Global Bttv/Ffz emotes and emojis. (#2999)
- Bugfix: Fixed "smiley" emotes being unable to be "Tabbed" with autocompletion, introduced in v2.3.3. (#3010)
- Dev: Ubuntu packages are now available (#2936)

View file

@ -73,124 +73,130 @@ int CompletionModel::rowCount(const QModelIndex &) const
void CompletionModel::refresh(const QString &prefix, bool isFirstWord)
{
std::function<void(const QString &, TaggedString::Type)> addString;
std::lock_guard<std::mutex> guard(this->itemsMutex_);
this->items_.clear();
if (prefix.length() < 2 || !this->channel_.isTwitchChannel())
{
return;
}
// Twitch channel
auto tc = dynamic_cast<TwitchChannel *>(&this->channel_);
std::function<void(const QString &str, TaggedString::Type type)> addString;
if (getSettings()->prefixOnlyEmoteCompletion)
{
addString = [&](const QString &str, TaggedString::Type type) {
addString = [=](const QString &str, TaggedString::Type type) {
if (str.startsWith(prefix, Qt::CaseInsensitive))
this->items_.emplace(str + " ", type);
};
}
else
{
addString = [&](const QString &str, TaggedString::Type type) {
addString = [=](const QString &str, TaggedString::Type type) {
if (str.contains(prefix, Qt::CaseInsensitive))
this->items_.emplace(str + " ", type);
};
}
std::lock_guard<std::mutex> guard(this->itemsMutex_);
this->items_.clear();
if (prefix.length() < 2)
return;
if (auto channel = dynamic_cast<TwitchChannel *>(&this->channel_))
if (auto account = getApp()->accounts->twitch.getCurrent())
{
if (auto account = getApp()->accounts->twitch.getCurrent())
// Twitch Emotes available globally
for (const auto &emote : account->accessEmotes()->emotes)
{
// Twitch Emotes available globally
for (const auto &emote : account->accessEmotes()->emotes)
{
addString(emote.first.string, TaggedString::TwitchGlobalEmote);
}
addString(emote.first.string, TaggedString::TwitchGlobalEmote);
}
// Twitch Emotes available locally
auto localEmoteData = account->accessLocalEmotes();
if (localEmoteData->find(channel->roomId()) !=
localEmoteData->end())
// Twitch Emotes available locally
auto localEmoteData = account->accessLocalEmotes();
if (tc && localEmoteData->find(tc->roomId()) != localEmoteData->end())
{
for (const auto &emote : localEmoteData->at(tc->roomId()))
{
for (const auto &emote : localEmoteData->at(channel->roomId()))
{
addString(emote.first.string,
TaggedString::Type::TwitchLocalEmote);
}
addString(emote.first.string,
TaggedString::Type::TwitchLocalEmote);
}
}
}
// Usernames
QString usernamePostfix =
isFirstWord && getSettings()->mentionUsersWithComma ? ","
: QString();
// Bttv Global
for (auto &emote : *getApp()->twitch2->getBttvEmotes().emotes())
{
addString(emote.first.string, TaggedString::Type::BTTVChannelEmote);
}
if (prefix.startsWith("@"))
// Ffz Global
for (auto &emote : *getApp()->twitch2->getFfzEmotes().emotes())
{
addString(emote.first.string, TaggedString::Type::FFZChannelEmote);
}
// Emojis
if (prefix.startsWith(":"))
{
const auto &emojiShortCodes = getApp()->emotes->emojis.shortCodes;
for (auto &m : emojiShortCodes)
{
QString usernamePrefix = prefix;
usernamePrefix.remove(0, 1);
auto chatters =
channel->accessChatters()->filterByPrefix(usernamePrefix);
for (const auto &name : chatters)
{
addString("@" + name + usernamePostfix,
TaggedString::Type::Username);
}
addString(QString(":%1:").arg(m), TaggedString::Type::Emoji);
}
else if (!getSettings()->userCompletionOnlyWithAt)
}
//
// Stuff below is available only in regular Twitch channels
if (!tc)
{
return;
}
// Usernames
QString usernamePostfix =
isFirstWord && getSettings()->mentionUsersWithComma ? "," : QString();
if (prefix.startsWith("@"))
{
QString usernamePrefix = prefix;
usernamePrefix.remove(0, 1);
auto chatters = tc->accessChatters()->filterByPrefix(usernamePrefix);
for (const auto &name : chatters)
{
auto chatters = channel->accessChatters()->filterByPrefix(prefix);
for (const auto &name : chatters)
{
addString(name + usernamePostfix, TaggedString::Type::Username);
}
addString("@" + name + usernamePostfix,
TaggedString::Type::Username);
}
}
else if (!getSettings()->userCompletionOnlyWithAt)
{
auto chatters = tc->accessChatters()->filterByPrefix(prefix);
// Bttv Global
for (auto &emote : *getApp()->twitch2->getBttvEmotes().emotes())
for (const auto &name : chatters)
{
addString(emote.first.string, TaggedString::Type::BTTVChannelEmote);
addString(name + usernamePostfix, TaggedString::Type::Username);
}
}
// Ffz Global
for (auto &emote : *getApp()->twitch2->getFfzEmotes().emotes())
{
addString(emote.first.string, TaggedString::Type::FFZChannelEmote);
}
// Bttv Channel
for (auto &emote : *tc->bttvEmotes())
{
addString(emote.first.string, TaggedString::Type::BTTVGlobalEmote);
}
// Bttv Channel
for (auto &emote : *channel->bttvEmotes())
{
addString(emote.first.string, TaggedString::Type::BTTVGlobalEmote);
}
// Ffz Channel
for (auto &emote : *tc->ffzEmotes())
{
addString(emote.first.string, TaggedString::Type::BTTVGlobalEmote);
}
// Ffz Channel
for (auto &emote : *channel->ffzEmotes())
{
addString(emote.first.string, TaggedString::Type::BTTVGlobalEmote);
}
// Commands
for (auto &command : getApp()->commands->items_)
{
addString(command.name, TaggedString::Command);
}
// Emojis
if (prefix.startsWith(":"))
{
const auto &emojiShortCodes = getApp()->emotes->emojis.shortCodes;
for (auto &m : emojiShortCodes)
{
addString(":" + m + ":", TaggedString::Type::Emoji);
}
}
// Commands
for (auto &command : getApp()->commands->items_)
{
addString(command.name, TaggedString::Command);
}
for (auto &command : getApp()->commands->getDefaultTwitchCommandList())
{
addString(command, TaggedString::Command);
}
for (auto &command : getApp()->commands->getDefaultTwitchCommandList())
{
addString(command, TaggedString::Command);
}
}

View file

@ -53,8 +53,6 @@ public:
static bool compareStrings(const QString &a, const QString &b);
private:
TaggedString createUser(const QString &str);
std::set<TaggedString> items_;
mutable std::mutex itemsMutex_;
Channel &channel_;