Adds option to mute ping sound for specific channels (#990)

Co-Authored-By: hemirt <hemirt@hemirt.com>
This commit is contained in:
hemirt 2019-05-10 22:36:37 +02:00 committed by pajlada
parent 9654650bee
commit c43c1dc207
9 changed files with 195 additions and 3 deletions

View file

@ -198,6 +198,8 @@ SOURCES += \
src/widgets/splits/SplitOverlay.cpp \ src/widgets/splits/SplitOverlay.cpp \
src/widgets/StreamView.cpp \ src/widgets/StreamView.cpp \
src/widgets/Window.cpp \ src/widgets/Window.cpp \
src/controllers/pings/PingController.cpp \
src/controllers/pings/PingModel.cpp \
HEADERS += \ HEADERS += \
src/Application.hpp \ src/Application.hpp \
@ -382,6 +384,8 @@ HEADERS += \
src/widgets/splits/SplitOverlay.hpp \ src/widgets/splits/SplitOverlay.hpp \
src/widgets/StreamView.hpp \ src/widgets/StreamView.hpp \
src/widgets/Window.hpp \ src/widgets/Window.hpp \
src/controllers/pings/PingController.hpp \
src/controllers/pings/PingModel.hpp \
RESOURCES += \ RESOURCES += \
resources/resources.qrc \ resources/resources.qrc \

View file

@ -6,6 +6,7 @@
#include "controllers/ignores/IgnoreController.hpp" #include "controllers/ignores/IgnoreController.hpp"
#include "controllers/moderationactions/ModerationActions.hpp" #include "controllers/moderationactions/ModerationActions.hpp"
#include "controllers/notifications/NotificationController.hpp" #include "controllers/notifications/NotificationController.hpp"
#include "controllers/pings/PingController.hpp"
#include "controllers/taggedusers/TaggedUsersController.hpp" #include "controllers/taggedusers/TaggedUsersController.hpp"
#include "debug/Log.hpp" #include "debug/Log.hpp"
#include "messages/MessageBuilder.hpp" #include "messages/MessageBuilder.hpp"
@ -53,6 +54,7 @@ Application::Application(Settings &_settings, Paths &_paths)
, commands(&this->emplace<CommandController>()) , commands(&this->emplace<CommandController>())
, highlights(&this->emplace<HighlightController>()) , highlights(&this->emplace<HighlightController>())
, notifications(&this->emplace<NotificationController>()) , notifications(&this->emplace<NotificationController>())
, pings(&this->emplace<PingController>())
, ignores(&this->emplace<IgnoreController>()) , ignores(&this->emplace<IgnoreController>())
, taggedUsers(&this->emplace<TaggedUsersController>()) , taggedUsers(&this->emplace<TaggedUsersController>())
, moderationActions(&this->emplace<ModerationActions>()) , moderationActions(&this->emplace<ModerationActions>())

View file

@ -18,6 +18,7 @@ class TaggedUsersController;
class AccountController; class AccountController;
class ModerationActions; class ModerationActions;
class NotificationController; class NotificationController;
class PingController;
class Theme; class Theme;
class WindowManager; class WindowManager;
@ -62,6 +63,7 @@ public:
CommandController *const commands{}; CommandController *const commands{};
HighlightController *const highlights{}; HighlightController *const highlights{};
NotificationController *const notifications{}; NotificationController *const notifications{};
PingController *const pings{};
IgnoreController *const ignores{}; IgnoreController *const ignores{};
TaggedUsersController *const taggedUsers{}; TaggedUsersController *const taggedUsers{};
ModerationActions *const moderationActions{}; ModerationActions *const moderationActions{};

View file

@ -0,0 +1,70 @@
#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.appendItem(channelName);
}
this->channelVector.delayedItemsChanged.connect([this] { //
this->pingSetting_.setValue(this->channelVector.getVector());
});
}
PingModel *PingController::createModel(QObject *parent)
{
PingModel *model = new PingModel(parent);
model->init(&this->channelVector);
return model;
}
bool PingController::isMuted(const QString &channelName)
{
for (const auto &channel : this->channelVector.getVector())
{
if (channelName.toLower() == channel.toLower())
{
return true;
}
}
return false;
}
void PingController::muteChannel(const QString &channelName)
{
channelVector.appendItem(channelName);
}
void PingController::unmuteChannel(const QString &channelName)
{
for (std::vector<int>::size_type i = 0;
i != channelVector.getVector().size(); i++)
{
if (channelVector.getVector()[i].toLower() == channelName.toLower())
{
channelVector.removeItem(i);
i--;
}
}
}
bool PingController::toggleMuteChannel(const QString &channelName)
{
if (this->isMuted(channelName))
{
unmuteChannel(channelName);
return false;
}
else
{
muteChannel(channelName);
return true;
}
}
} // namespace chatterino

View file

@ -0,0 +1,36 @@
#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;
UnsortedSignalVector<QString> channelVector;
ChatterinoSetting<std::vector<QString>> pingSetting_ = {"/pings/muted"};
};
} // namespace chatterino

View file

@ -0,0 +1,28 @@
#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

View file

@ -0,0 +1,28 @@
#pragma once
#include <QObject>
#include "common/SignalVectorModel.hpp"
#include "controllers/notifications/NotificationController.hpp"
namespace chatterino {
class PingController;
class PingModel : public SignalVectorModel<QString>
{
explicit PingModel(QObject *parent);
protected:
// turn a vector item into a model row
virtual QString getItemFromRow(std::vector<QStandardItem *> &row,
const QString &original) override;
// 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

View file

@ -4,6 +4,7 @@
#include "controllers/accounts/AccountController.hpp" #include "controllers/accounts/AccountController.hpp"
#include "controllers/highlights/HighlightController.hpp" #include "controllers/highlights/HighlightController.hpp"
#include "controllers/ignores/IgnoreController.hpp" #include "controllers/ignores/IgnoreController.hpp"
#include "controllers/pings/PingController.hpp"
#include "debug/Log.hpp" #include "debug/Log.hpp"
#include "messages/Message.hpp" #include "messages/Message.hpp"
#include "providers/chatterino/ChatterinoBadges.hpp" #include "providers/chatterino/ChatterinoBadges.hpp"
@ -885,13 +886,16 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg)
if (!isPastMsg) if (!isPastMsg)
{ {
if (playSound && bool notMuted = !getApp()->pings->isMuted(this->channel->getName());
(!hasFocus || getSettings()->highlightAlwaysPlaySound)) bool resolveFocus =
!hasFocus || getSettings()->highlightAlwaysPlaySound;
if (playSound && notMuted && resolveFocus)
{ {
player->play(); player->play();
} }
if (doAlert) if (doAlert && notMuted)
{ {
getApp()->windows->sendAlert(); getApp()->windows->sendAlert();
} }

View file

@ -4,6 +4,7 @@
#include "controllers/accounts/AccountController.hpp" #include "controllers/accounts/AccountController.hpp"
#include "controllers/moderationactions/ModerationActions.hpp" #include "controllers/moderationactions/ModerationActions.hpp"
#include "controllers/notifications/NotificationController.hpp" #include "controllers/notifications/NotificationController.hpp"
#include "controllers/pings/PingController.hpp"
#include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchServer.hpp" #include "providers/twitch/TwitchServer.hpp"
#include "singletons/Resources.hpp" #include "singletons/Resources.hpp"
@ -297,6 +298,23 @@ std::unique_ptr<QMenu> SplitHeader::createMainMenu()
moreMenu->addAction(action); moreMenu->addAction(action);
{
auto action = new QAction(this);
action->setText("Mute highlight sound");
action->setCheckable(true);
QObject::connect(moreMenu, &QMenu::aboutToShow, this, [action, this]() {
action->setChecked(getApp()->pings->isMuted(
this->split_->getChannel()->getName()));
});
action->connect(action, &QAction::triggered, this, [this]() {
getApp()->pings->toggleMuteChannel(
this->split_->getChannel()->getName());
});
moreMenu->addAction(action);
}
moreMenu->addSeparator(); moreMenu->addSeparator();
moreMenu->addAction("Reconnect", this, SLOT(reconnect())); moreMenu->addAction("Reconnect", this, SLOT(reconnect()));
moreMenu->addAction("Reload channel emotes", this, moreMenu->addAction("Reload channel emotes", this,