2017-06-11 09:31:45 +02:00
|
|
|
#include "channel.hpp"
|
2017-11-04 14:57:29 +01:00
|
|
|
#include "debug/log.hpp"
|
2017-06-11 09:31:45 +02:00
|
|
|
#include "messages/message.hpp"
|
2018-01-01 22:29:21 +01:00
|
|
|
#include "singletons/emotemanager.hpp"
|
|
|
|
#include "singletons/ircmanager.hpp"
|
2018-01-28 14:23:55 +01:00
|
|
|
#include "singletons/loggingmanager.hpp"
|
2017-12-31 00:50:07 +01:00
|
|
|
#include "singletons/windowmanager.hpp"
|
2017-01-01 13:07:36 +01:00
|
|
|
|
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-11-04 14:57:29 +01:00
|
|
|
Channel::Channel(const QString &_name)
|
|
|
|
: name(_name)
|
2018-03-24 12:02:07 +01:00
|
|
|
, completionModel(this->name)
|
2017-01-01 13:07:36 +01:00
|
|
|
{
|
2018-03-30 13:50:43 +02:00
|
|
|
this->clearCompletionModelTimer = new QTimer;
|
|
|
|
QObject::connect(this->clearCompletionModelTimer, &QTimer::timeout, [this]() {
|
|
|
|
this->completionModel.ClearExpiredStrings(); //
|
|
|
|
});
|
|
|
|
this->clearCompletionModelTimer->start(60 * 1000);
|
2017-01-07 20:43:55 +01:00
|
|
|
}
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
Channel::~Channel()
|
|
|
|
{
|
|
|
|
this->destroyed.invoke();
|
2018-03-30 13:50:43 +02:00
|
|
|
|
|
|
|
this->clearCompletionModelTimer->stop();
|
|
|
|
this->clearCompletionModelTimer->deleteLater();
|
2018-02-05 15:11:50 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
bool Channel::isEmpty() const
|
|
|
|
{
|
2018-02-05 15:11:50 +01:00
|
|
|
return this->name.isEmpty();
|
2017-01-26 17:26:20 +01:00
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
messages::LimitedQueueSnapshot<messages::MessagePtr> Channel::getMessageSnapshot()
|
2017-01-26 17:26:20 +01:00
|
|
|
{
|
2017-09-21 12:15:01 +02:00
|
|
|
return this->messages.getSnapshot();
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2017-01-26 17:26:20 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
void Channel::addMessage(MessagePtr message)
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
MessagePtr deleted;
|
2017-01-26 17:26:20 +01:00
|
|
|
|
2017-12-17 21:05:25 +01:00
|
|
|
const QString &username = message->loginName;
|
2017-12-17 17:49:32 +01:00
|
|
|
|
|
|
|
if (!username.isEmpty()) {
|
|
|
|
// TODO: Add recent chatters display name. This should maybe be a setting
|
2017-12-17 21:05:25 +01:00
|
|
|
this->addRecentChatter(message);
|
2017-12-17 17:49:32 +01:00
|
|
|
}
|
|
|
|
|
2018-01-28 14:23:55 +01:00
|
|
|
singletons::LoggingManager::getInstance().addMessage(this->name, message);
|
2017-01-26 17:26:20 +01:00
|
|
|
|
2018-01-01 22:29:21 +01:00
|
|
|
if (this->messages.pushBack(message, deleted)) {
|
2018-01-28 14:23:55 +01:00
|
|
|
this->messageRemovedFromStart(deleted);
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
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
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
void Channel::addMessagesAtStart(std::vector<messages::MessagePtr> &_messages)
|
2018-01-01 22:29:21 +01:00
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
std::vector<messages::MessagePtr> addedMessages = this->messages.pushFront(_messages);
|
2018-01-01 22:29:21 +01:00
|
|
|
|
|
|
|
if (addedMessages.size() != 0) {
|
|
|
|
this->messagesAddedAtStart(addedMessages);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
void Channel::replaceMessage(messages::MessagePtr message, messages::MessagePtr replacement)
|
2018-01-05 23:14:55 +01:00
|
|
|
{
|
|
|
|
int index = this->messages.replaceItem(message, replacement);
|
|
|
|
|
|
|
|
if (index >= 0) {
|
|
|
|
this->messageReplaced((size_t)index, replacement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-17 21:05:25 +01:00
|
|
|
void Channel::addRecentChatter(const std::shared_ptr<messages::Message> &message)
|
2017-12-17 17:49:32 +01:00
|
|
|
{
|
2018-03-30 12:16:12 +02:00
|
|
|
// Do nothing by default
|
2017-12-17 17:49:32 +01:00
|
|
|
}
|
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
bool Channel::canSendMessage() const
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2017-09-16 00:05:06 +02:00
|
|
|
return false;
|
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)
|
|
|
|
{
|
2017-01-05 16:07:20 +01:00
|
|
|
}
|
2017-03-11 11:32:19 +01:00
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
std::shared_ptr<Channel> Channel::getEmpty()
|
|
|
|
{
|
|
|
|
static std::shared_ptr<Channel> channel(new Channel(""));
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Channel::onConnected()
|
|
|
|
{
|
|
|
|
}
|
2018-03-30 12:16:12 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace chatterino
|