-
-
Notifications
You must be signed in to change notification settings - Fork 548
Expand file tree
/
Copy pathChannel.hpp
More file actions
190 lines (155 loc) · 5.82 KB
/
Channel.hpp
File metadata and controls
190 lines (155 loc) · 5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#pragma once
#include "common/enums/MessageContext.hpp"
#include "controllers/completion/TabCompletionModel.hpp"
#include "messages/LimitedQueue.hpp"
#include "messages/MessageFlag.hpp"
#include "messages/MessageSink.hpp"
#include <magic_enum/magic_enum.hpp>
#include <pajlada/signals/signal.hpp>
#include <QDate>
#include <QString>
#include <QTimer>
#include <memory>
#include <optional>
namespace chatterino {
struct Message;
using MessagePtr = std::shared_ptr<const Message>;
class EmoteHolder;
class Channel : public std::enable_shared_from_this<Channel>, public MessageSink
{
public:
// This is for Lua. See scripts/make_luals_meta.py
/**
* @exposeenum c2.ChannelType
*/
enum class Type : std::uint8_t {
/// This channel may not be backed by a real channel.
///
/// Messages sent to this channel are not logged.
None,
/// Direct
Direct,
/// Twitch
Twitch,
/// TwitchWhispers
TwitchWhispers,
/// TwitchWatching
TwitchWatching,
/// TwitchMentions
TwitchMentions,
/// TwitchLive
TwitchLive,
/// TwitchAutomod
TwitchAutomod,
/// TwitchEnd
TwitchEnd,
/// Misc
Misc,
};
explicit Channel(const QString &name, Type type);
~Channel() override;
// SIGNALS
pajlada::Signals::Signal<const QString &, const QString &, bool &>
sendMessageSignal;
pajlada::Signals::Signal<const QString &, const QString &, const QString &,
bool &>
sendReplySignal;
pajlada::Signals::Signal<MessagePtr &, std::optional<MessageFlags>>
messageAppended;
pajlada::Signals::Signal<std::vector<MessagePtr> &> messagesAddedAtStart;
/// (index, prev-message, replacement)
pajlada::Signals::Signal<size_t, const MessagePtr &, const MessagePtr &>
messageReplaced;
/// Invoked when some number of messages were filled in using time received
pajlada::Signals::Signal<const std::vector<MessagePtr> &> filledInMessages;
pajlada::Signals::NoArgSignal destroyed;
pajlada::Signals::NoArgSignal displayNameChanged;
pajlada::Signals::NoArgSignal messagesCleared;
Type getType() const;
const QString &getName() const;
virtual const QString &getDisplayName() const;
virtual const QString &getLocalizedName() const;
bool isTwitchChannel() const;
virtual bool isEmpty() const;
std::vector<MessagePtr> getMessageSnapshot() const;
std::vector<MessagePtr> getMessageSnapshot(size_t nItems) const;
/// Returns the last message (the one at the bottom). If the channel has no
/// messages, this will return an empty shared pointer.
MessagePtr getLastMessage() const;
// MESSAGES
// overridingFlags can be filled in with flags that should be used instead
// of the message's flags. This is useful in case a flag is specific to a
// type of split
void addMessage(
MessagePtr message, MessageContext context,
std::optional<MessageFlags> overridingFlags = std::nullopt) final;
void addMessagesAtStart(const std::vector<MessagePtr> &messages_);
void addSystemMessage(const QString &contents);
/// Inserts the given messages in order by Message::serverReceivedTime.
void fillInMissingMessages(const std::vector<MessagePtr> &messages);
void addOrReplaceTimeout(MessagePtr message, const QDateTime &now) final;
void addOrReplaceClearChat(MessagePtr message, const QDateTime &now) final;
void disableAllMessages() final;
void replaceMessage(const MessagePtr &message,
const MessagePtr &replacement);
void replaceMessage(size_t index, const MessagePtr &replacement);
void replaceMessage(size_t hint, const MessagePtr &message,
const MessagePtr &replacement);
void disableMessage(const QString &messageID);
/// Removes all messages from this channel and invokes #messagesCleared
void clearMessages();
MessagePtr findMessageByID(QStringView messageID) final;
bool hasMessages() const;
void applySimilarityFilters(const MessagePtr &message) const final;
MessageSinkTraits sinkTraits() const final;
EmoteHolder *emotes();
const EmoteHolder *emotes() const;
// CHANNEL INFO
virtual bool canSendMessage() const;
virtual bool isWritable() const; // whether split input will be usable
virtual void sendMessage(const QString &message);
virtual bool isMod() const;
virtual bool isBroadcaster() const;
virtual bool hasModRights() const;
virtual bool hasHighRateLimit() const;
virtual bool isLive() const;
virtual bool isRerun() const;
virtual bool shouldIgnoreHighlights() const;
virtual bool canReconnect() const;
virtual void reconnect();
virtual QString getCurrentStreamID() const;
static std::shared_ptr<Channel> getEmpty();
TabCompletionModel *completionModel;
QDate lastDate_;
protected:
virtual void onConnected();
virtual void messageRemovedFromStart(const MessagePtr &msg);
QString platform_;
std::unique_ptr<EmoteHolder> emotes_;
private:
const QString name_;
LimitedQueue<MessagePtr> messages_;
Type type_;
bool anythingLogged_ = false;
QTimer clearCompletionModelTimer_;
};
using ChannelPtr = std::shared_ptr<Channel>;
class IndirectChannel
{
struct Data {
ChannelPtr channel;
Channel::Type type;
pajlada::Signals::NoArgSignal changed;
Data(ChannelPtr channel, Channel::Type type);
};
public:
IndirectChannel(ChannelPtr channel,
Channel::Type type = Channel::Type::Direct);
ChannelPtr get() const;
void reset(ChannelPtr channel);
pajlada::Signals::NoArgSignal &getChannelChanged();
Channel::Type getType() const;
private:
std::shared_ptr<Data> data_;
};
} // namespace chatterino