From db41044daf7ec4ab20c083b77566d2bf7321f5ee Mon Sep 17 00:00:00 2001 From: fourtf Date: Wed, 17 Jan 2018 03:10:21 +0100 Subject: [PATCH] Fixed #216 bundles connected and disconnected --- src/messages/message.hpp | 3 ++- src/singletons/ircmanager.cpp | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/messages/message.hpp b/src/messages/message.hpp index 902980cf0..881b406f8 100644 --- a/src/messages/message.hpp +++ b/src/messages/message.hpp @@ -14,7 +14,7 @@ namespace messages { class Message; typedef std::shared_ptr MessagePtr; -typedef uint8_t MessageFlagsType; +typedef uint16_t MessageFlagsType; class Message { @@ -29,6 +29,7 @@ public: Disabled = (1 << 5), DisableCompactEmotes = (1 << 6), Collapsed = (1 << 7), + DisconnectedMessage = (1 << 8), }; // Elements diff --git a/src/singletons/ircmanager.cpp b/src/singletons/ircmanager.cpp index 1ef61f266..f76d94ef6 100644 --- a/src/singletons/ircmanager.cpp +++ b/src/singletons/ircmanager.cpp @@ -382,9 +382,20 @@ void IrcManager::removeIgnoredUser(QString const &username) void IrcManager::onConnected() { MessagePtr msg = Message::createSystemMessage("connected to chat"); + MessagePtr remsg = Message::createSystemMessage("reconnected to chat"); - this->channelManager.doOnAll([msg](SharedChannel channel) { + this->channelManager.doOnAll([msg, remsg](SharedChannel channel) { assert(channel); + + LimitedQueueSnapshot snapshot = channel->getMessageSnapshot(); + + if (snapshot.getLength() > 0 && + snapshot[snapshot.getLength() - 1]->hasFlags(Message::DisconnectedMessage)) // + { + channel->replaceMessage(snapshot[snapshot.getLength() - 1], remsg); + return; + } + channel->addMessage(msg); }); } @@ -392,6 +403,7 @@ void IrcManager::onConnected() void IrcManager::onDisconnected() { MessagePtr msg = Message::createSystemMessage("disconnected from chat"); + msg->addFlags(Message::DisconnectedMessage); this->channelManager.doOnAll([msg](SharedChannel channel) { assert(channel); @@ -404,12 +416,11 @@ Communi::IrcConnection *IrcManager::getReadConnection() return this->readConnection.get(); } -void -IrcManager::addFakeMessage(const QString &data) +void IrcManager::addFakeMessage(const QString &data) { auto fakeMessage = Communi::IrcMessage::fromData(data.toUtf8(), this->readConnection.get()); - this->privateMessageReceived(qobject_cast(fakeMessage)); + this->privateMessageReceived(qobject_cast(fakeMessage)); } } // namespace singletons