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 ## 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) - Bugfix: Fixed "smiley" emotes being unable to be "Tabbed" with autocompletion, introduced in v2.3.3. (#3010)
- Dev: Ubuntu packages are now available (#2936) - Dev: Ubuntu packages are now available (#2936)

View file

@ -73,30 +73,33 @@ int CompletionModel::rowCount(const QModelIndex &) const
void CompletionModel::refresh(const QString &prefix, bool isFirstWord) 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) if (getSettings()->prefixOnlyEmoteCompletion)
{ {
addString = [&](const QString &str, TaggedString::Type type) { addString = [=](const QString &str, TaggedString::Type type) {
if (str.startsWith(prefix, Qt::CaseInsensitive)) if (str.startsWith(prefix, Qt::CaseInsensitive))
this->items_.emplace(str + " ", type); this->items_.emplace(str + " ", type);
}; };
} }
else else
{ {
addString = [&](const QString &str, TaggedString::Type type) { addString = [=](const QString &str, TaggedString::Type type) {
if (str.contains(prefix, Qt::CaseInsensitive)) if (str.contains(prefix, Qt::CaseInsensitive))
this->items_.emplace(str + " ", type); 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 // Twitch Emotes available globally
@ -107,10 +110,9 @@ void CompletionModel::refresh(const QString &prefix, bool isFirstWord)
// Twitch Emotes available locally // Twitch Emotes available locally
auto localEmoteData = account->accessLocalEmotes(); auto localEmoteData = account->accessLocalEmotes();
if (localEmoteData->find(channel->roomId()) != if (tc && localEmoteData->find(tc->roomId()) != localEmoteData->end())
localEmoteData->end())
{ {
for (const auto &emote : localEmoteData->at(channel->roomId())) for (const auto &emote : localEmoteData->at(tc->roomId()))
{ {
addString(emote.first.string, addString(emote.first.string,
TaggedString::Type::TwitchLocalEmote); TaggedString::Type::TwitchLocalEmote);
@ -118,35 +120,6 @@ void CompletionModel::refresh(const QString &prefix, bool isFirstWord)
} }
} }
// Usernames
QString usernamePostfix =
isFirstWord && getSettings()->mentionUsersWithComma ? ","
: QString();
if (prefix.startsWith("@"))
{
QString usernamePrefix = prefix;
usernamePrefix.remove(0, 1);
auto chatters =
channel->accessChatters()->filterByPrefix(usernamePrefix);
for (const auto &name : chatters)
{
addString("@" + name + usernamePostfix,
TaggedString::Type::Username);
}
}
else if (!getSettings()->userCompletionOnlyWithAt)
{
auto chatters = channel->accessChatters()->filterByPrefix(prefix);
for (const auto &name : chatters)
{
addString(name + usernamePostfix, TaggedString::Type::Username);
}
}
// Bttv Global // Bttv Global
for (auto &emote : *getApp()->twitch2->getBttvEmotes().emotes()) for (auto &emote : *getApp()->twitch2->getBttvEmotes().emotes())
{ {
@ -159,28 +132,62 @@ void CompletionModel::refresh(const QString &prefix, bool isFirstWord)
addString(emote.first.string, TaggedString::Type::FFZChannelEmote); addString(emote.first.string, TaggedString::Type::FFZChannelEmote);
} }
// Bttv Channel
for (auto &emote : *channel->bttvEmotes())
{
addString(emote.first.string, TaggedString::Type::BTTVGlobalEmote);
}
// Ffz Channel
for (auto &emote : *channel->ffzEmotes())
{
addString(emote.first.string, TaggedString::Type::BTTVGlobalEmote);
}
// Emojis // Emojis
if (prefix.startsWith(":")) if (prefix.startsWith(":"))
{ {
const auto &emojiShortCodes = getApp()->emotes->emojis.shortCodes; const auto &emojiShortCodes = getApp()->emotes->emojis.shortCodes;
for (auto &m : emojiShortCodes) for (auto &m : emojiShortCodes)
{ {
addString(":" + m + ":", TaggedString::Type::Emoji); addString(QString(":%1:").arg(m), TaggedString::Type::Emoji);
} }
} }
//
// 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)
{
addString("@" + name + usernamePostfix,
TaggedString::Type::Username);
}
}
else if (!getSettings()->userCompletionOnlyWithAt)
{
auto chatters = tc->accessChatters()->filterByPrefix(prefix);
for (const auto &name : chatters)
{
addString(name + usernamePostfix, TaggedString::Type::Username);
}
}
// Bttv Channel
for (auto &emote : *tc->bttvEmotes())
{
addString(emote.first.string, TaggedString::Type::BTTVGlobalEmote);
}
// Ffz Channel
for (auto &emote : *tc->ffzEmotes())
{
addString(emote.first.string, TaggedString::Type::BTTVGlobalEmote);
}
// Commands // Commands
for (auto &command : getApp()->commands->items_) for (auto &command : getApp()->commands->items_)
{ {
@ -192,7 +199,6 @@ void CompletionModel::refresh(const QString &prefix, bool isFirstWord)
addString(command, TaggedString::Command); addString(command, TaggedString::Command);
} }
} }
}
bool CompletionModel::compareStrings(const QString &a, const QString &b) bool CompletionModel::compareStrings(const QString &a, const QString &b)
{ {

View file

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