fixed and optimized the autocompletion

This commit is contained in:
fourtf 2018-08-13 13:54:39 +02:00
parent f1fbd7ee5c
commit f6e110b7fb
12 changed files with 362 additions and 164 deletions

View file

@ -250,7 +250,8 @@ SOURCES += \
src/widgets/helper/EffectLabel.cpp \ src/widgets/helper/EffectLabel.cpp \
src/widgets/helper/Button.cpp \ src/widgets/helper/Button.cpp \
src/messages/MessageContainer.cpp \ src/messages/MessageContainer.cpp \
src/debug/Benchmark.cpp src/debug/Benchmark.cpp \
src/common/UsernameSet.cpp
HEADERS += \ HEADERS += \
src/Application.hpp \ src/Application.hpp \
@ -445,7 +446,8 @@ HEADERS += \
src/widgets/helper/EffectLabel.hpp \ src/widgets/helper/EffectLabel.hpp \
src/util/LayoutHelper.hpp \ src/util/LayoutHelper.hpp \
src/widgets/helper/Button.hpp \ src/widgets/helper/Button.hpp \
src/messages/MessageContainer.hpp src/messages/MessageContainer.hpp \
src/common/UsernameSet.hpp
RESOURCES += \ RESOURCES += \
resources/resources.qrc \ resources/resources.qrc \

View file

@ -51,7 +51,6 @@ public:
void addOrReplaceTimeout(MessagePtr message); void addOrReplaceTimeout(MessagePtr message);
void disableAllMessages(); void disableAllMessages();
void replaceMessage(MessagePtr message, MessagePtr replacement); void replaceMessage(MessagePtr message, MessagePtr replacement);
virtual void addRecentChatter(const MessagePtr &message);
QStringList modList; QStringList modList;
@ -67,6 +66,7 @@ public:
protected: protected:
virtual void onConnected(); virtual void onConnected();
virtual void addRecentChatter(const MessagePtr &message);
private: private:
const QString name_; const QString name_;

View file

@ -2,8 +2,10 @@
#include "Application.hpp" #include "Application.hpp"
#include "common/Common.hpp" #include "common/Common.hpp"
#include "common/UsernameSet.hpp"
#include "controllers/accounts/AccountController.hpp" #include "controllers/accounts/AccountController.hpp"
#include "controllers/commands/CommandController.hpp" #include "controllers/commands/CommandController.hpp"
#include "debug/Benchmark.hpp"
#include "debug/Log.hpp" #include "debug/Log.hpp"
#include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchServer.hpp" #include "providers/twitch/TwitchServer.hpp"
@ -103,88 +105,81 @@ int CompletionModel::rowCount(const QModelIndex &) const
return this->emotes_.size(); return this->emotes_.size();
} }
void CompletionModel::refresh() void CompletionModel::refresh(const QString &prefix)
{ {
log("[CompletionModel:{}] Refreshing...]", this->channelName_); {
std::lock_guard<std::mutex> guard(this->emotesMutex_);
this->emotes_.clear();
}
auto app = getApp(); if (prefix.length() < 2) return;
// User-specific: Twitch Emotes BenchmarkGuard guard("CompletionModel::refresh");
if (auto account = app->accounts->twitch.getCurrent()) {
auto addString = [&](const QString &str, TaggedString::Type type) {
if (str.startsWith(prefix)) this->emotes_.emplace(str + " ", type);
};
auto _channel = getApp()->twitch2->getChannelOrEmpty(this->channelName_);
if (auto channel = dynamic_cast<TwitchChannel *>(_channel.get())) {
// account emotes
if (auto account = getApp()->accounts->twitch.getCurrent()) {
for (const auto &emote : account->accessEmotes()->allEmoteNames) { for (const auto &emote : account->accessEmotes()->allEmoteNames) {
// XXX: No way to discern between a twitch global emote and sub // XXX: No way to discern between a twitch global emote and sub
// emote right now // emote right now
this->addString(emote.string, addString(emote.string, TaggedString::Type::TwitchGlobalEmote);
TaggedString::Type::TwitchGlobalEmote);
} }
} }
// // Global: BTTV Global Emotes // Usernames
// std::vector<QString> &bttvGlobalEmoteCodes = if (prefix.length() >= UsernameSet::PrefixLength) {
// app->emotes->bttv.globalEmoteNames_; for (const auto &m : auto usernames = channel->accessChatters();
// bttvGlobalEmoteCodes) {
// this->addString(m, TaggedString::Type::BTTVGlobalEmote);
// }
// // Global: FFZ Global Emotes for (const auto &name : usernames->subrange(Prefix(prefix))) {
// std::vector<QString> &ffzGlobalEmoteCodes = addString(name, TaggedString::Type::Username);
// app->emotes->ffz.globalEmoteCodes; for (const auto &m : addString("@" + name, TaggedString::Type::Username);
// ffzGlobalEmoteCodes) {
// this->addString(m, TaggedString::Type::FFZGlobalEmote);
// }
// Channel emotes
if (auto channel = dynamic_cast<TwitchChannel *>(
getApp()
->twitch2->getChannelOrEmptyByID(this->channelName_)
.get())) {
auto bttv = channel->bttvEmotes();
// auto it = bttv->begin();
// for (const auto &emote : *bttv) {
// }
// std::vector<QString> &bttvChannelEmoteCodes =
// app->emotes->bttv.channelEmoteName_[this->channelName_];
// for (const auto &m : bttvChannelEmoteCodes) {
// this->addString(m, TaggedString::Type::BTTVChannelEmote);
// }
// Channel-specific: FFZ Channel Emotes
for (const auto &emote : *channel->ffzEmotes()) {
this->addString(emote.second->name.string,
TaggedString::Type::FFZChannelEmote);
} }
} }
// Bttv Global
for (auto &emote : *channel->globalBttv().emotes()) {
addString(emote.first.string, TaggedString::Type::BTTVChannelEmote);
}
// Ffz Global
for (auto &emote : *channel->globalFfz().emotes()) {
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
const auto &emojiShortCodes = app->emotes->emojis.shortCodes; if (prefix.startsWith(":")) {
for (const auto &m : emojiShortCodes) { const auto &emojiShortCodes = getApp()->emotes->emojis.shortCodes;
this->addString(":" + m + ":", TaggedString::Type::Emoji); for (auto &m : emojiShortCodes) {
addString(":" + m + ":", TaggedString::Type::Emoji);
}
} }
// Commands // Commands
for (auto &command : app->commands->items.getVector()) { for (auto &command : getApp()->commands->items.getVector()) {
this->addString(command.name, TaggedString::Command); addString(command.name, TaggedString::Command);
} }
for (auto &command : app->commands->getDefaultTwitchCommandList()) { for (auto &command :
this->addString(command, TaggedString::Command); getApp()->commands->getDefaultTwitchCommandList()) {
addString(command, TaggedString::Command);
}
} }
// Channel-specific: Usernames
// fourtf: only works with twitch chat
// auto c =
// 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);
// if (!name.localizedName.isEmpty()) {
// this->addString(name.localizedName);
// this->addString('@' + name.localizedName);
// }
// }
} }
void CompletionModel::addString(const QString &str, TaggedString::Type type) void CompletionModel::addString(const QString &str, TaggedString::Type type)
@ -200,8 +195,7 @@ void CompletionModel::addUser(const QString &username)
auto add = [this](const QString &str) { auto add = [this](const QString &str) {
auto ts = this->createUser(str + " "); auto ts = this->createUser(str + " ");
// Always add a space at the end of completions // Always add a space at the end of completions
std::pair<std::set<TaggedString>::iterator, bool> p = auto p = this->emotes_.insert(ts);
this->emotes_.insert(ts);
if (!p.second) { if (!p.second) {
// No inseration was made, figure out if we need to replace the // No inseration was made, figure out if we need to replace the
// username. // username.

View file

@ -51,7 +51,7 @@ public:
virtual QVariant data(const QModelIndex &index, int) const override; virtual QVariant data(const QModelIndex &index, int) const override;
virtual int rowCount(const QModelIndex &) const override; virtual int rowCount(const QModelIndex &) const override;
void refresh(); void refresh(const QString &prefix);
void addString(const QString &str, TaggedString::Type type); void addString(const QString &str, TaggedString::Type type);
void addUser(const QString &str); void addUser(const QString &str);

110
src/common/UsernameSet.cpp Normal file
View file

@ -0,0 +1,110 @@
#include "UsernameSet.hpp"
#include <tuple>
namespace chatterino {
//
// UsernameSet
//
UsernameSet::ConstIterator UsernameSet::begin() const
{
return this->items.begin();
}
UsernameSet::ConstIterator UsernameSet::end() const
{
return this->items.end();
}
UsernameSet::Range UsernameSet::subrange(const Prefix &prefix) const
{
auto it = this->firstKeyForPrefix.find(prefix);
if (it != this->firstKeyForPrefix.end()) {
auto start = this->items.find(it->second);
auto end = start;
while (end != this->items.end() && prefix.isStartOf(*end)) {
end++;
}
return {start, end};
}
return {this->items.end(), this->items.end()};
}
std::set<QString>::size_type UsernameSet::size() const
{
return this->items.size();
}
std::pair<UsernameSet::Iterator, bool> UsernameSet::insert(const QString &value)
{
this->insertPrefix(value);
return this->items.insert(value);
}
std::pair<UsernameSet::Iterator, bool> UsernameSet::insert(QString &&value)
{
this->insertPrefix(value);
return this->items.insert(std::move(value));
}
void UsernameSet::insertPrefix(const QString &value)
{
auto &string = this->firstKeyForPrefix[Prefix(value)];
if (string.isNull() || value < string) string = value;
}
//
// Range
//
UsernameSet::Range::Range(ConstIterator start, ConstIterator end)
: start_(start)
, end_(end)
{
}
UsernameSet::ConstIterator UsernameSet::Range::begin()
{
return this->start_;
}
UsernameSet::ConstIterator UsernameSet::Range::end()
{
return this->end_;
}
//
// Prefix
//
Prefix::Prefix(const QString &string)
: first(string.size() >= 1 ? string[0] : '\0')
, second(string.size() >= 2 ? string[1] : '\0')
{
}
bool Prefix::operator==(const Prefix &other) const
{
return std::tie(this->first, this->second) ==
std::tie(other.first, other.second);
}
bool Prefix::isStartOf(const QString &string) const
{
if (string.size() == 0) {
return this->first == QChar('\0') && this->second == QChar('\0');
} else if (string.size() == 1) {
return this->first == string[0] && this->second == QChar('\0');
} else {
return this->first == string[0] && this->second == string[1];
}
}
} // namespace chatterino

View file

@ -0,0 +1,73 @@
#pragma once
#include <QString>
#include <functional>
#include <set>
#include <unordered_map>
namespace chatterino {
class Prefix
{
public:
Prefix(const QString &string);
bool operator==(const Prefix &other) const;
bool isStartOf(const QString &string) const;
private:
QChar first;
QChar second;
friend struct std::hash<Prefix>;
};
} // namespace chatterino
namespace std {
template <>
struct hash<chatterino::Prefix> {
size_t operator()(const chatterino::Prefix &prefix) const
{
return (size_t(prefix.first.unicode()) << 16) |
size_t(prefix.second.unicode());
}
};
} // namespace std
namespace chatterino {
class UsernameSet
{
public:
static constexpr int PrefixLength = 2;
using Iterator = std::set<QString>::iterator;
using ConstIterator = std::set<QString>::const_iterator;
class Range
{
public:
Range(ConstIterator start, ConstIterator end);
ConstIterator begin();
ConstIterator end();
private:
ConstIterator start_;
ConstIterator end_;
};
ConstIterator begin() const;
ConstIterator end() const;
Range subrange(const Prefix &prefix) const;
std::set<QString>::size_type size() const;
std::pair<Iterator, bool> insert(const QString &value);
std::pair<Iterator, bool> insert(QString &&value);
private:
void insertPrefix(const QString &string);
std::set<QString> items;
std::unordered_map<Prefix, QString> firstKeyForPrefix;
};
} // namespace chatterino

View file

@ -49,6 +49,24 @@ auto parseRecentMessages(const QJsonObject &jsonRoot, TwitchChannel &channel)
return messages; return messages;
} }
std::pair<Outcome, UsernameSet> parseChatters(const QJsonObject &jsonRoot)
{
static QStringList categories = {"moderators", "staff", "admins",
"global_mods", "viewers"};
auto usernames = UsernameSet();
// parse json
QJsonObject jsonCategories = jsonRoot.value("chatters").toObject();
for (const auto &category : categories) {
for (auto jsonCategory : jsonCategories.value(category).toArray()) {
usernames.insert(jsonCategory.toString());
}
}
return {Success, std::move(usernames)};
}
} // namespace } // namespace
TwitchChannel::TwitchChannel(const QString &name, BttvEmotes &bttv, TwitchChannel::TwitchChannel(const QString &name, BttvEmotes &bttv,
@ -72,22 +90,22 @@ TwitchChannel::TwitchChannel(const QString &name, BttvEmotes &bttv,
[=] { this->setMod(false); }); [=] { this->setMod(false); });
// pubsub // pubsub
this->userStateChanged.connect([=] { this->refreshPubsub(); });
this->managedConnect(getApp()->accounts->twitch.currentUserChanged, this->managedConnect(getApp()->accounts->twitch.currentUserChanged,
[=] { this->refreshPubsub(); }); [=] { this->refreshPubsub(); });
this->refreshPubsub(); this->refreshPubsub();
this->userStateChanged.connect([this] { this->refreshPubsub(); });
// room id loaded -> refresh live status // room id loaded -> refresh live status
this->roomIdChanged.connect([this]() { this->roomIdChanged.connect([this]() {
this->refreshPubsub(); this->refreshPubsub();
this->refreshLiveStatus(); this->refreshLiveStatus();
this->loadBadges(); this->refreshBadges();
this->loadCheerEmotes(); this->refreshCheerEmotes();
}); });
// timers // timers
QObject::connect(&this->chattersListTimer_, &QTimer::timeout, QObject::connect(&this->chattersListTimer_, &QTimer::timeout,
[=] { this->refreshViewerList(); }); [=] { this->refreshChatters(); });
this->chattersListTimer_.start(5 * 60 * 1000); this->chattersListTimer_.start(5 * 60 * 1000);
QObject::connect(&this->liveStatusTimer_, &QTimer::timeout, QObject::connect(&this->liveStatusTimer_, &QTimer::timeout,
@ -101,11 +119,17 @@ TwitchChannel::TwitchChannel(const QString &name, BttvEmotes &bttv,
// debugging // debugging
#if 0 #if 0
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
this->addMessage(makeSystemMessage("asdf")); this->addMessage(makeSystemMessage("asef"));
} }
#endif #endif
} }
void TwitchChannel::initialize()
{
this->refreshChatters();
this->refreshChannelEmotes();
}
bool TwitchChannel::isEmpty() const bool TwitchChannel::isEmpty() const
{ {
return this->getName().isEmpty(); return this->getName().isEmpty();
@ -293,6 +317,11 @@ TwitchChannel::accessStreamStatus() const
return this->streamStatus_.accessConst(); return this->streamStatus_.accessConst();
} }
AccessGuard<const UsernameSet> TwitchChannel::accessChatters() const
{
return this->chatters_.accessConst();
}
const BttvEmotes &TwitchChannel::globalBttv() const const BttvEmotes &TwitchChannel::globalBttv() const
{ {
return this->globalBttv_; return this->globalBttv_;
@ -314,7 +343,7 @@ boost::optional<EmotePtr> TwitchChannel::bttvEmote(const EmoteName &name) const
boost::optional<EmotePtr> TwitchChannel::ffzEmote(const EmoteName &name) const boost::optional<EmotePtr> TwitchChannel::ffzEmote(const EmoteName &name) const
{ {
auto emotes = this->bttvEmotes_.get(); auto emotes = this->ffzEmotes_.get();
auto it = emotes->find(name); auto it = emotes->find(name);
if (it == emotes->end()) return boost::none; if (it == emotes->end()) return boost::none;
@ -508,7 +537,7 @@ void TwitchChannel::refreshPubsub()
account); account);
} }
void TwitchChannel::refreshViewerList() void TwitchChannel::refreshChatters()
{ {
// setting? // setting?
const auto streamStatus = this->accessStreamStatus(); const auto streamStatus = this->accessStreamStatus();
@ -531,31 +560,18 @@ void TwitchChannel::refreshViewerList()
auto shared = weak.lock(); auto shared = weak.lock();
if (!shared) return Failure; if (!shared) return Failure;
return this->parseViewerList(result.parseJson()); auto pair = parseChatters(result.parseJson());
if (pair.first) {
*this->chatters_.access() = std::move(pair.second);
}
return pair.first;
}); });
request.execute(); request.execute();
} }
Outcome TwitchChannel::parseViewerList(const QJsonObject &jsonRoot) void TwitchChannel::refreshBadges()
{
static QStringList categories = {"moderators", "staff", "admins",
"global_mods", "viewers"};
// parse json
QJsonObject jsonCategories = jsonRoot.value("chatters").toObject();
for (const auto &category : categories) {
for (const auto jsonCategory :
jsonCategories.value(category).toArray()) {
this->completionModel.addUser(jsonCategory.toString());
}
}
return Success;
}
void TwitchChannel::loadBadges()
{ {
auto url = Url{"https://badges.twitch.tv/v1/badges/channels/" + auto url = Url{"https://badges.twitch.tv/v1/badges/channels/" +
this->roomId() + "/display?language=en"}; this->roomId() + "/display?language=en"};
@ -600,7 +616,7 @@ void TwitchChannel::loadBadges()
req.execute(); req.execute();
} }
void TwitchChannel::loadCheerEmotes() void TwitchChannel::refreshCheerEmotes()
{ {
/*auto url = Url{"https://api.twitch.tv/kraken/bits/actions?channel_id=" + /*auto url = Url{"https://api.twitch.tv/kraken/bits/actions?channel_id=" +
this->getRoomId()}; this->getRoomId()};
@ -664,7 +680,7 @@ void TwitchChannel::loadCheerEmotes()
*/ */
} }
boost::optional<EmotePtr> TwitchChannel::getTwitchBadge( boost::optional<EmotePtr> TwitchChannel::twitchBadge(
const QString &set, const QString &version) const const QString &set, const QString &version) const
{ {
auto badgeSets = this->badgeSets_.access(); auto badgeSets = this->badgeSets_.access();

View file

@ -1,13 +1,17 @@
#pragma once #pragma once
#include <IrcConnection>
#include "common/Aliases.hpp" #include "common/Aliases.hpp"
#include "common/Atomic.hpp" #include "common/Atomic.hpp"
#include "common/Channel.hpp" #include "common/Channel.hpp"
#include "common/Outcome.hpp" #include "common/Outcome.hpp"
#include "common/UniqueAccess.hpp" #include "common/UniqueAccess.hpp"
#include "common/UsernameSet.hpp"
#include "providers/twitch/TwitchEmotes.hpp"
#include <rapidjson/document.h>
#include <IrcConnection>
#include <QColor>
#include <QRegularExpression>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <mutex> #include <mutex>
#include <pajlada/signals/signalholder.hpp> #include <pajlada/signals/signalholder.hpp>
@ -37,11 +41,6 @@ public:
QString streamType; QString streamType;
}; };
struct UserState {
bool mod;
bool broadcaster;
};
struct RoomModes { struct RoomModes {
bool submode = false; bool submode = false;
bool r9k = false; bool r9k = false;
@ -51,32 +50,24 @@ public:
QString broadcasterLang; QString broadcasterLang;
}; };
void refreshChannelEmotes(); void initialize();
// Channel methods // Channel methods
virtual bool isEmpty() const override; virtual bool isEmpty() const override;
virtual bool canSendMessage() const override; virtual bool canSendMessage() const override;
virtual void sendMessage(const QString &message) override; virtual void sendMessage(const QString &message) override;
// Auto completion
void addRecentChatter(const MessagePtr &message) final;
void addJoinedUser(const QString &user);
void addPartedUser(const QString &user);
bool isLive() const;
virtual bool isMod() const override; virtual bool isMod() const override;
void setMod(bool value);
virtual bool isBroadcaster() const override; virtual bool isBroadcaster() const override;
// Data // Data
const QString &subscriptionUrl(); const QString &subscriptionUrl();
const QString &channelUrl(); const QString &channelUrl();
const QString &popoutPlayerUrl(); const QString &popoutPlayerUrl();
bool isLive() const;
QString roomId() const; QString roomId() const;
void setRoomId(const QString &id);
AccessGuard<const RoomModes> accessRoomModes() const; AccessGuard<const RoomModes> accessRoomModes() const;
void setRoomModes(const RoomModes &roomModes_);
AccessGuard<const StreamStatus> accessStreamStatus() const; AccessGuard<const StreamStatus> accessStreamStatus() const;
AccessGuard<const UsernameSet> accessChatters() const;
// Emotes // Emotes
const BttvEmotes &globalBttv() const; const BttvEmotes &globalBttv() const;
@ -86,58 +77,53 @@ public:
std::shared_ptr<const EmoteMap> bttvEmotes() const; std::shared_ptr<const EmoteMap> bttvEmotes() const;
std::shared_ptr<const EmoteMap> ffzEmotes() const; std::shared_ptr<const EmoteMap> ffzEmotes() const;
boost::optional<EmotePtr> getTwitchBadge(const QString &set, void refreshChannelEmotes();
// Badges
boost::optional<EmotePtr> twitchBadge(const QString &set,
const QString &version) const; const QString &version) const;
// Signals // Signals
pajlada::Signals::NoArgSignal roomIdChanged; pajlada::Signals::NoArgSignal roomIdChanged;
pajlada::Signals::NoArgSignal liveStatusChanged;
pajlada::Signals::NoArgSignal userStateChanged; pajlada::Signals::NoArgSignal userStateChanged;
pajlada::Signals::NoArgSignal liveStatusChanged;
pajlada::Signals::NoArgSignal roomModesChanged; pajlada::Signals::NoArgSignal roomModesChanged;
protected:
void addRecentChatter(const MessagePtr &message) override;
private: private:
struct NameOptions { struct NameOptions {
QString displayName; QString displayName;
QString localizedName; QString localizedName;
}; };
struct CheerEmote { explicit TwitchChannel(const QString &channelName, BttvEmotes &globalBttv,
// a Cheermote indicates one tier FfzEmotes &globalFfz);
QColor color;
int minBits;
EmotePtr animatedEmote;
EmotePtr staticEmote;
};
struct CheerEmoteSet {
QRegularExpression regex;
std::vector<CheerEmote> cheerEmotes;
};
explicit TwitchChannel(const QString &channelName, BttvEmotes &bttv,
FfzEmotes &ffz);
// Methods // Methods
void refreshLiveStatus(); void refreshLiveStatus();
Outcome parseLiveStatus(const rapidjson::Document &document); Outcome parseLiveStatus(const rapidjson::Document &document);
void refreshPubsub(); void refreshPubsub();
void refreshViewerList(); void refreshChatters();
Outcome parseViewerList(const QJsonObject &jsonRoot); void refreshBadges();
void refreshCheerEmotes();
void loadRecentMessages(); void loadRecentMessages();
void addJoinedUser(const QString &user);
void addPartedUser(const QString &user);
void setLive(bool newLiveStatus); void setLive(bool newLiveStatus);
void setMod(bool value);
void loadBadges(); void setRoomId(const QString &id);
void loadCheerEmotes(); void setRoomModes(const RoomModes &roomModes_);
// Data // Data
const QString subscriptionUrl_; const QString subscriptionUrl_;
const QString channelUrl_; const QString channelUrl_;
const QString popoutPlayerUrl_; const QString popoutPlayerUrl_;
UniqueAccess<StreamStatus> streamStatus_; UniqueAccess<StreamStatus> streamStatus_;
UniqueAccess<UserState> userState_;
UniqueAccess<RoomModes> roomModes_; UniqueAccess<RoomModes> roomModes_;
UniqueAccess<UsernameSet> chatters_; // maps 2 char prefix to set of names
// Emotes // Emotes
BttvEmotes &globalBttv_; BttvEmotes &globalBttv_;
@ -145,6 +131,11 @@ private:
Atomic<std::shared_ptr<const EmoteMap>> bttvEmotes_; Atomic<std::shared_ptr<const EmoteMap>> bttvEmotes_;
Atomic<std::shared_ptr<const EmoteMap>> ffzEmotes_; Atomic<std::shared_ptr<const EmoteMap>> ffzEmotes_;
// Badges
UniqueAccess<std::map<QString, std::map<QString, EmotePtr>>>
badgeSets_; // "subscribers": { "0": ... "3": ... "6": ...
UniqueAccess<std::vector<CheerEmoteSet>> cheerEmoteSets_;
bool mod_ = false; bool mod_ = false;
UniqueAccess<QString> roomID_; UniqueAccess<QString> roomID_;
@ -153,10 +144,6 @@ private:
UniqueAccess<QStringList> partedUsers_; UniqueAccess<QStringList> partedUsers_;
bool partedUsersMergeQueued_ = false; bool partedUsersMergeQueued_ = false;
// "subscribers": { "0": ... "3": ... "6": ...
UniqueAccess<std::map<QString, std::map<QString, EmotePtr>>> badgeSets_;
UniqueAccess<std::vector<CheerEmoteSet>> cheerEmoteSets_;
// -- // --
QByteArray messageSuffix_; QByteArray messageSuffix_;
QString lastSentMessage_; QString lastSentMessage_;
@ -165,6 +152,8 @@ private:
QTimer chattersListTimer_; QTimer chattersListTimer_;
friend class TwitchServer; friend class TwitchServer;
friend class TwitchMessageBuilder;
friend class IrcMessageHandler;
}; };
} // namespace chatterino } // namespace chatterino

View file

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <QColor>
#include <QRegularExpression>
#include <QString> #include <QString>
#include <unordered_map> #include <unordered_map>
@ -11,10 +13,22 @@
"https://static-cdn.jtvnw.net/emoticons/v1/{id}/{scale}" "https://static-cdn.jtvnw.net/emoticons/v1/{id}/{scale}"
namespace chatterino { namespace chatterino {
struct Emote; struct Emote;
using EmotePtr = std::shared_ptr<const Emote>; using EmotePtr = std::shared_ptr<const Emote>;
struct CheerEmote {
QColor color;
int minBits;
EmotePtr animatedEmote;
EmotePtr staticEmote;
};
struct CheerEmoteSet {
QRegularExpression regex;
std::vector<CheerEmote> cheerEmotes;
};
class TwitchEmotes class TwitchEmotes
{ {
public: public:

View file

@ -646,7 +646,7 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
flags = MessageElementFlag::BttvEmote; flags = MessageElementFlag::BttvEmote;
} else if ((emote = this->twitchChannel->globalFfz().emote(name))) { } else if ((emote = this->twitchChannel->globalFfz().emote(name))) {
flags = MessageElementFlag::FfzEmote; flags = MessageElementFlag::FfzEmote;
} else if (twitchChannel && (emote = this->twitchChannel->ffzEmote(name))) { } else if ((emote = this->twitchChannel->ffzEmote(name))) {
flags = MessageElementFlag::FfzEmote; flags = MessageElementFlag::FfzEmote;
} }
@ -691,7 +691,7 @@ void TwitchMessageBuilder::appendTwitchBadges()
// Try to fetch channel-specific bit badge // Try to fetch channel-specific bit badge
try { try {
if (twitchChannel) if (twitchChannel)
if (const auto &badge = this->twitchChannel->getTwitchBadge( if (const auto &badge = this->twitchChannel->twitchBadge(
"bits", cheerAmount)) { "bits", cheerAmount)) {
this->emplace<EmoteElement>( this->emplace<EmoteElement>(
badge.get(), MessageElementFlag::BadgeVanity) badge.get(), MessageElementFlag::BadgeVanity)

View file

@ -85,7 +85,7 @@ std::shared_ptr<Channel> TwitchServer::createChannel(const QString &channelName)
{ {
auto channel = std::shared_ptr<TwitchChannel>( auto channel = std::shared_ptr<TwitchChannel>(
new TwitchChannel(channelName, this->bttv, this->ffz)); new TwitchChannel(channelName, this->bttv, this->ffz));
channel->refreshChannelEmotes(); channel->initialize();
channel->sendMessageSignal.connect( channel->sendMessageSignal.connect(
[this, channel = channel.get()](auto &chan, auto &msg, bool &sent) { [this, channel = channel.get()](auto &chan, auto &msg, bool &sent) {

View file

@ -102,7 +102,7 @@ void ResizingTextEdit::keyPressEvent(QKeyEvent *event)
// First type pressing tab after modifying a message, we refresh our // First type pressing tab after modifying a message, we refresh our
// completion model // completion model
this->completer_->setModel(completionModel); this->completer_->setModel(completionModel);
completionModel->refresh(); completionModel->refresh(currentCompletionPrefix);
this->completionInProgress_ = true; this->completionInProgress_ = true;
this->completer_->setCompletionPrefix(currentCompletionPrefix); this->completer_->setCompletionPrefix(currentCompletionPrefix);
this->completer_->complete(); this->completer_->complete();