fixed having the same chat open multiple times

This commit is contained in:
fourtf 2017-02-02 23:51:02 +01:00
parent c6c90d9f50
commit a92c3dc2a4
5 changed files with 29 additions and 25 deletions

View file

@ -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<messages::Message>(
// new messages::Message("test xD test")));
// }
reloadChannelEmotes();
}

View file

@ -46,12 +46,6 @@ public:
return name.isEmpty();
}
const QMutex &
getMessageMutex() const
{
return messageMutex;
}
const QString &
getName() const
{
@ -125,7 +119,6 @@ private:
ConcurrentMap<QString, messages::LazyLoadedImage *> bttvChannelEmotes;
ConcurrentMap<QString, messages::LazyLoadedImage *> ffzChannelEmotes;
QMutex messageMutex;
QString subLink;
QString channelLink;

View file

@ -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()) {

View file

@ -4,6 +4,7 @@
#include "settings.h"
#include "widgets/textinputdialog.h"
#include <QDebug>
#include <QFont>
#include <QFontDatabase>
#include <QPainter>
@ -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<messages::Message> &message) {
@ -75,14 +76,26 @@ ChatWidget::setChannelName(const QString &name)
auto messageRef = new messages::MessageRef(message);
qDebug() << "xD";
this->messages.appendItem(
std::shared_ptr<messages::MessageRef>(messageRef), deleted);
});
messageRemovedConnection =
this->messageRemovedConnection =
this->channel.get()->messageRemovedFromStart.connect(
[this](std::shared_ptr<messages::Message> &message) {});
[this](std::shared_ptr<messages::Message> &) {});
auto snapshot = this->channel.get()->getMessageSnapshot();
for (int i = 0; i < snapshot.getLength(); i++) {
std::shared_ptr<messages::MessageRef> deleted;
auto messageRef = new messages::MessageRef(snapshot[i]);
this->messages.appendItem(
std::shared_ptr<messages::MessageRef>(messageRef), deleted);
}
}
this->view.layoutMessages();

View file

@ -56,7 +56,7 @@ public:
}
protected:
void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
void paintEvent(QPaintEvent *) override;
private:
messages::LimitedQueue<std::shared_ptr<messages::MessageRef>> messages;