Fixes #210 aallow duplicate messages behaves weird

This commit is contained in:
fourtf 2018-01-22 15:24:39 +01:00
parent d966c24bc3
commit 9d8edc4ae0
4 changed files with 18 additions and 11 deletions

View file

@ -34,9 +34,6 @@ IrcManager::IrcManager(ChannelManager &_channelManager, ResourceManager &_resour
, resources(_resources) , resources(_resources)
, accountManager(_accountManager) , accountManager(_accountManager)
{ {
this->messageSuffix.append(' ');
this->messageSuffix.append(QChar(0x206D));
this->account = accountManager.Twitch.getCurrent(); this->account = accountManager.Twitch.getCurrent();
accountManager.Twitch.userChanged.connect([this]() { accountManager.Twitch.userChanged.connect([this]() {
this->setUser(accountManager.Twitch.getCurrent()); this->setUser(accountManager.Twitch.getCurrent());
@ -208,12 +205,8 @@ 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 (singletons::SettingManager::getInstance().allowDuplicateMessages && (++i % 2) == 0) {
trimmedMessage.append(this->messageSuffix);
}
this->writeConnection->sendRaw("PRIVMSG #" + channelName + " :" + trimmedMessage); this->writeConnection->sendRaw("PRIVMSG #" + channelName + " :" + trimmedMessage);
} }

View file

@ -89,9 +89,6 @@ private:
void onConnected(); void onConnected();
void onDisconnected(); void onDisconnected();
private:
QByteArray messageSuffix;
}; };
} // namespace singletons } // namespace singletons

View file

@ -41,6 +41,9 @@ TwitchChannel::TwitchChannel(const QString &channelName)
this->connectedConnection = singletons::IrcManager::getInstance().connected.connect( this->connectedConnection = singletons::IrcManager::getInstance().connected.connect(
[this] { this->userStateChanged(); }); [this] { this->userStateChanged(); });
this->messageSuffix.append(' ');
this->messageSuffix.append(QChar(0x206D));
} }
TwitchChannel::~TwitchChannel() TwitchChannel::~TwitchChannel()
@ -87,6 +90,19 @@ void TwitchChannel::sendMessage(const QString &message)
// Do last message processing // Do last message processing
QString parsedMessage = emoteManager.replaceShortCodes(message); QString parsedMessage = emoteManager.replaceShortCodes(message);
parsedMessage = parsedMessage.trimmed();
if (parsedMessage.isEmpty())
return;
if (singletons::SettingManager::getInstance().allowDuplicateMessages) {
if (parsedMessage == this->lastSentMessage) {
parsedMessage.append(this->messageSuffix);
this->lastSentMessage = "";
}
}
singletons::IrcManager::getInstance().sendMessage(this->name, parsedMessage); singletons::IrcManager::getInstance().sendMessage(this->name, parsedMessage);
} }
@ -228,6 +244,5 @@ void TwitchChannel::fetchRecentMessages()
} }
}); });
} }
} // namespace twitch } // namespace twitch
} // namespace chatterino } // namespace chatterino

View file

@ -57,6 +57,8 @@ private:
boost::signals2::connection connectedConnection; boost::signals2::connection connectedConnection;
bool mod; bool mod;
QByteArray messageSuffix;
QString lastSentMessage;
}; };
} // namespace twitch } // namespace twitch