From a92c3dc2a47ec7869ec5de7c458dd295c16fe208 Mon Sep 17 00:00:00 2001 From: fourtf Date: Thu, 2 Feb 2017 23:51:02 +0100 Subject: [PATCH] fixed having the same chat open multiple times --- channel.cpp | 6 ------ channel.h | 7 ------- channels.cpp | 4 ++++ widgets/chatwidget.cpp | 35 ++++++++++++++++++++++++----------- widgets/chatwidget.h | 2 +- 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/channel.cpp b/channel.cpp index 75ad0364a..00f5a76c4 100644 --- a/channel.cpp +++ b/channel.cpp @@ -20,17 +20,11 @@ Channel::Channel(const QString &channel) : channel) , bttvChannelEmotes() , ffzChannelEmotes() - , messageMutex() , subLink("https://www.twitch.tv/" + name + "/subscribe?ref=in_chat_subscriber_link") , channelLink("https://twitch.tv/" + name) , popoutPlayerLink("https://player.twitch.tv/?channel=" + name) { - // for (int i = 0; i < 40; i++) { - // addMessage(std::shared_ptr( - // new messages::Message("test xD test"))); - // } - reloadChannelEmotes(); } diff --git a/channel.h b/channel.h index 24da99abe..a3a2d0405 100644 --- a/channel.h +++ b/channel.h @@ -46,12 +46,6 @@ public: return name.isEmpty(); } - const QMutex & - getMessageMutex() const - { - return messageMutex; - } - const QString & getName() const { @@ -125,7 +119,6 @@ private: ConcurrentMap bttvChannelEmotes; ConcurrentMap ffzChannelEmotes; - QMutex messageMutex; QString subLink; QString channelLink; diff --git a/channels.cpp b/channels.cpp index 1040c5854..f6fcda7ad 100644 --- a/channels.cpp +++ b/channels.cpp @@ -31,6 +31,10 @@ Channels::addChannel(const QString &channel) QString channelName = channel.toLower(); + if (channel.length() > 1 && channel.at(0) == '/') { + return getChannel(channel); + } + auto it = Channels::channels.find(channelName); if (it == Channels::channels.end()) { diff --git a/widgets/chatwidget.cpp b/widgets/chatwidget.cpp index 7a599092d..1c05fc20a 100644 --- a/widgets/chatwidget.cpp +++ b/widgets/chatwidget.cpp @@ -4,6 +4,7 @@ #include "settings.h" #include "widgets/textinputdialog.h" +#include #include #include #include @@ -47,18 +48,18 @@ ChatWidget::setChannelName(const QString &name) return; } + if (!this->channelName.isEmpty()) { + Channels::removeChannel(this->channelName); + + this->messageAppendedConnection.disconnect(); + this->messageRemovedConnection.disconnect(); + } + this->channelName = channel; this->header.updateChannelText(); this->view.layoutMessages(); - if (!this->channelName.isEmpty()) { - Channels::removeChannel(this->channelName); - - messageAppendedConnection.disconnect(); - messageRemovedConnection.disconnect(); - } - messages.clear(); if (channel.isEmpty()) { @@ -67,7 +68,7 @@ ChatWidget::setChannelName(const QString &name) } else { this->channel = Channels::addChannel(channel); - messageAppendedConnection = + this->messageAppendedConnection = this->channel.get()->messageAppended.connect([this]( std::shared_ptr &message) { @@ -75,14 +76,26 @@ ChatWidget::setChannelName(const QString &name) auto messageRef = new messages::MessageRef(message); + qDebug() << "xD"; + this->messages.appendItem( std::shared_ptr(messageRef), deleted); - }); - messageRemovedConnection = + this->messageRemovedConnection = this->channel.get()->messageRemovedFromStart.connect( - [this](std::shared_ptr &message) {}); + [this](std::shared_ptr &) {}); + + auto snapshot = this->channel.get()->getMessageSnapshot(); + + for (int i = 0; i < snapshot.getLength(); i++) { + std::shared_ptr deleted; + + auto messageRef = new messages::MessageRef(snapshot[i]); + + this->messages.appendItem( + std::shared_ptr(messageRef), deleted); + } } this->view.layoutMessages(); diff --git a/widgets/chatwidget.h b/widgets/chatwidget.h index 4f0734b55..9c568939a 100644 --- a/widgets/chatwidget.h +++ b/widgets/chatwidget.h @@ -56,7 +56,7 @@ public: } protected: - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent *) override; private: messages::LimitedQueue> messages;