mirror-chatterino2/src/channel.cpp

141 lines
3.1 KiB
C++
Raw Normal View History

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"
#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-01-11 01:08:20 +01:00
#include <memory>
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
Channel::Channel(WindowManager &_windowManager, EmoteManager &_emoteManager,
IrcManager &_ircManager, const QString &channel, bool isSpecial)
: windowManager(_windowManager)
, emoteManager(_emoteManager)
, ircManager(_ircManager)
2017-04-12 17:46:44 +02:00
, _name((channel.length() > 0 && channel[0] == '#') ? channel.mid(1) : channel)
, bttvChannelEmotes(this->emoteManager.bttvChannels[channel])
, ffzChannelEmotes(this->emoteManager.ffzChannels[channel])
2017-04-12 17:46:44 +02:00
, _subLink("https://www.twitch.tv/" + _name + "/subscribe?ref=in_chat_subscriber_link")
, _channelLink("https://twitch.tv/" + _name)
, _popoutPlayerLink("https://player.twitch.tv/?channel=" + _name)
// , _loggingChannel(logging::get(_name))
{
qDebug() << "Open channel:" << channel << ". Name: " << _name;
printf("Channel pointer: %p\n", this);
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
//
EmoteManager::EmoteMap &Channel::getBTTVChannelEmotes()
2017-01-26 17:26:20 +01:00
{
return this->bttvChannelEmotes;
2017-04-12 17:46:44 +02:00
}
2017-01-26 17:26:20 +01:00
EmoteManager::EmoteMap &Channel::getFFZChannelEmotes()
2017-04-12 17:46:44 +02:00
{
return this->ffzChannelEmotes;
2017-04-12 17:46:44 +02:00
}
2017-01-26 17:26:20 +01:00
2017-04-12 17:46:44 +02:00
bool Channel::isEmpty() const
{
return _name.isEmpty();
}
2017-01-26 17:26:20 +01:00
2017-04-12 17:46:44 +02:00
const QString &Channel::getName() const
{
return _name;
}
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
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()
{
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
void Channel::sendMessage(const QString &message)
{
qDebug() << "Channel send message: " << message;
this->ircManager.sendMessage(_name, message);
2017-01-05 16:07:20 +01:00
}
2017-04-14 17:52:22 +02:00
} // namespace chatterino