Add CI workflow to check line endings of all source files (#2082)
In addition, all found errors (formatting & line ending) have been fixed in this PR.
This commit is contained in:
@@ -1,72 +1,72 @@
|
||||
#include "ChannelChatters.hpp"
|
||||
|
||||
#include "messages/Message.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
ChannelChatters::ChannelChatters(Channel &channel)
|
||||
: channel_(channel)
|
||||
{
|
||||
}
|
||||
|
||||
AccessGuard<const UsernameSet> ChannelChatters::accessChatters() const
|
||||
{
|
||||
return this->chatters_.accessConst();
|
||||
}
|
||||
|
||||
void ChannelChatters::addRecentChatter(const QString &user)
|
||||
{
|
||||
this->chatters_.access()->insert(user);
|
||||
}
|
||||
|
||||
void ChannelChatters::addJoinedUser(const QString &user)
|
||||
{
|
||||
auto joinedUsers = this->joinedUsers_.access();
|
||||
joinedUsers->append(user);
|
||||
|
||||
if (!this->joinedUsersMergeQueued_)
|
||||
{
|
||||
this->joinedUsersMergeQueued_ = true;
|
||||
|
||||
QTimer::singleShot(500, &this->lifetimeGuard_, [this] {
|
||||
auto joinedUsers = this->joinedUsers_.access();
|
||||
|
||||
MessageBuilder builder(systemMessage,
|
||||
"Users joined: " + joinedUsers->join(", "));
|
||||
builder->flags.set(MessageFlag::Collapsed);
|
||||
joinedUsers->clear();
|
||||
this->channel_.addMessage(builder.release());
|
||||
this->joinedUsersMergeQueued_ = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelChatters::addPartedUser(const QString &user)
|
||||
{
|
||||
auto partedUsers = this->partedUsers_.access();
|
||||
partedUsers->append(user);
|
||||
|
||||
if (!this->partedUsersMergeQueued_)
|
||||
{
|
||||
this->partedUsersMergeQueued_ = true;
|
||||
|
||||
QTimer::singleShot(500, &this->lifetimeGuard_, [this] {
|
||||
auto partedUsers = this->partedUsers_.access();
|
||||
|
||||
MessageBuilder builder(systemMessage,
|
||||
"Users parted: " + partedUsers->join(", "));
|
||||
builder->flags.set(MessageFlag::Collapsed);
|
||||
this->channel_.addMessage(builder.release());
|
||||
partedUsers->clear();
|
||||
|
||||
this->partedUsersMergeQueued_ = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
void ChannelChatters::setChatters(UsernameSet &&set)
|
||||
{
|
||||
*this->chatters_.access() = set;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
#include "ChannelChatters.hpp"
|
||||
|
||||
#include "messages/Message.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
ChannelChatters::ChannelChatters(Channel &channel)
|
||||
: channel_(channel)
|
||||
{
|
||||
}
|
||||
|
||||
AccessGuard<const UsernameSet> ChannelChatters::accessChatters() const
|
||||
{
|
||||
return this->chatters_.accessConst();
|
||||
}
|
||||
|
||||
void ChannelChatters::addRecentChatter(const QString &user)
|
||||
{
|
||||
this->chatters_.access()->insert(user);
|
||||
}
|
||||
|
||||
void ChannelChatters::addJoinedUser(const QString &user)
|
||||
{
|
||||
auto joinedUsers = this->joinedUsers_.access();
|
||||
joinedUsers->append(user);
|
||||
|
||||
if (!this->joinedUsersMergeQueued_)
|
||||
{
|
||||
this->joinedUsersMergeQueued_ = true;
|
||||
|
||||
QTimer::singleShot(500, &this->lifetimeGuard_, [this] {
|
||||
auto joinedUsers = this->joinedUsers_.access();
|
||||
|
||||
MessageBuilder builder(systemMessage,
|
||||
"Users joined: " + joinedUsers->join(", "));
|
||||
builder->flags.set(MessageFlag::Collapsed);
|
||||
joinedUsers->clear();
|
||||
this->channel_.addMessage(builder.release());
|
||||
this->joinedUsersMergeQueued_ = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelChatters::addPartedUser(const QString &user)
|
||||
{
|
||||
auto partedUsers = this->partedUsers_.access();
|
||||
partedUsers->append(user);
|
||||
|
||||
if (!this->partedUsersMergeQueued_)
|
||||
{
|
||||
this->partedUsersMergeQueued_ = true;
|
||||
|
||||
QTimer::singleShot(500, &this->lifetimeGuard_, [this] {
|
||||
auto partedUsers = this->partedUsers_.access();
|
||||
|
||||
MessageBuilder builder(systemMessage,
|
||||
"Users parted: " + partedUsers->join(", "));
|
||||
builder->flags.set(MessageFlag::Collapsed);
|
||||
this->channel_.addMessage(builder.release());
|
||||
partedUsers->clear();
|
||||
|
||||
this->partedUsersMergeQueued_ = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
void ChannelChatters::setChatters(UsernameSet &&set)
|
||||
{
|
||||
*this->chatters_.access() = set;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Channel.hpp"
|
||||
#include "common/UniqueAccess.hpp"
|
||||
#include "common/UsernameSet.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class ChannelChatters
|
||||
{
|
||||
public:
|
||||
ChannelChatters(Channel &channel);
|
||||
virtual ~ChannelChatters() = default; // add vtable
|
||||
|
||||
AccessGuard<const UsernameSet> accessChatters() const;
|
||||
|
||||
void addRecentChatter(const QString &user);
|
||||
void addJoinedUser(const QString &user);
|
||||
void addPartedUser(const QString &user);
|
||||
void setChatters(UsernameSet &&set);
|
||||
|
||||
private:
|
||||
Channel &channel_;
|
||||
|
||||
// maps 2 char prefix to set of names
|
||||
UniqueAccess<UsernameSet> chatters_;
|
||||
|
||||
// combines multiple joins/parts into one message
|
||||
UniqueAccess<QStringList> joinedUsers_;
|
||||
bool joinedUsersMergeQueued_ = false;
|
||||
UniqueAccess<QStringList> partedUsers_;
|
||||
bool partedUsersMergeQueued_ = false;
|
||||
|
||||
QObject lifetimeGuard_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
#pragma once
|
||||
|
||||
#include "common/Channel.hpp"
|
||||
#include "common/UniqueAccess.hpp"
|
||||
#include "common/UsernameSet.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class ChannelChatters
|
||||
{
|
||||
public:
|
||||
ChannelChatters(Channel &channel);
|
||||
virtual ~ChannelChatters() = default; // add vtable
|
||||
|
||||
AccessGuard<const UsernameSet> accessChatters() const;
|
||||
|
||||
void addRecentChatter(const QString &user);
|
||||
void addJoinedUser(const QString &user);
|
||||
void addPartedUser(const QString &user);
|
||||
void setChatters(UsernameSet &&set);
|
||||
|
||||
private:
|
||||
Channel &channel_;
|
||||
|
||||
// maps 2 char prefix to set of names
|
||||
UniqueAccess<UsernameSet> chatters_;
|
||||
|
||||
// combines multiple joins/parts into one message
|
||||
UniqueAccess<QStringList> joinedUsers_;
|
||||
bool joinedUsersMergeQueued_ = false;
|
||||
UniqueAccess<QStringList> partedUsers_;
|
||||
bool partedUsersMergeQueued_ = false;
|
||||
|
||||
QObject lifetimeGuard_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
+235
-235
@@ -1,235 +1,235 @@
|
||||
#include "Credentials.hpp"
|
||||
|
||||
#include "debug/AssertInGuiThread.hpp"
|
||||
#include "keychain.h"
|
||||
#include "singletons/Paths.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "util/CombinePath.hpp"
|
||||
#include "util/Overloaded.hpp"
|
||||
|
||||
#include <QSaveFile>
|
||||
#include <boost/variant.hpp>
|
||||
|
||||
#define FORMAT_NAME \
|
||||
([&] { \
|
||||
assert(!provider.contains(":")); \
|
||||
return QString("chatterino:%1:%2").arg(provider).arg(name_); \
|
||||
})()
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
namespace {
|
||||
bool useKeyring()
|
||||
{
|
||||
if (getPaths()->isPortable())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
return getSettings()->useKeyring;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Insecure storage:
|
||||
QString insecurePath()
|
||||
{
|
||||
return combinePath(getPaths()->settingsDirectory, "credentials.json");
|
||||
}
|
||||
|
||||
QJsonDocument loadInsecure()
|
||||
{
|
||||
QFile file(insecurePath());
|
||||
file.open(QIODevice::ReadOnly);
|
||||
return QJsonDocument::fromJson(file.readAll());
|
||||
}
|
||||
|
||||
void storeInsecure(const QJsonDocument &doc)
|
||||
{
|
||||
QSaveFile file(insecurePath());
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write(doc.toJson());
|
||||
file.commit();
|
||||
}
|
||||
|
||||
QJsonDocument &insecureInstance()
|
||||
{
|
||||
static auto store = loadInsecure();
|
||||
return store;
|
||||
}
|
||||
|
||||
void queueInsecureSave()
|
||||
{
|
||||
static bool isQueued = false;
|
||||
|
||||
if (!isQueued)
|
||||
{
|
||||
isQueued = true;
|
||||
QTimer::singleShot(200, qApp, [] {
|
||||
storeInsecure(insecureInstance());
|
||||
isQueued = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// QKeychain runs jobs asyncronously, so we have to assure that set/erase
|
||||
// jobs gets executed in order.
|
||||
struct SetJob {
|
||||
QString name;
|
||||
QString credential;
|
||||
};
|
||||
|
||||
struct EraseJob {
|
||||
QString name;
|
||||
};
|
||||
|
||||
using Job = boost::variant<SetJob, EraseJob>;
|
||||
|
||||
static std::queue<Job> &jobQueue()
|
||||
{
|
||||
static std::queue<Job> jobs;
|
||||
return jobs;
|
||||
}
|
||||
|
||||
static void runNextJob()
|
||||
{
|
||||
auto &&queue = jobQueue();
|
||||
|
||||
if (!queue.empty())
|
||||
{
|
||||
// we were gonna use std::visit here but macos is shit
|
||||
|
||||
auto &&item = queue.front();
|
||||
|
||||
if (item.which() == 0) // set job
|
||||
{
|
||||
auto set = boost::get<SetJob>(item);
|
||||
auto job = new QKeychain::WritePasswordJob("chatterino");
|
||||
job->setAutoDelete(true);
|
||||
job->setKey(set.name);
|
||||
job->setTextData(set.credential);
|
||||
QObject::connect(job, &QKeychain::Job::finished, qApp,
|
||||
[](auto) { runNextJob(); });
|
||||
job->start();
|
||||
}
|
||||
else // erase job
|
||||
{
|
||||
auto erase = boost::get<EraseJob>(item);
|
||||
auto job = new QKeychain::DeletePasswordJob("chatterino");
|
||||
job->setAutoDelete(true);
|
||||
job->setKey(erase.name);
|
||||
QObject::connect(job, &QKeychain::Job::finished, qApp,
|
||||
[](auto) { runNextJob(); });
|
||||
job->start();
|
||||
}
|
||||
|
||||
queue.pop();
|
||||
}
|
||||
}
|
||||
|
||||
static void queueJob(Job &&job)
|
||||
{
|
||||
auto &&queue = jobQueue();
|
||||
|
||||
queue.push(std::move(job));
|
||||
if (queue.size() == 1)
|
||||
{
|
||||
runNextJob();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Credentials &Credentials::instance()
|
||||
{
|
||||
static Credentials creds;
|
||||
return creds;
|
||||
}
|
||||
|
||||
Credentials::Credentials()
|
||||
{
|
||||
}
|
||||
|
||||
void Credentials::get(const QString &provider, const QString &name_,
|
||||
QObject *receiver,
|
||||
std::function<void(const QString &)> &&onLoaded)
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
auto name = FORMAT_NAME;
|
||||
|
||||
if (useKeyring())
|
||||
{
|
||||
auto job = new QKeychain::ReadPasswordJob("chatterino");
|
||||
job->setAutoDelete(true);
|
||||
job->setKey(name);
|
||||
QObject::connect(
|
||||
job, &QKeychain::Job::finished, receiver,
|
||||
[job, onLoaded = std::move(onLoaded)](auto) mutable {
|
||||
onLoaded(job->textData());
|
||||
},
|
||||
Qt::DirectConnection);
|
||||
job->start();
|
||||
}
|
||||
else
|
||||
{
|
||||
auto &instance = insecureInstance();
|
||||
|
||||
onLoaded(instance.object().find(name).value().toString());
|
||||
}
|
||||
}
|
||||
|
||||
void Credentials::set(const QString &provider, const QString &name_,
|
||||
const QString &credential)
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
/// On linux, we try to use a keychain but show a message to disable it when it fails.
|
||||
/// XXX: add said message
|
||||
|
||||
auto name = FORMAT_NAME;
|
||||
|
||||
if (useKeyring())
|
||||
{
|
||||
queueJob(SetJob{name, credential});
|
||||
}
|
||||
else
|
||||
{
|
||||
auto &instance = insecureInstance();
|
||||
|
||||
auto obj = instance.object();
|
||||
obj[name] = credential;
|
||||
instance.setObject(obj);
|
||||
|
||||
queueInsecureSave();
|
||||
}
|
||||
}
|
||||
|
||||
void Credentials::erase(const QString &provider, const QString &name_)
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
auto name = FORMAT_NAME;
|
||||
|
||||
if (useKeyring())
|
||||
{
|
||||
queueJob(EraseJob{name});
|
||||
}
|
||||
else
|
||||
{
|
||||
auto &instance = insecureInstance();
|
||||
|
||||
if (auto it = instance.object().find(name);
|
||||
it != instance.object().end())
|
||||
{
|
||||
instance.object().erase(it);
|
||||
}
|
||||
|
||||
queueInsecureSave();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
#include "Credentials.hpp"
|
||||
|
||||
#include "debug/AssertInGuiThread.hpp"
|
||||
#include "keychain.h"
|
||||
#include "singletons/Paths.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "util/CombinePath.hpp"
|
||||
#include "util/Overloaded.hpp"
|
||||
|
||||
#include <QSaveFile>
|
||||
#include <boost/variant.hpp>
|
||||
|
||||
#define FORMAT_NAME \
|
||||
([&] { \
|
||||
assert(!provider.contains(":")); \
|
||||
return QString("chatterino:%1:%2").arg(provider).arg(name_); \
|
||||
})()
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
namespace {
|
||||
bool useKeyring()
|
||||
{
|
||||
if (getPaths()->isPortable())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
return getSettings()->useKeyring;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Insecure storage:
|
||||
QString insecurePath()
|
||||
{
|
||||
return combinePath(getPaths()->settingsDirectory, "credentials.json");
|
||||
}
|
||||
|
||||
QJsonDocument loadInsecure()
|
||||
{
|
||||
QFile file(insecurePath());
|
||||
file.open(QIODevice::ReadOnly);
|
||||
return QJsonDocument::fromJson(file.readAll());
|
||||
}
|
||||
|
||||
void storeInsecure(const QJsonDocument &doc)
|
||||
{
|
||||
QSaveFile file(insecurePath());
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write(doc.toJson());
|
||||
file.commit();
|
||||
}
|
||||
|
||||
QJsonDocument &insecureInstance()
|
||||
{
|
||||
static auto store = loadInsecure();
|
||||
return store;
|
||||
}
|
||||
|
||||
void queueInsecureSave()
|
||||
{
|
||||
static bool isQueued = false;
|
||||
|
||||
if (!isQueued)
|
||||
{
|
||||
isQueued = true;
|
||||
QTimer::singleShot(200, qApp, [] {
|
||||
storeInsecure(insecureInstance());
|
||||
isQueued = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// QKeychain runs jobs asyncronously, so we have to assure that set/erase
|
||||
// jobs gets executed in order.
|
||||
struct SetJob {
|
||||
QString name;
|
||||
QString credential;
|
||||
};
|
||||
|
||||
struct EraseJob {
|
||||
QString name;
|
||||
};
|
||||
|
||||
using Job = boost::variant<SetJob, EraseJob>;
|
||||
|
||||
static std::queue<Job> &jobQueue()
|
||||
{
|
||||
static std::queue<Job> jobs;
|
||||
return jobs;
|
||||
}
|
||||
|
||||
static void runNextJob()
|
||||
{
|
||||
auto &&queue = jobQueue();
|
||||
|
||||
if (!queue.empty())
|
||||
{
|
||||
// we were gonna use std::visit here but macos is shit
|
||||
|
||||
auto &&item = queue.front();
|
||||
|
||||
if (item.which() == 0) // set job
|
||||
{
|
||||
auto set = boost::get<SetJob>(item);
|
||||
auto job = new QKeychain::WritePasswordJob("chatterino");
|
||||
job->setAutoDelete(true);
|
||||
job->setKey(set.name);
|
||||
job->setTextData(set.credential);
|
||||
QObject::connect(job, &QKeychain::Job::finished, qApp,
|
||||
[](auto) { runNextJob(); });
|
||||
job->start();
|
||||
}
|
||||
else // erase job
|
||||
{
|
||||
auto erase = boost::get<EraseJob>(item);
|
||||
auto job = new QKeychain::DeletePasswordJob("chatterino");
|
||||
job->setAutoDelete(true);
|
||||
job->setKey(erase.name);
|
||||
QObject::connect(job, &QKeychain::Job::finished, qApp,
|
||||
[](auto) { runNextJob(); });
|
||||
job->start();
|
||||
}
|
||||
|
||||
queue.pop();
|
||||
}
|
||||
}
|
||||
|
||||
static void queueJob(Job &&job)
|
||||
{
|
||||
auto &&queue = jobQueue();
|
||||
|
||||
queue.push(std::move(job));
|
||||
if (queue.size() == 1)
|
||||
{
|
||||
runNextJob();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Credentials &Credentials::instance()
|
||||
{
|
||||
static Credentials creds;
|
||||
return creds;
|
||||
}
|
||||
|
||||
Credentials::Credentials()
|
||||
{
|
||||
}
|
||||
|
||||
void Credentials::get(const QString &provider, const QString &name_,
|
||||
QObject *receiver,
|
||||
std::function<void(const QString &)> &&onLoaded)
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
auto name = FORMAT_NAME;
|
||||
|
||||
if (useKeyring())
|
||||
{
|
||||
auto job = new QKeychain::ReadPasswordJob("chatterino");
|
||||
job->setAutoDelete(true);
|
||||
job->setKey(name);
|
||||
QObject::connect(
|
||||
job, &QKeychain::Job::finished, receiver,
|
||||
[job, onLoaded = std::move(onLoaded)](auto) mutable {
|
||||
onLoaded(job->textData());
|
||||
},
|
||||
Qt::DirectConnection);
|
||||
job->start();
|
||||
}
|
||||
else
|
||||
{
|
||||
auto &instance = insecureInstance();
|
||||
|
||||
onLoaded(instance.object().find(name).value().toString());
|
||||
}
|
||||
}
|
||||
|
||||
void Credentials::set(const QString &provider, const QString &name_,
|
||||
const QString &credential)
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
/// On linux, we try to use a keychain but show a message to disable it when it fails.
|
||||
/// XXX: add said message
|
||||
|
||||
auto name = FORMAT_NAME;
|
||||
|
||||
if (useKeyring())
|
||||
{
|
||||
queueJob(SetJob{name, credential});
|
||||
}
|
||||
else
|
||||
{
|
||||
auto &instance = insecureInstance();
|
||||
|
||||
auto obj = instance.object();
|
||||
obj[name] = credential;
|
||||
instance.setObject(obj);
|
||||
|
||||
queueInsecureSave();
|
||||
}
|
||||
}
|
||||
|
||||
void Credentials::erase(const QString &provider, const QString &name_)
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
auto name = FORMAT_NAME;
|
||||
|
||||
if (useKeyring())
|
||||
{
|
||||
queueJob(EraseJob{name});
|
||||
}
|
||||
else
|
||||
{
|
||||
auto &instance = insecureInstance();
|
||||
|
||||
if (auto it = instance.object().find(name);
|
||||
it != instance.object().end())
|
||||
{
|
||||
instance.object().erase(it);
|
||||
}
|
||||
|
||||
queueInsecureSave();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
+23
-23
@@ -1,23 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <functional>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Credentials
|
||||
{
|
||||
public:
|
||||
static Credentials &instance();
|
||||
|
||||
void get(const QString &provider, const QString &name, QObject *receiver,
|
||||
std::function<void(const QString &)> &&onLoaded);
|
||||
void set(const QString &provider, const QString &name,
|
||||
const QString &credential);
|
||||
void erase(const QString &provider, const QString &name);
|
||||
|
||||
private:
|
||||
Credentials();
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <functional>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Credentials
|
||||
{
|
||||
public:
|
||||
static Credentials &instance();
|
||||
|
||||
void get(const QString &provider, const QString &name, QObject *receiver,
|
||||
std::function<void(const QString &)> &&onLoaded);
|
||||
void set(const QString &provider, const QString &name,
|
||||
const QString &credential);
|
||||
void erase(const QString &provider, const QString &name);
|
||||
|
||||
private:
|
||||
Credentials();
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user