2017-01-01 13:07:36 +01:00
|
|
|
#include "channel.h"
|
2017-01-05 16:07:20 +01:00
|
|
|
#include "message.h"
|
2017-01-01 13:07:36 +01:00
|
|
|
|
2017-01-11 01:08:20 +01:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
Channel Channel::whispers(QString("/whispers"));
|
|
|
|
Channel Channel::mentions(QString("/mentions"));
|
2017-01-01 13:07:36 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
QMap<QString, Channel *> Channel::channels = QMap<QString, Channel *>();
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-01-01 13:07:36 +01:00
|
|
|
Channel::Channel(QString channel)
|
2017-01-13 18:59:11 +01:00
|
|
|
: m_messages()
|
|
|
|
, m_name((channel.length() > 0 && channel[0] == '#') ? channel.mid(1)
|
2017-01-11 18:52:09 +01:00
|
|
|
: channel)
|
2017-01-07 20:43:55 +01:00
|
|
|
, m_bttvChannelEmotes()
|
|
|
|
, m_ffzChannelEmotes()
|
|
|
|
, m_messageMutex()
|
2017-01-11 18:52:09 +01:00
|
|
|
, m_subLink("https://www.twitch.tv/" + m_name +
|
|
|
|
"/subscribe?ref=in_chat_subscriber_link")
|
2017-01-07 20:43:55 +01:00
|
|
|
, m_channelLink("https://twitch.tv/" + m_name)
|
|
|
|
, m_popoutPlayerLink("https://player.twitch.tv/?channel=" + m_name)
|
2017-01-01 13:07:36 +01:00
|
|
|
{
|
2017-01-07 20:43:55 +01:00
|
|
|
}
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
Channel *
|
|
|
|
Channel::addChannel(const QString &channel)
|
2017-01-03 21:19:33 +01:00
|
|
|
{
|
|
|
|
auto c = getChannel(channel);
|
|
|
|
|
|
|
|
if (c == NULL) {
|
|
|
|
c = new Channel(channel);
|
|
|
|
channels.insert(channel, c);
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2017-01-11 01:08:20 +01:00
|
|
|
c->m_referenceCount++;
|
2017-01-03 21:19:33 +01:00
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
Channel *
|
|
|
|
Channel::getChannel(const QString &channel)
|
2017-01-03 21:19:33 +01:00
|
|
|
{
|
|
|
|
if (channel == "/whispers") {
|
2017-01-11 18:52:09 +01:00
|
|
|
return const_cast<Channel *>(&whispers);
|
2017-01-03 21:19:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (channel == "/mentions") {
|
2017-01-11 18:52:09 +01:00
|
|
|
return const_cast<Channel *>(&mentions);
|
2017-01-03 21:19:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
auto a = channels.find(channel);
|
|
|
|
|
|
|
|
if (a == channels.end()) {
|
2017-01-05 16:07:20 +01:00
|
|
|
return NULL;
|
2017-01-03 21:19:33 +01:00
|
|
|
}
|
|
|
|
|
2017-01-05 16:07:20 +01:00
|
|
|
return a.value();
|
2017-01-03 21:19:33 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
Channel::removeChannel(const QString &channel)
|
2017-01-03 21:19:33 +01:00
|
|
|
{
|
|
|
|
auto c = getChannel(channel);
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (c == NULL)
|
|
|
|
return;
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-01-11 01:08:20 +01:00
|
|
|
c->m_referenceCount--;
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-01-11 01:08:20 +01:00
|
|
|
if (c->m_referenceCount == 0) {
|
2017-01-03 21:19:33 +01:00
|
|
|
channels.remove(channel);
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
QVector<std::shared_ptr<Message>>
|
|
|
|
Channel::getMessagesClone()
|
2017-01-05 16:07:20 +01:00
|
|
|
{
|
2017-01-07 20:43:55 +01:00
|
|
|
m_messageMutex.lock();
|
2017-01-11 01:08:20 +01:00
|
|
|
QVector<std::shared_ptr<Message>> M(m_messages);
|
|
|
|
M.detach();
|
2017-01-07 20:43:55 +01:00
|
|
|
m_messageMutex.unlock();
|
2017-01-05 16:07:20 +01:00
|
|
|
return M;
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
Channel::addMessage(std::shared_ptr<Message> message)
|
2017-01-05 16:07:20 +01:00
|
|
|
{
|
2017-01-07 20:43:55 +01:00
|
|
|
m_messageMutex.lock();
|
2017-01-11 01:08:20 +01:00
|
|
|
m_messages.append(message);
|
2017-01-07 20:43:55 +01:00
|
|
|
m_messageMutex.unlock();
|
2017-01-05 16:07:20 +01:00
|
|
|
}
|