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)
, accountManager(_accountManager)
{
this->messageSuffix.append(' ');
this->messageSuffix.append(QChar(0x206D));
this->account = accountManager.Twitch.getCurrent();
accountManager.Twitch.userChanged.connect([this]() {
this->setUser(accountManager.Twitch.getCurrent());
@ -208,12 +205,8 @@ void IrcManager::sendMessage(const QString &channelName, QString message)
}
this->connectionMutex.lock();
static int i = 0;
if (this->writeConnection) {
if (singletons::SettingManager::getInstance().allowDuplicateMessages && (++i % 2) == 0) {
trimmedMessage.append(this->messageSuffix);
}
this->writeConnection->sendRaw("PRIVMSG #" + channelName + " :" + trimmedMessage);
}

View file

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

View file

@ -41,6 +41,9 @@ TwitchChannel::TwitchChannel(const QString &channelName)
this->connectedConnection = singletons::IrcManager::getInstance().connected.connect(
[this] { this->userStateChanged(); });
this->messageSuffix.append(' ');
this->messageSuffix.append(QChar(0x206D));
}
TwitchChannel::~TwitchChannel()
@ -87,6 +90,19 @@ void TwitchChannel::sendMessage(const QString &message)
// Do last message processing
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);
}
@ -228,6 +244,5 @@ void TwitchChannel::fetchRecentMessages()
}
});
}
} // namespace twitch
} // namespace chatterino

View file

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