Add feature to select channels to log (#4302)

* Add checkbox for custom logging and table with channels to log on Logs page

* Add checkbox to enable and disable logging per channel

* Return from addMessage before logging if custom logging enabled and channel does not have logging enabled

* Use clang-format to fix formatting

* Add CHANGELOG.md entry

* Resolve PR comments

* Remove toggle for channels so any channel listed will be logged

* Move Only log channels listed below checkbox to just above table

* Fix formatting

* Re-order changelog

* ChannelLog constructor: Copy & move instead of const ref & copy

* ChannelLog::createEmpty: Curly brace initialize instead of repeating
name

* ChannelLog toString & createEmpty: nodiscard

* Use COUNT paradigm in model column

* Remove ChanneLoggingModel source file comments

* Use Column::Channel in getRowFromItem

* Rename `getItemFromRow` parameter and mark it as unused

* Curly brace initialize ChannelLog

* private & friend class the model

* Filter out channels to log using a set instead of iterating over a vector every time a message comes in

* Rename `ChannelLog::channel` member to `ChannelLog::channelName`

Also made it private

* mini comment on ChannelLog

Co-authored-by: Felanbird <41973452+Felanbird@users.noreply.github.com>
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
askepticaldreamer
2023-01-15 03:47:22 -08:00
committed by GitHub
parent a567cc5ae7
commit 4c782ce90c
11 changed files with 225 additions and 6 deletions
+25
View File
@@ -0,0 +1,25 @@
#include "controllers/logging/ChannelLog.hpp"
namespace chatterino {
ChannelLog::ChannelLog(QString channelName)
: channelName_(std::move(channelName))
{
}
QString ChannelLog::channelName() const
{
return this->channelName_;
}
QString ChannelLog::toString() const
{
return this->channelName_;
}
ChannelLog ChannelLog::createEmpty()
{
return {""};
}
} // namespace chatterino
+69
View File
@@ -0,0 +1,69 @@
#pragma once
#include "util/RapidjsonHelpers.hpp"
#include <pajlada/serialize.hpp>
#include <QString>
namespace chatterino {
/**
* @brief Contains the description of a channel that will be logged
**/
class ChannelLog
{
QString channelName_;
public:
ChannelLog(QString channelName);
bool operator==(const ChannelLog &other) const;
[[nodiscard]] QString channelName() const;
[[nodiscard]] QString toString() const;
[[nodiscard]] static ChannelLog createEmpty();
};
} // namespace chatterino
namespace pajlada {
template <>
struct Serialize<chatterino::ChannelLog> {
static rapidjson::Value get(const chatterino::ChannelLog &value,
rapidjson::Document::AllocatorType &a)
{
rapidjson::Value ret(rapidjson::kObjectType);
chatterino::rj::set(ret, "channelName", value.channelName(), a);
return ret;
}
};
template <>
struct Deserialize<chatterino::ChannelLog> {
static chatterino::ChannelLog get(const rapidjson::Value &value,
bool *error = nullptr)
{
if (!value.IsObject())
{
PAJLADA_REPORT_ERROR(error);
return chatterino::ChannelLog::createEmpty();
}
QString channelName;
if (!chatterino::rj::getSafe(value, "channelName", channelName))
{
PAJLADA_REPORT_ERROR(error);
return chatterino::ChannelLog::createEmpty();
}
return {channelName};
}
};
} // namespace pajlada
@@ -0,0 +1,25 @@
#include "controllers/logging/ChannelLoggingModel.hpp"
#include "util/StandardItemHelper.hpp"
namespace chatterino {
ChannelLoggingModel ::ChannelLoggingModel(QObject *parent)
: SignalVectorModel<ChannelLog>(Column::COUNT, parent)
{
}
ChannelLog ChannelLoggingModel::getItemFromRow(
std::vector<QStandardItem *> &row, const ChannelLog & /*original*/)
{
auto channelName = row[Column::Channel]->data(Qt::DisplayRole).toString();
return {channelName};
}
void ChannelLoggingModel::getRowFromItem(const ChannelLog &item,
std::vector<QStandardItem *> &row)
{
setStringItem(row[Column::Channel], item.channelName());
}
} // namespace chatterino
@@ -0,0 +1,31 @@
#pragma once
#include "common/SignalVectorModel.hpp"
#include "controllers/logging/ChannelLog.hpp"
#include <QObject>
namespace chatterino {
class ChannelLoggingModel : public SignalVectorModel<ChannelLog>
{
explicit ChannelLoggingModel(QObject *parent);
enum Column {
Channel,
COUNT,
};
protected:
// turn a vector item into a model row
ChannelLog getItemFromRow(std::vector<QStandardItem *> &row,
const ChannelLog &original) override;
// turns a row in the model into a vector item
void getRowFromItem(const ChannelLog &item,
std::vector<QStandardItem *> &row) override;
friend class ModerationPage;
};
} // namespace chatterino