mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
refactored TaggedUsers and Ping
This commit is contained in:
parent
df91ea44c4
commit
d0a81f3fe7
14 changed files with 131 additions and 161 deletions
|
@ -142,8 +142,8 @@ SOURCES += \
|
|||
src/controllers/moderationactions/ModerationActions.cpp \
|
||||
src/controllers/notifications/NotificationController.cpp \
|
||||
src/controllers/notifications/NotificationModel.cpp \
|
||||
src/controllers/pings/PingController.cpp \
|
||||
src/controllers/pings/PingModel.cpp \
|
||||
src/controllers/pings/MutedChannelController.cpp \
|
||||
src/controllers/pings/MutedChannelModel.cpp \
|
||||
src/controllers/taggedusers/TaggedUser.cpp \
|
||||
src/controllers/taggedusers/TaggedUsersController.cpp \
|
||||
src/controllers/taggedusers/TaggedUsersModel.cpp \
|
||||
|
@ -338,8 +338,8 @@ HEADERS += \
|
|||
src/controllers/moderationactions/ModerationActions.hpp \
|
||||
src/controllers/notifications/NotificationController.hpp \
|
||||
src/controllers/notifications/NotificationModel.hpp \
|
||||
src/controllers/pings/PingController.hpp \
|
||||
src/controllers/pings/PingModel.hpp \
|
||||
src/controllers/pings/MutedChannelController.hpp \
|
||||
src/controllers/pings/MutedChannelModel.hpp \
|
||||
src/controllers/taggedusers/TaggedUser.hpp \
|
||||
src/controllers/taggedusers/TaggedUsersController.hpp \
|
||||
src/controllers/taggedusers/TaggedUsersModel.hpp \
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "controllers/ignores/IgnoreController.hpp"
|
||||
#include "controllers/moderationactions/ModerationActions.hpp"
|
||||
#include "controllers/notifications/NotificationController.hpp"
|
||||
#include "controllers/pings/PingController.hpp"
|
||||
#include "controllers/pings/MutedChannelController.hpp"
|
||||
#include "controllers/taggedusers/TaggedUsersController.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
#include "providers/bttv/BttvEmotes.hpp"
|
||||
|
@ -56,7 +56,7 @@ Application::Application(Settings &_settings, Paths &_paths)
|
|||
, commands(&this->emplace<CommandController>())
|
||||
, highlights(&this->emplace<HighlightController>())
|
||||
, notifications(&this->emplace<NotificationController>())
|
||||
, pings(&this->emplace<PingController>())
|
||||
, pings(&this->emplace<MutedChannelController>())
|
||||
, ignores(&this->emplace<IgnoreController>())
|
||||
, taggedUsers(&this->emplace<TaggedUsersController>())
|
||||
, moderationActions(&this->emplace<ModerationActions>())
|
||||
|
|
|
@ -18,7 +18,7 @@ class TaggedUsersController;
|
|||
class AccountController;
|
||||
class ModerationActions;
|
||||
class NotificationController;
|
||||
class PingController;
|
||||
class MutedChannelController;
|
||||
|
||||
class Theme;
|
||||
class WindowManager;
|
||||
|
@ -60,7 +60,7 @@ public:
|
|||
CommandController *const commands{};
|
||||
HighlightController *const highlights{};
|
||||
NotificationController *const notifications{};
|
||||
PingController *const pings{};
|
||||
MutedChannelController *const pings{};
|
||||
IgnoreController *const ignores{};
|
||||
TaggedUsersController *const taggedUsers{};
|
||||
ModerationActions *const moderationActions{};
|
||||
|
|
57
src/controllers/pings/MutedChannelController.cpp
Normal file
57
src/controllers/pings/MutedChannelController.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include "controllers/pings/MutedChannelController.hpp"
|
||||
#include "controllers/pings/MutedChannelModel.hpp"
|
||||
#include "util/PersistSignalVector.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
void MutedChannelController::initialize(Settings &settings, Paths &paths)
|
||||
{
|
||||
this->initialized_ = true;
|
||||
|
||||
persist(this->channels, "/pings/muted");
|
||||
}
|
||||
|
||||
bool MutedChannelController::isMuted(const QString &channelName)
|
||||
{
|
||||
for (const auto &channel : this->channels)
|
||||
{
|
||||
if (channelName.toLower() == channel.toLower())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void MutedChannelController::mute(const QString &channelName)
|
||||
{
|
||||
channels.append(channelName);
|
||||
}
|
||||
|
||||
void MutedChannelController::unmute(const QString &channelName)
|
||||
{
|
||||
for (std::vector<int>::size_type i = 0; i != channels.raw().size(); i++)
|
||||
{
|
||||
if (channels.raw()[i].toLower() == channelName.toLower())
|
||||
{
|
||||
channels.removeAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool MutedChannelController::toggleMuted(const QString &channelName)
|
||||
{
|
||||
if (this->isMuted(channelName))
|
||||
{
|
||||
unmute(channelName);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
mute(channelName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
32
src/controllers/pings/MutedChannelController.hpp
Normal file
32
src/controllers/pings/MutedChannelController.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "common/SignalVector.hpp"
|
||||
#include "common/Singleton.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Settings;
|
||||
class Paths;
|
||||
|
||||
class MutedChannelModel;
|
||||
|
||||
class MutedChannelController final : public Singleton, private QObject
|
||||
{
|
||||
public:
|
||||
virtual void initialize(Settings &settings, Paths &paths) override;
|
||||
|
||||
bool isMuted(const QString &channelName);
|
||||
bool toggleMuted(const QString &channelName);
|
||||
|
||||
private:
|
||||
void mute(const QString &channelName);
|
||||
void unmute(const QString &channelName);
|
||||
bool initialized_ = false;
|
||||
|
||||
SignalVector<QString> channels;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
28
src/controllers/pings/MutedChannelModel.cpp
Normal file
28
src/controllers/pings/MutedChannelModel.cpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include "MutedChannelModel.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "util/StandardItemHelper.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
MutedChannelModel::MutedChannelModel(QObject *parent)
|
||||
: SignalVectorModel<QString>(1, parent)
|
||||
{
|
||||
}
|
||||
|
||||
// turn a vector item into a model row
|
||||
QString MutedChannelModel::getItemFromRow(std::vector<QStandardItem *> &row,
|
||||
const QString &original)
|
||||
{
|
||||
return QString(row[0]->data(Qt::DisplayRole).toString());
|
||||
}
|
||||
|
||||
// turn a model
|
||||
void MutedChannelModel::getRowFromItem(const QString &item,
|
||||
std::vector<QStandardItem *> &row)
|
||||
{
|
||||
setStringItem(row[0], item);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
|
@ -7,11 +7,11 @@
|
|||
|
||||
namespace chatterino {
|
||||
|
||||
class PingController;
|
||||
class MutedChannelController;
|
||||
|
||||
class PingModel : public SignalVectorModel<QString>
|
||||
class MutedChannelModel : public SignalVectorModel<QString>
|
||||
{
|
||||
explicit PingModel(QObject *parent);
|
||||
explicit MutedChannelModel(QObject *parent);
|
||||
|
||||
protected:
|
||||
// turn a vector item into a model row
|
||||
|
@ -21,8 +21,6 @@ protected:
|
|||
// turns a row in the model into a vector item
|
||||
virtual void getRowFromItem(const QString &item,
|
||||
std::vector<QStandardItem *> &row) override;
|
||||
|
||||
friend class PingController;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -1,70 +0,0 @@
|
|||
#include "controllers/pings/PingController.hpp"
|
||||
#include "controllers/pings/PingModel.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
void PingController::initialize(Settings &settings, Paths &paths)
|
||||
{
|
||||
this->initialized_ = true;
|
||||
for (const QString &channelName : this->pingSetting_.getValue())
|
||||
{
|
||||
this->channelVector.append(channelName);
|
||||
}
|
||||
|
||||
this->channelVector.delayedItemsChanged.connect([this] { //
|
||||
this->pingSetting_.setValue(this->channelVector.raw());
|
||||
});
|
||||
}
|
||||
|
||||
PingModel *PingController::createModel(QObject *parent)
|
||||
{
|
||||
PingModel *model = new PingModel(parent);
|
||||
model->initialize(&this->channelVector);
|
||||
return model;
|
||||
}
|
||||
|
||||
bool PingController::isMuted(const QString &channelName)
|
||||
{
|
||||
for (const auto &channel : this->channelVector)
|
||||
{
|
||||
if (channelName.toLower() == channel.toLower())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void PingController::muteChannel(const QString &channelName)
|
||||
{
|
||||
channelVector.append(channelName);
|
||||
}
|
||||
|
||||
void PingController::unmuteChannel(const QString &channelName)
|
||||
{
|
||||
for (std::vector<int>::size_type i = 0; i != channelVector.raw().size();
|
||||
i++)
|
||||
{
|
||||
if (channelVector.raw()[i].toLower() == channelName.toLower())
|
||||
{
|
||||
channelVector.removeAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool PingController::toggleMuteChannel(const QString &channelName)
|
||||
{
|
||||
if (this->isMuted(channelName))
|
||||
{
|
||||
unmuteChannel(channelName);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
muteChannel(channelName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
|
@ -1,36 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "common/SignalVector.hpp"
|
||||
#include "common/Singleton.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Settings;
|
||||
class Paths;
|
||||
|
||||
class PingModel;
|
||||
|
||||
class PingController final : public Singleton, private QObject
|
||||
{
|
||||
public:
|
||||
virtual void initialize(Settings &settings, Paths &paths) override;
|
||||
|
||||
bool isMuted(const QString &channelName);
|
||||
void muteChannel(const QString &channelName);
|
||||
void unmuteChannel(const QString &channelName);
|
||||
bool toggleMuteChannel(const QString &channelName);
|
||||
|
||||
PingModel *createModel(QObject *parent);
|
||||
|
||||
private:
|
||||
bool initialized_ = false;
|
||||
|
||||
SignalVector<QString> channelVector;
|
||||
|
||||
ChatterinoSetting<std::vector<QString>> pingSetting_ = {"/pings/muted"};
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -1,28 +0,0 @@
|
|||
#include "PingModel.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "util/StandardItemHelper.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
PingModel::PingModel(QObject *parent)
|
||||
: SignalVectorModel<QString>(1, parent)
|
||||
{
|
||||
}
|
||||
|
||||
// turn a vector item into a model row
|
||||
QString PingModel::getItemFromRow(std::vector<QStandardItem *> &row,
|
||||
const QString &original)
|
||||
{
|
||||
return QString(row[0]->data(Qt::DisplayRole).toString());
|
||||
}
|
||||
|
||||
// turn a model
|
||||
void PingModel::getRowFromItem(const QString &item,
|
||||
std::vector<QStandardItem *> &row)
|
||||
{
|
||||
setStringItem(row[0], item);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
|
@ -9,12 +9,4 @@ TaggedUsersController::TaggedUsersController()
|
|||
{
|
||||
}
|
||||
|
||||
TaggedUsersModel *TaggedUsersController::createModel(QObject *parent)
|
||||
{
|
||||
TaggedUsersModel *model = new TaggedUsersModel(parent);
|
||||
model->initialize(&this->users);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -15,8 +15,6 @@ public:
|
|||
TaggedUsersController();
|
||||
|
||||
SignalVector<TaggedUser> users;
|
||||
|
||||
TaggedUsersModel *createModel(QObject *parent = nullptr);
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "controllers/highlights/HighlightController.hpp"
|
||||
#include "controllers/ignores/IgnoreController.hpp"
|
||||
#include "controllers/pings/PingController.hpp"
|
||||
#include "controllers/pings/MutedChannelController.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "providers/chatterino/ChatterinoBadges.hpp"
|
||||
#include "providers/twitch/TwitchBadges.hpp"
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "controllers/moderationactions/ModerationActions.hpp"
|
||||
#include "controllers/notifications/NotificationController.hpp"
|
||||
#include "controllers/pings/PingController.hpp"
|
||||
#include "controllers/pings/MutedChannelController.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||
#include "singletons/Resources.hpp"
|
||||
|
@ -343,8 +343,7 @@ std::unique_ptr<QMenu> SplitHeader::createMainMenu()
|
|||
this->split_->getChannel()->getName()));
|
||||
});
|
||||
action->connect(action, &QAction::triggered, this, [this]() {
|
||||
getApp()->pings->toggleMuteChannel(
|
||||
this->split_->getChannel()->getName());
|
||||
getApp()->pings->toggleMuted(this->split_->getChannel()->getName());
|
||||
});
|
||||
|
||||
moreMenu->addAction(action);
|
||||
|
|
Loading…
Reference in a new issue