Implement duplicate message sending setting

Fixes #142
This commit is contained in:
Rasmus Karlsson 2017-12-17 15:34:07 +01:00
parent c7feec20d8
commit d182c22a4e
2 changed files with 13 additions and 2 deletions

View file

@ -6,6 +6,7 @@
#include "debug/log.hpp" #include "debug/log.hpp"
#include "emotemanager.hpp" #include "emotemanager.hpp"
#include "messages/messageparseargs.hpp" #include "messages/messageparseargs.hpp"
#include "settingsmanager.hpp"
#include "twitch/twitchmessagebuilder.hpp" #include "twitch/twitchmessagebuilder.hpp"
#include "twitch/twitchparsemessage.hpp" #include "twitch/twitchparsemessage.hpp"
#include "twitch/twitchuser.hpp" #include "twitch/twitchuser.hpp"
@ -31,6 +32,9 @@ IrcManager::IrcManager(ChannelManager &_channelManager, Resources &_resources,
, resources(_resources) , resources(_resources)
, windowManager(_windowManager) , windowManager(_windowManager)
{ {
this->messageSuffix.append(' ');
this->messageSuffix.append(QChar(0x206D));
AccountManager::getInstance().Twitch.userChanged.connect([this]() { AccountManager::getInstance().Twitch.userChanged.connect([this]() {
this->setUser(AccountManager::getInstance().Twitch.getCurrent()); this->setUser(AccountManager::getInstance().Twitch.getCurrent());
@ -177,11 +181,15 @@ void IrcManager::disconnect()
this->writeConnection->close(); this->writeConnection->close();
} }
void IrcManager::sendMessage(const QString &channelName, const QString &message) void IrcManager::sendMessage(const QString &channelName, QString message)
{ {
this->connectionMutex.lock(); this->connectionMutex.lock();
static int i = 0;
if (this->writeConnection) { if (this->writeConnection) {
if (SettingsManager::getInstance().allowDuplicateMessages && (++i % 2) == 0) {
message.append(this->messageSuffix);
}
this->writeConnection->sendRaw("PRIVMSG #" + channelName + " :" + message); this->writeConnection->sendRaw("PRIVMSG #" + channelName + " :" + message);
} }

View file

@ -38,7 +38,7 @@ public:
bool tryRemoveIgnoredUser(QString const &username, QString &errorMessage); bool tryRemoveIgnoredUser(QString const &username, QString &errorMessage);
void removeIgnoredUser(QString const &username); void removeIgnoredUser(QString const &username);
void sendMessage(const QString &channelName, const QString &message); void sendMessage(const QString &channelName, QString message);
void joinChannel(const QString &channelName); void joinChannel(const QString &channelName);
void partChannel(const QString &channelName); void partChannel(const QString &channelName);
@ -89,6 +89,9 @@ private:
void onConnected(); void onConnected();
void onDisconnected(); void onDisconnected();
private:
QByteArray messageSuffix;
}; };
} // namespace chatterino } // namespace chatterino