2017-06-11 09:31:45 +02:00
|
|
|
#include "channel.hpp"
|
|
|
|
#include "emotemanager.hpp"
|
|
|
|
#include "ircmanager.hpp"
|
|
|
|
#include "logging/loggingmanager.hpp"
|
|
|
|
#include "messages/message.hpp"
|
|
|
|
#include "windowmanager.hpp"
|
2017-01-01 13:07:36 +01:00
|
|
|
|
2017-05-27 17:45:40 +02:00
|
|
|
#include <QDebug>
|
2017-01-26 17:48:14 +01:00
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonValue>
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QNetworkRequest>
|
2017-03-11 11:39:59 +01:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
using namespace chatterino::messages;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
Channel::Channel(WindowManager &_windowManager, EmoteManager &_emoteManager,
|
2017-07-23 09:53:50 +02:00
|
|
|
IrcManager &_ircManager, const QString &channelName, bool isSpecial)
|
2017-06-13 21:13:58 +02:00
|
|
|
: windowManager(_windowManager)
|
|
|
|
, emoteManager(_emoteManager)
|
|
|
|
, ircManager(_ircManager)
|
2017-07-23 09:53:50 +02:00
|
|
|
, name(channelName)
|
|
|
|
, bttvChannelEmotes(this->emoteManager.bttvChannels[channelName])
|
|
|
|
, ffzChannelEmotes(this->emoteManager.ffzChannels[channelName])
|
|
|
|
, _subLink("https://www.twitch.tv/" + name + "/subscribe?ref=in_chat_subscriber_link")
|
|
|
|
, _channelLink("https://twitch.tv/" + name)
|
|
|
|
, _popoutPlayerLink("https://player.twitch.tv/?channel=" + name)
|
2017-04-13 18:51:46 +02:00
|
|
|
// , _loggingChannel(logging::get(_name))
|
2017-01-01 13:07:36 +01:00
|
|
|
{
|
2017-07-23 09:53:50 +02:00
|
|
|
qDebug() << "Open channel:" << this->name;
|
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
if (!isSpecial) {
|
|
|
|
this->reloadChannelEmotes();
|
|
|
|
}
|
2017-01-07 20:43:55 +01:00
|
|
|
}
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
//
|
|
|
|
// properties
|
|
|
|
//
|
2017-01-26 17:26:20 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
bool Channel::isEmpty() const
|
|
|
|
{
|
2017-07-23 09:53:50 +02:00
|
|
|
return name.isEmpty();
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString &Channel::getSubLink() const
|
|
|
|
{
|
|
|
|
return _subLink;
|
|
|
|
}
|
2017-01-26 17:26:20 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
const QString &Channel::getChannelLink() const
|
|
|
|
{
|
|
|
|
return _channelLink;
|
|
|
|
}
|
2017-01-26 17:26:20 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
const QString &Channel::getPopoutPlayerLink() const
|
|
|
|
{
|
|
|
|
return _popoutPlayerLink;
|
|
|
|
}
|
2017-01-26 17:26:20 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
bool Channel::getIsLive() const
|
|
|
|
{
|
|
|
|
return _isLive;
|
|
|
|
}
|
2017-01-26 17:26:20 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
int Channel::getStreamViewerCount() const
|
|
|
|
{
|
|
|
|
return _streamViewerCount;
|
|
|
|
}
|
2017-01-26 17:26:20 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
const QString &Channel::getStreamStatus() const
|
|
|
|
{
|
|
|
|
return _streamStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &Channel::getStreamGame() const
|
|
|
|
{
|
|
|
|
return _streamGame;
|
2017-01-26 17:26:20 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
messages::LimitedQueueSnapshot<messages::SharedMessage> Channel::getMessageSnapshot()
|
2017-01-26 17:26:20 +01:00
|
|
|
{
|
2017-04-12 17:46:44 +02:00
|
|
|
return _messages.getSnapshot();
|
|
|
|
}
|
2017-01-26 17:26:20 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
//
|
|
|
|
// methods
|
|
|
|
//
|
|
|
|
void Channel::addMessage(std::shared_ptr<Message> message)
|
|
|
|
{
|
|
|
|
std::shared_ptr<Message> deleted;
|
2017-01-26 17:26:20 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
// if (_loggingChannel.get() != nullptr) {
|
|
|
|
// _loggingChannel->append(message);
|
|
|
|
// }
|
2017-01-26 17:26:20 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
if (_messages.appendItem(message, deleted)) {
|
|
|
|
messageRemovedFromStart(deleted);
|
|
|
|
}
|
2017-01-26 17:26:20 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
this->messageAppended(message);
|
2017-01-26 17:26:20 +01:00
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
this->windowManager.repaintVisibleChatWidgets(this);
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2017-01-26 17:26:20 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
// private methods
|
|
|
|
void Channel::reloadChannelEmotes()
|
|
|
|
{
|
2017-07-23 09:53:50 +02:00
|
|
|
printf("[Channel:%s] Reloading channel emotes\n", qPrintable(this->name));
|
|
|
|
this->emoteManager.reloadBTTVChannelEmotes(this->name);
|
|
|
|
this->emoteManager.reloadFFZChannelEmotes(this->name);
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2017-01-26 17:26:20 +01:00
|
|
|
|
2017-05-27 17:45:40 +02:00
|
|
|
void Channel::sendMessage(const QString &message)
|
|
|
|
{
|
|
|
|
qDebug() << "Channel send message: " << message;
|
2017-07-31 22:15:02 +02:00
|
|
|
|
|
|
|
// Do last message processing
|
|
|
|
QString parsedMessage = this->emoteManager.replaceShortCodes(message);
|
|
|
|
|
|
|
|
this->ircManager.sendMessage(name, parsedMessage);
|
2017-01-05 16:07:20 +01:00
|
|
|
}
|
2017-03-11 11:32:19 +01:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace chatterino
|