Added the ability to add nicknames for users (#2981)
Co-authored-by: Mm2PL <mm2pl+gh@kotmisia.pl> Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
|
||||
#include "util/RapidJsonSerializeQString.hpp"
|
||||
#include "util/RapidjsonHelpers.hpp"
|
||||
|
||||
#include <QString>
|
||||
#include <pajlada/serialize.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Nickname
|
||||
{
|
||||
public:
|
||||
Nickname(const QString &name, const QString &replace)
|
||||
: name_(name)
|
||||
, replace_(replace)
|
||||
{
|
||||
}
|
||||
|
||||
const QString &name() const
|
||||
{
|
||||
return this->name_;
|
||||
}
|
||||
const QString &replace() const
|
||||
{
|
||||
return this->replace_;
|
||||
}
|
||||
|
||||
private:
|
||||
QString name_;
|
||||
QString replace_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
namespace pajlada {
|
||||
|
||||
template <>
|
||||
struct Serialize<chatterino::Nickname> {
|
||||
static rapidjson::Value get(const chatterino::Nickname &value,
|
||||
rapidjson::Document::AllocatorType &a)
|
||||
{
|
||||
rapidjson::Value ret(rapidjson::kObjectType);
|
||||
|
||||
chatterino::rj::set(ret, "name", value.name(), a);
|
||||
chatterino::rj::set(ret, "replace", value.replace(), a);
|
||||
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Deserialize<chatterino::Nickname> {
|
||||
static chatterino::Nickname get(const rapidjson::Value &value,
|
||||
bool *error = nullptr)
|
||||
{
|
||||
if (!value.IsObject())
|
||||
{
|
||||
PAJLADA_REPORT_ERROR(error)
|
||||
return chatterino::Nickname(QString(), QString());
|
||||
}
|
||||
|
||||
QString _name;
|
||||
QString _replace;
|
||||
|
||||
chatterino::rj::getSafe(value, "name", _name);
|
||||
chatterino::rj::getSafe(value, "replace", _replace);
|
||||
|
||||
return chatterino::Nickname(_name, _replace);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace pajlada
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "NicknamesModel.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "providers/twitch/api/Helix.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "util/StandardItemHelper.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
NicknamesModel::NicknamesModel(QObject *parent)
|
||||
: SignalVectorModel<Nickname>(2, parent)
|
||||
{
|
||||
}
|
||||
|
||||
// turn a vector item into a model row
|
||||
Nickname NicknamesModel::getItemFromRow(std::vector<QStandardItem *> &row,
|
||||
const Nickname &original)
|
||||
{
|
||||
return Nickname{row[0]->data(Qt::DisplayRole).toString(),
|
||||
row[1]->data(Qt::DisplayRole).toString()};
|
||||
}
|
||||
|
||||
// turns a row in the model into a vector item
|
||||
void NicknamesModel::getRowFromItem(const Nickname &item,
|
||||
std::vector<QStandardItem *> &row)
|
||||
{
|
||||
setStringItem(row[0], item.name());
|
||||
setStringItem(row[1], item.replace());
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "common/SignalVectorModel.hpp"
|
||||
#include "controllers/nicknames/Nickname.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class NicknamesModel : public SignalVectorModel<Nickname>
|
||||
{
|
||||
public:
|
||||
explicit NicknamesModel(QObject *parent);
|
||||
|
||||
protected:
|
||||
// turn a vector item into a model row
|
||||
virtual Nickname getItemFromRow(std::vector<QStandardItem *> &row,
|
||||
const Nickname &original) override;
|
||||
|
||||
// turns a row in the model into a vector item
|
||||
virtual void getRowFromItem(const Nickname &item,
|
||||
std::vector<QStandardItem *> &row) override;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
Reference in New Issue
Block a user