this commit is too big
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
#include <functional>
|
||||
|
||||
#define QStringAlias(name) \
|
||||
namespace chatterino { \
|
||||
struct name { \
|
||||
QString string; \
|
||||
bool operator==(const name &other) const \
|
||||
{ \
|
||||
return this->string == other.string; \
|
||||
} \
|
||||
bool operator!=(const name &other) const \
|
||||
{ \
|
||||
return this->string != other.string; \
|
||||
} \
|
||||
}; \
|
||||
} /* namespace chatterino */ \
|
||||
namespace std { \
|
||||
template <> \
|
||||
struct hash<chatterino::name> { \
|
||||
size_t operator()(const chatterino::name &s) const \
|
||||
{ \
|
||||
return qHash(s.string); \
|
||||
} \
|
||||
}; \
|
||||
} /* namespace std */
|
||||
|
||||
QStringAlias(UserName);
|
||||
QStringAlias(UserId);
|
||||
QStringAlias(Url);
|
||||
QStringAlias(Tooltip);
|
||||
+10
-5
@@ -17,9 +17,9 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
Channel::Channel(const QString &_name, Type type)
|
||||
: name(_name)
|
||||
, completionModel(this->name)
|
||||
Channel::Channel(const QString &name, Type type)
|
||||
: completionModel(name)
|
||||
, name_(name)
|
||||
, type_(type)
|
||||
{
|
||||
QObject::connect(&this->clearCompletionModelTimer_, &QTimer::timeout, [this]() {
|
||||
@@ -38,6 +38,11 @@ Channel::Type Channel::getType() const
|
||||
return this->type_;
|
||||
}
|
||||
|
||||
const QString &Channel::getName() const
|
||||
{
|
||||
return this->name_;
|
||||
}
|
||||
|
||||
bool Channel::isTwitchChannel() const
|
||||
{
|
||||
return this->type_ >= Type::Twitch && this->type_ < Type::TwitchEnd;
|
||||
@@ -45,7 +50,7 @@ bool Channel::isTwitchChannel() const
|
||||
|
||||
bool Channel::isEmpty() const
|
||||
{
|
||||
return this->name.isEmpty();
|
||||
return this->name_.isEmpty();
|
||||
}
|
||||
|
||||
LimitedQueueSnapshot<MessagePtr> Channel::getMessageSnapshot()
|
||||
@@ -66,7 +71,7 @@ void Channel::addMessage(MessagePtr message)
|
||||
|
||||
// FOURTF: change this when adding more providers
|
||||
if (this->isTwitchChannel()) {
|
||||
app->logging->addMessage(this->name, message);
|
||||
app->logging->addMessage(this->name_, message);
|
||||
}
|
||||
|
||||
if (this->messages_.pushBack(message, deleted)) {
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
pajlada::Signals::NoArgSignal destroyed;
|
||||
|
||||
Type getType() const;
|
||||
const QString &getName() const;
|
||||
bool isTwitchChannel() const;
|
||||
virtual bool isEmpty() const;
|
||||
LimitedQueueSnapshot<MessagePtr> getMessageSnapshot();
|
||||
@@ -52,7 +53,6 @@ public:
|
||||
void replaceMessage(MessagePtr message, MessagePtr replacement);
|
||||
virtual void addRecentChatter(const std::shared_ptr<Message> &message);
|
||||
|
||||
QString name;
|
||||
QStringList modList;
|
||||
|
||||
virtual bool canSendMessage() const;
|
||||
@@ -72,6 +72,7 @@ protected:
|
||||
virtual void onConnected();
|
||||
|
||||
private:
|
||||
const QString name_;
|
||||
LimitedQueue<MessagePtr> messages_;
|
||||
Type type_;
|
||||
QTimer clearCompletionModelTimer_;
|
||||
|
||||
+16
-8
@@ -1,9 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Aliases.hpp"
|
||||
#include "common/Outcome.hpp"
|
||||
#include "common/ProviderId.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/preprocessor.hpp>
|
||||
|
||||
#include <string>
|
||||
@@ -27,14 +31,18 @@ const Qt::KeyboardModifiers showResizeHandlesModifiers = Qt::ControlModifier;
|
||||
|
||||
static const char *ANONYMOUS_USERNAME_LABEL ATTR_UNUSED = " - anonymous - ";
|
||||
|
||||
#define return_if(condition) \
|
||||
if ((condition)) { \
|
||||
return; \
|
||||
}
|
||||
template <typename T>
|
||||
std::weak_ptr<T> weakOf(T *element)
|
||||
{
|
||||
return element->shared_from_this();
|
||||
}
|
||||
|
||||
#define return_unless(condition) \
|
||||
if (!(condition)) { \
|
||||
return; \
|
||||
}
|
||||
template <class... Ts>
|
||||
struct overloaded : Ts... {
|
||||
using Ts::operator()...;
|
||||
};
|
||||
|
||||
template <class... Ts>
|
||||
overloaded(Ts...)->overloaded<Ts...>;
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "common/Common.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "controllers/commands/CommandController.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "providers/twitch/TwitchServer.hpp"
|
||||
#include "singletons/Emotes.hpp"
|
||||
|
||||
#include <QtAlgorithms>
|
||||
@@ -107,41 +109,45 @@ void CompletionModel::refresh()
|
||||
auto app = getApp();
|
||||
|
||||
// User-specific: Twitch Emotes
|
||||
// TODO: Fix this so it properly updates with the proper api. oauth token needs proper scope
|
||||
for (const auto &m : app->emotes->twitch.emotes) {
|
||||
for (const auto &emoteName : m.second.emoteCodes) {
|
||||
if (auto account = app->accounts->twitch.getCurrent()) {
|
||||
for (const auto &emote : account->accessEmotes()->allEmoteNames) {
|
||||
// XXX: No way to discern between a twitch global emote and sub emote right now
|
||||
this->addString(emoteName, TaggedString::Type::TwitchGlobalEmote);
|
||||
this->addString(emote.string, TaggedString::Type::TwitchGlobalEmote);
|
||||
}
|
||||
}
|
||||
|
||||
// Global: BTTV Global Emotes
|
||||
std::vector<QString> &bttvGlobalEmoteCodes = app->emotes->bttv.globalEmoteCodes;
|
||||
for (const auto &m : bttvGlobalEmoteCodes) {
|
||||
this->addString(m, TaggedString::Type::BTTVGlobalEmote);
|
||||
// // Global: BTTV Global Emotes
|
||||
// std::vector<QString> &bttvGlobalEmoteCodes = app->emotes->bttv.globalEmoteNames_;
|
||||
// for (const auto &m : bttvGlobalEmoteCodes) {
|
||||
// this->addString(m, TaggedString::Type::BTTVGlobalEmote);
|
||||
// }
|
||||
|
||||
// // Global: FFZ Global Emotes
|
||||
// std::vector<QString> &ffzGlobalEmoteCodes = app->emotes->ffz.globalEmoteCodes;
|
||||
// for (const auto &m : ffzGlobalEmoteCodes) {
|
||||
// this->addString(m, TaggedString::Type::FFZGlobalEmote);
|
||||
// }
|
||||
|
||||
// Channel emotes
|
||||
if (auto channel = dynamic_cast<TwitchChannel *>(
|
||||
getApp()->twitch2->getChannelOrEmptyByID(this->channelName_).get())) {
|
||||
auto bttv = channel->accessBttvEmotes();
|
||||
// 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->accessFfzEmotes()) {
|
||||
this->addString(emote.second->name.string, TaggedString::Type::FFZChannelEmote);
|
||||
}
|
||||
}
|
||||
|
||||
// Global: FFZ Global Emotes
|
||||
std::vector<QString> &ffzGlobalEmoteCodes = app->emotes->ffz.globalEmoteCodes;
|
||||
for (const auto &m : ffzGlobalEmoteCodes) {
|
||||
this->addString(m, TaggedString::Type::FFZGlobalEmote);
|
||||
}
|
||||
|
||||
// Channel-specific: BTTV Channel Emotes
|
||||
std::vector<QString> &bttvChannelEmoteCodes =
|
||||
app->emotes->bttv.channelEmoteCodes[this->channelName_];
|
||||
for (const auto &m : bttvChannelEmoteCodes) {
|
||||
this->addString(m, TaggedString::Type::BTTVChannelEmote);
|
||||
}
|
||||
|
||||
// Channel-specific: FFZ Channel Emotes
|
||||
std::vector<QString> &ffzChannelEmoteCodes =
|
||||
app->emotes->ffz.channelEmoteCodes[this->channelName_];
|
||||
for (const auto &m : ffzChannelEmoteCodes) {
|
||||
this->addString(m, TaggedString::Type::FFZChannelEmote);
|
||||
}
|
||||
|
||||
// Global: Emojis
|
||||
// Emojis
|
||||
const auto &emojiShortCodes = app->emotes->emojis.shortCodes;
|
||||
for (const auto &m : emojiShortCodes) {
|
||||
this->addString(":" + m + ":", TaggedString::Type::Emoji);
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class TwitchChannel;
|
||||
|
||||
class CompletionModel : public QAbstractListModel
|
||||
{
|
||||
struct TaggedString {
|
||||
|
||||
+32
-32
@@ -5,42 +5,42 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
EmoteData::EmoteData(Image *image)
|
||||
: image1x(image)
|
||||
{
|
||||
}
|
||||
// EmoteData::EmoteData(Image *image)
|
||||
// : image1x(image)
|
||||
//{
|
||||
//}
|
||||
|
||||
// Emotes must have a 1x image to be valid
|
||||
bool EmoteData::isValid() const
|
||||
{
|
||||
return this->image1x != nullptr;
|
||||
}
|
||||
//// Emotes must have a 1x image to be valid
|
||||
// bool EmoteData::isValid() const
|
||||
//{
|
||||
// return this->image1x != nullptr;
|
||||
//}
|
||||
|
||||
Image *EmoteData::getImage(float scale) const
|
||||
{
|
||||
int quality = getApp()->settings->preferredEmoteQuality;
|
||||
// Image *EmoteData::getImage(float scale) const
|
||||
//{
|
||||
// int quality = getApp()->settings->preferredEmoteQuality;
|
||||
|
||||
if (quality == 0) {
|
||||
scale *= getApp()->settings->emoteScale.getValue();
|
||||
quality = [&] {
|
||||
if (scale <= 1)
|
||||
return 1;
|
||||
if (scale <= 2)
|
||||
return 2;
|
||||
return 3;
|
||||
}();
|
||||
}
|
||||
// if (quality == 0) {
|
||||
// scale *= getApp()->settings->emoteScale.getValue();
|
||||
// quality = [&] {
|
||||
// if (scale <= 1)
|
||||
// return 1;
|
||||
// if (scale <= 2)
|
||||
// return 2;
|
||||
// return 3;
|
||||
// }();
|
||||
// }
|
||||
|
||||
Image *_image;
|
||||
if (quality == 3 && this->image3x != nullptr) {
|
||||
_image = this->image3x;
|
||||
} else if (quality >= 2 && this->image2x != nullptr) {
|
||||
_image = this->image2x;
|
||||
} else {
|
||||
_image = this->image1x;
|
||||
}
|
||||
// Image *_image;
|
||||
// if (quality == 3 && this->image3x != nullptr) {
|
||||
// _image = this->image3x;
|
||||
// } else if (quality >= 2 && this->image2x != nullptr) {
|
||||
// _image = this->image2x;
|
||||
// } else {
|
||||
// _image = this->image1x;
|
||||
// }
|
||||
|
||||
return _image;
|
||||
}
|
||||
// return _image;
|
||||
//}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
+13
-13
@@ -5,23 +5,23 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
struct EmoteData {
|
||||
EmoteData() = default;
|
||||
// struct EmoteData {
|
||||
// EmoteData() = default;
|
||||
|
||||
EmoteData(Image *image);
|
||||
// EmoteData(Image *image);
|
||||
|
||||
// Emotes must have a 1x image to be valid
|
||||
bool isValid() const;
|
||||
Image *getImage(float scale) const;
|
||||
// // Emotes must have a 1x image to be valid
|
||||
// bool isValid() const;
|
||||
// Image *getImage(float scale) const;
|
||||
|
||||
// Link to the emote page i.e. https://www.frankerfacez.com/emoticon/144722-pajaCringe
|
||||
QString pageLink;
|
||||
// // Link to the emote page i.e. https://www.frankerfacez.com/emoticon/144722-pajaCringe
|
||||
// QString pageLink;
|
||||
|
||||
Image *image1x = nullptr;
|
||||
Image *image2x = nullptr;
|
||||
Image *image3x = nullptr;
|
||||
};
|
||||
// Image *image1x = nullptr;
|
||||
// Image *image2x = nullptr;
|
||||
// Image *image3x = nullptr;
|
||||
//};
|
||||
|
||||
using EmoteMap = ConcurrentMap<QString, EmoteData>;
|
||||
// using EmoteMap = ConcurrentMap<QString, EmoteData>;
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "Common.hpp"
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class NetworkResult;
|
||||
|
||||
using NetworkSuccessCallback = std::function<bool(NetworkResult)>;
|
||||
using NetworkSuccessCallback = std::function<Outcome(NetworkResult)>;
|
||||
using NetworkErrorCallback = std::function<bool(int)>;
|
||||
using NetworkReplyCreatedCallback = std::function<void(QNetworkReply *)>;
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ void NetworkRequest::execute()
|
||||
}
|
||||
}
|
||||
|
||||
bool NetworkRequest::tryLoadCachedFile()
|
||||
Outcome NetworkRequest::tryLoadCachedFile()
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
@@ -137,24 +137,24 @@ bool NetworkRequest::tryLoadCachedFile()
|
||||
|
||||
if (!cachedFile.exists()) {
|
||||
// File didn't exist
|
||||
return false;
|
||||
return Failure;
|
||||
}
|
||||
|
||||
if (!cachedFile.open(QIODevice::ReadOnly)) {
|
||||
// File could not be opened
|
||||
return false;
|
||||
return Failure;
|
||||
}
|
||||
|
||||
QByteArray bytes = cachedFile.readAll();
|
||||
NetworkResult result(bytes);
|
||||
|
||||
bool success = this->data->onSuccess_(result);
|
||||
auto outcome = this->data->onSuccess_(result);
|
||||
|
||||
cachedFile.close();
|
||||
|
||||
// XXX: If success is false, we should invalidate the cache file somehow/somewhere
|
||||
|
||||
return success;
|
||||
return outcome;
|
||||
}
|
||||
|
||||
void NetworkRequest::doRequest()
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
|
||||
explicit NetworkRequest(const std::string &url,
|
||||
NetworkRequestType requestType = NetworkRequestType::Get);
|
||||
NetworkRequest(QUrl url, NetworkRequestType requestType = NetworkRequestType::Get);
|
||||
explicit NetworkRequest(QUrl url, NetworkRequestType requestType = NetworkRequestType::Get);
|
||||
|
||||
~NetworkRequest();
|
||||
|
||||
@@ -58,7 +58,7 @@ private:
|
||||
// Returns true if the file was successfully loaded from cache
|
||||
// Returns false if the cache file either didn't exist, or it contained "invalid" data
|
||||
// "invalid" is specified by the onSuccess callback
|
||||
bool tryLoadCachedFile();
|
||||
Outcome tryLoadCachedFile();
|
||||
|
||||
void doRequest();
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ rapidjson::Document NetworkResult::parseRapidJson() const
|
||||
return ret;
|
||||
}
|
||||
|
||||
QByteArray NetworkResult::getData() const
|
||||
const QByteArray &NetworkResult::getData() const
|
||||
{
|
||||
return this->data_;
|
||||
}
|
||||
|
||||
@@ -7,14 +7,15 @@ namespace chatterino {
|
||||
|
||||
class NetworkResult
|
||||
{
|
||||
QByteArray data_;
|
||||
|
||||
public:
|
||||
NetworkResult(const QByteArray &data);
|
||||
|
||||
QJsonObject parseJson() const;
|
||||
rapidjson::Document parseRapidJson() const;
|
||||
QByteArray getData() const;
|
||||
const QByteArray &getData() const;
|
||||
|
||||
private:
|
||||
QByteArray data_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
template <typename T>
|
||||
@@ -23,7 +25,7 @@ public:
|
||||
return element_;
|
||||
}
|
||||
|
||||
T &operator*() const
|
||||
typename std::add_lvalue_reference<T>::type &operator*() const
|
||||
{
|
||||
assert(this->hasElement());
|
||||
|
||||
@@ -52,6 +54,17 @@ public:
|
||||
return this->hasElement();
|
||||
}
|
||||
|
||||
bool operator!() const
|
||||
{
|
||||
return !this->hasElement();
|
||||
}
|
||||
|
||||
template <typename X = T, typename = std::enable_if_t<!std::is_const<X>::value>>
|
||||
operator NullablePtr<const T>() const
|
||||
{
|
||||
return NullablePtr<const T>(this->element_);
|
||||
}
|
||||
|
||||
private:
|
||||
T *element_;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
struct SuccessTag {
|
||||
};
|
||||
|
||||
struct FailureTag {
|
||||
};
|
||||
|
||||
const SuccessTag Success{};
|
||||
const FailureTag Failure{};
|
||||
|
||||
class Outcome
|
||||
{
|
||||
public:
|
||||
Outcome(SuccessTag)
|
||||
: success_(true)
|
||||
{
|
||||
}
|
||||
|
||||
Outcome(FailureTag)
|
||||
: success_(false)
|
||||
{
|
||||
}
|
||||
|
||||
explicit operator bool() const
|
||||
{
|
||||
return this->success_;
|
||||
}
|
||||
|
||||
bool operator!() const
|
||||
{
|
||||
return !this->success_;
|
||||
}
|
||||
|
||||
bool operator==(const Outcome &other) const
|
||||
{
|
||||
return this->success_ == other.success_;
|
||||
}
|
||||
|
||||
bool operator!=(const Outcome &other) const
|
||||
{
|
||||
return !this->operator==(other);
|
||||
}
|
||||
|
||||
private:
|
||||
bool success_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
@@ -4,14 +4,18 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Application;
|
||||
class Settings;
|
||||
class Paths;
|
||||
|
||||
class Singleton : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
virtual void initialize(Application &app)
|
||||
virtual ~Singleton() = default;
|
||||
|
||||
virtual void initialize(Settings &settings, Paths &paths)
|
||||
{
|
||||
(void)(app);
|
||||
(void)(settings);
|
||||
(void)(paths);
|
||||
}
|
||||
|
||||
virtual void save()
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <mutex>
|
||||
#include <type_traits>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
template <typename T>
|
||||
class AccessGuard
|
||||
class AccessGuard : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
AccessGuard(T &element, std::mutex &mutex)
|
||||
@@ -21,31 +22,16 @@ public:
|
||||
this->mutex_.unlock();
|
||||
}
|
||||
|
||||
const T *operator->() const
|
||||
T *operator->() const
|
||||
{
|
||||
return &this->element_;
|
||||
}
|
||||
|
||||
T *operator->()
|
||||
{
|
||||
return &this->element_;
|
||||
}
|
||||
|
||||
const T &operator*() const
|
||||
T &operator*() const
|
||||
{
|
||||
return this->element_;
|
||||
}
|
||||
|
||||
T &operator*()
|
||||
{
|
||||
return this->element_;
|
||||
}
|
||||
|
||||
T clone() const
|
||||
{
|
||||
return T(this->element_);
|
||||
}
|
||||
|
||||
private:
|
||||
T &element_;
|
||||
std::mutex &mutex_;
|
||||
@@ -55,7 +41,7 @@ template <typename T>
|
||||
class UniqueAccess
|
||||
{
|
||||
public:
|
||||
template <typename X = decltype(T())>
|
||||
// template <typename X = decltype(T())>
|
||||
UniqueAccess()
|
||||
: element_(T())
|
||||
{
|
||||
@@ -83,14 +69,15 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
AccessGuard<T> access()
|
||||
AccessGuard<T> access() const
|
||||
{
|
||||
return AccessGuard<T>(this->element_, this->mutex_);
|
||||
}
|
||||
|
||||
const AccessGuard<T> access() const
|
||||
template <typename X = T, typename = std::enable_if_t<!std::is_const_v<X>>>
|
||||
AccessGuard<const X> accessConst() const
|
||||
{
|
||||
return AccessGuard<T>(this->element_, this->mutex_);
|
||||
return AccessGuard<const T>(this->element_, this->mutex_);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user