mirror-chatterino2/src/channel.cpp
Rasmus Karlsson 6ea3a1df08 Switch some c-style includes to c++-style includes (i.e. stdint.h to
cstdint)

Make MessageElement to a class to fit better with the derived classes.
Make MessageLayoutElement to a class to fit better with the derived
classes.

Remove virtual from override functions

Replace all instances of boost::signals2 with pajlada::Signals. This
lets us properly use clang code model to check for issues.

Add missing virtual destructor to AbstractIrcServer
Add missing virtual destructor to MessageLayoutElement

Remove unused "connectedConnection" connection in TwitchChannel

Fix typo in TrimChannelName function
Fix typo in MessageParseArgs

Replace some raw pointers with unique pointers where it made more sense.
This allowed us to remove some manually written destructors whose only
purpose was to delete that raw pointer.

Reformat: Add namespace comments
Reformat: Add empty empty lines between main namespace beginning and end
Reformat: Re-order includes
Reformat: Fix some includes that used quotes where they should use angle
brackets
Reformat: Replace some typedef's with using's

Filter out more useless warnings
2018-04-11 22:54:34 +02:00

113 lines
2.6 KiB
C++

#include "channel.hpp"
#include "debug/log.hpp"
#include "messages/message.hpp"
#include "singletons/emotemanager.hpp"
#include "singletons/ircmanager.hpp"
#include "singletons/loggingmanager.hpp"
#include "singletons/windowmanager.hpp"
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
using namespace chatterino::messages;
namespace chatterino {
Channel::Channel(const QString &_name)
: name(_name)
, completionModel(this->name)
{
this->clearCompletionModelTimer = new QTimer;
QObject::connect(this->clearCompletionModelTimer, &QTimer::timeout, [this]() {
this->completionModel.ClearExpiredStrings(); //
});
this->clearCompletionModelTimer->start(60 * 1000);
}
Channel::~Channel()
{
this->destroyed.invoke();
this->clearCompletionModelTimer->stop();
this->clearCompletionModelTimer->deleteLater();
}
bool Channel::isEmpty() const
{
return this->name.isEmpty();
}
messages::LimitedQueueSnapshot<messages::MessagePtr> Channel::getMessageSnapshot()
{
return this->messages.getSnapshot();
}
void Channel::addMessage(MessagePtr message)
{
MessagePtr deleted;
const QString &username = message->loginName;
if (!username.isEmpty()) {
// TODO: Add recent chatters display name. This should maybe be a setting
this->addRecentChatter(message);
}
singletons::LoggingManager::getInstance().addMessage(this->name, message);
if (this->messages.pushBack(message, deleted)) {
this->messageRemovedFromStart.invoke(deleted);
}
this->messageAppended.invoke(message);
}
void Channel::addMessagesAtStart(std::vector<messages::MessagePtr> &_messages)
{
std::vector<messages::MessagePtr> addedMessages = this->messages.pushFront(_messages);
if (addedMessages.size() != 0) {
this->messagesAddedAtStart.invoke(addedMessages);
}
}
void Channel::replaceMessage(messages::MessagePtr message, messages::MessagePtr replacement)
{
int index = this->messages.replaceItem(message, replacement);
if (index >= 0) {
this->messageReplaced.invoke((size_t)index, replacement);
}
}
void Channel::addRecentChatter(const std::shared_ptr<messages::Message> &message)
{
// Do nothing by default
}
bool Channel::canSendMessage() const
{
return false;
}
void Channel::sendMessage(const QString &message)
{
}
std::shared_ptr<Channel> Channel::getEmpty()
{
static std::shared_ptr<Channel> channel(new Channel(""));
return channel;
}
void Channel::onConnected()
{
}
} // namespace chatterino