2017-06-07 10:09:24 +02:00
|
|
|
#pragma once
|
2017-01-01 13:07:36 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
#include "messages/image.hpp"
|
2017-06-11 09:31:45 +02:00
|
|
|
#include "messages/limitedqueue.hpp"
|
2018-01-28 14:23:55 +01:00
|
|
|
#include "messages/message.hpp"
|
2018-03-24 12:13:09 +01:00
|
|
|
#include "util/completionmodel.hpp"
|
2017-12-31 22:58:35 +01:00
|
|
|
#include "util/concurrentmap.hpp"
|
2017-01-07 20:43:55 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
#include <QString>
|
2018-03-30 13:50:43 +02:00
|
|
|
#include <QTimer>
|
2018-04-03 02:55:32 +02:00
|
|
|
#include <pajlada/signals/signal.hpp>
|
2017-06-07 10:09:24 +02:00
|
|
|
|
2017-01-11 01:08:20 +01:00
|
|
|
#include <memory>
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
|
|
|
namespace messages {
|
2018-01-28 03:29:42 +01:00
|
|
|
struct Message;
|
2018-04-03 02:55:32 +02:00
|
|
|
} // namespace messages
|
2017-01-01 13:07:36 +01:00
|
|
|
|
2018-01-05 00:58:25 +01:00
|
|
|
class Channel : public std::enable_shared_from_this<Channel>
|
2017-01-01 13:07:36 +01:00
|
|
|
{
|
2018-03-30 13:50:43 +02:00
|
|
|
QTimer *clearCompletionModelTimer;
|
|
|
|
|
2017-01-01 13:07:36 +01:00
|
|
|
public:
|
2018-04-18 09:12:29 +02:00
|
|
|
enum Type {
|
|
|
|
None,
|
2018-04-20 19:54:45 +02:00
|
|
|
Direct,
|
2018-04-18 09:12:29 +02:00
|
|
|
Twitch,
|
|
|
|
TwitchWhispers,
|
|
|
|
TwitchWatching,
|
|
|
|
TwitchMentions,
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit Channel(const QString &_name, Type type);
|
2018-02-05 15:11:50 +01:00
|
|
|
virtual ~Channel();
|
|
|
|
|
|
|
|
pajlada::Signals::Signal<const QString &, const QString &> sendMessageSignal;
|
2017-01-07 20:43:55 +01:00
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
pajlada::Signals::Signal<messages::MessagePtr &> messageRemovedFromStart;
|
|
|
|
pajlada::Signals::Signal<messages::MessagePtr &> messageAppended;
|
|
|
|
pajlada::Signals::Signal<std::vector<messages::MessagePtr> &> messagesAddedAtStart;
|
|
|
|
pajlada::Signals::Signal<size_t, messages::MessagePtr &> messageReplaced;
|
2018-02-05 15:11:50 +01:00
|
|
|
pajlada::Signals::NoArgSignal destroyed;
|
2017-02-02 20:35:12 +01:00
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
Type getType() const;
|
2017-09-16 00:05:06 +02:00
|
|
|
virtual bool isEmpty() const;
|
2018-01-11 20:16:25 +01:00
|
|
|
messages::LimitedQueueSnapshot<messages::MessagePtr> getMessageSnapshot();
|
2017-01-05 20:49:33 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
void addMessage(messages::MessagePtr message);
|
|
|
|
void addMessagesAtStart(std::vector<messages::MessagePtr> &messages);
|
|
|
|
void replaceMessage(messages::MessagePtr message, messages::MessagePtr replacement);
|
2018-03-30 12:16:12 +02:00
|
|
|
virtual void addRecentChatter(const std::shared_ptr<messages::Message> &message);
|
2017-12-17 17:49:32 +01:00
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
QString name;
|
2017-09-23 19:23:10 +02:00
|
|
|
QStringList modList;
|
2017-05-27 17:45:40 +02:00
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
virtual bool canSendMessage() const;
|
|
|
|
virtual void sendMessage(const QString &message);
|
2018-04-18 09:12:29 +02:00
|
|
|
virtual bool isMod() const;
|
2017-07-02 15:12:00 +02:00
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
static std::shared_ptr<Channel> getEmpty();
|
|
|
|
|
2018-03-24 12:13:09 +01:00
|
|
|
CompletionModel completionModel;
|
2018-03-24 12:02:07 +01:00
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
protected:
|
|
|
|
virtual void onConnected();
|
|
|
|
|
2017-01-01 13:07:36 +01:00
|
|
|
private:
|
2018-01-11 20:16:25 +01:00
|
|
|
messages::LimitedQueue<messages::MessagePtr> messages;
|
2018-04-18 09:12:29 +02:00
|
|
|
Type type;
|
2017-01-01 13:07:36 +01:00
|
|
|
};
|
2017-03-11 11:32:19 +01:00
|
|
|
|
2018-03-30 12:37:00 +02:00
|
|
|
using ChannelPtr = std::shared_ptr<Channel>;
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-04-20 19:54:45 +02:00
|
|
|
class IndirectChannel
|
|
|
|
{
|
|
|
|
struct Data {
|
|
|
|
ChannelPtr channel;
|
|
|
|
Channel::Type type;
|
|
|
|
pajlada::Signals::NoArgSignal changed;
|
|
|
|
|
|
|
|
Data() = delete;
|
|
|
|
Data(ChannelPtr _channel, Channel::Type _type)
|
|
|
|
: channel(_channel)
|
|
|
|
, type(_type)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::shared_ptr<Data> data;
|
|
|
|
|
|
|
|
public:
|
|
|
|
IndirectChannel(ChannelPtr channel, Channel::Type type = Channel::None)
|
|
|
|
: data(new Data(channel, type))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ChannelPtr get()
|
|
|
|
{
|
|
|
|
return data->channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void update(ChannelPtr ptr)
|
|
|
|
{
|
|
|
|
assert(this->data->type != Channel::Direct);
|
|
|
|
|
|
|
|
this->data->channel = ptr;
|
|
|
|
this->data->changed.invoke();
|
|
|
|
}
|
|
|
|
|
|
|
|
pajlada::Signals::NoArgSignal &getChannelChanged()
|
|
|
|
{
|
|
|
|
return this->data->changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
Channel::Type getType()
|
|
|
|
{
|
|
|
|
if (this->data->type == Channel::Direct) {
|
|
|
|
return this->get()->getType();
|
|
|
|
} else {
|
|
|
|
return this->data->type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace chatterino
|