2018-06-26 14:09:39 +02:00
|
|
|
#include "IrcChannel2.hpp"
|
2018-02-05 15:11:50 +01:00
|
|
|
|
2019-09-10 14:46:43 +02:00
|
|
|
#include "debug/AssertInGuiThread.hpp"
|
|
|
|
#include "messages/MessageBuilder.hpp"
|
2019-09-18 10:58:43 +02:00
|
|
|
#include "providers/irc/IrcCommands.hpp"
|
2019-09-10 14:46:43 +02:00
|
|
|
#include "providers/irc/IrcServer.hpp"
|
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
namespace chatterino {
|
2018-06-26 16:37:59 +02:00
|
|
|
|
2019-09-10 14:46:43 +02:00
|
|
|
IrcChannel::IrcChannel(const QString &name, IrcServer *server)
|
2019-09-09 22:26:14 +02:00
|
|
|
: Channel(name, Channel::Type::Irc)
|
2019-09-17 12:10:38 +02:00
|
|
|
, ChannelChatters(*static_cast<Channel *>(this))
|
2019-09-10 14:46:43 +02:00
|
|
|
, server_(server)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcChannel::sendMessage(const QString &message)
|
|
|
|
{
|
|
|
|
assertInGuiThread();
|
|
|
|
|
2019-09-18 10:58:43 +02:00
|
|
|
if (message.startsWith("/"))
|
|
|
|
{
|
|
|
|
int index = message.indexOf(' ', 1);
|
|
|
|
QString command = message.mid(1, index - 1);
|
|
|
|
QString params = index == -1 ? "" : message.mid(index + 1);
|
|
|
|
|
|
|
|
invokeIrcCommand(command, params, *this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (this->server())
|
|
|
|
this->server()->sendMessage(this->getName(), message);
|
|
|
|
|
|
|
|
MessageBuilder builder;
|
|
|
|
builder.emplace<TimestampElement>();
|
|
|
|
builder.emplace<TextElement>(this->server()->nick() + ":",
|
|
|
|
MessageElementFlag::Username);
|
|
|
|
builder.emplace<TextElement>(message, MessageElementFlag::Text);
|
|
|
|
this->addMessage(builder.release());
|
|
|
|
}
|
2019-09-10 14:46:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
IrcServer *IrcChannel::server()
|
2019-09-09 22:26:14 +02:00
|
|
|
{
|
2019-09-10 14:46:43 +02:00
|
|
|
assertInGuiThread();
|
|
|
|
|
|
|
|
return this->server_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcChannel::setServer(IrcServer *server)
|
|
|
|
{
|
|
|
|
assertInGuiThread();
|
|
|
|
|
|
|
|
this->server_ = server;
|
2019-09-09 22:26:14 +02:00
|
|
|
}
|
|
|
|
|
2019-09-18 08:05:51 +02:00
|
|
|
bool IrcChannel::canReconnect() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcChannel::reconnect()
|
|
|
|
{
|
|
|
|
if (this->server())
|
|
|
|
this->server()->connect();
|
|
|
|
}
|
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
} // namespace chatterino
|