mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
refactored Channel
This commit is contained in:
parent
b639604a47
commit
aa3df2e6d8
14 changed files with 55 additions and 59 deletions
|
@ -20,31 +20,27 @@ namespace chatterino {
|
|||
Channel::Channel(const QString &_name, Type _type)
|
||||
: name(_name)
|
||||
, completionModel(this->name)
|
||||
, type(_type)
|
||||
, type_(_type)
|
||||
{
|
||||
this->clearCompletionModelTimer = new QTimer;
|
||||
QObject::connect(this->clearCompletionModelTimer, &QTimer::timeout, [this]() {
|
||||
QObject::connect(&this->clearCompletionModelTimer, &QTimer::timeout, [this]() {
|
||||
this->completionModel.ClearExpiredStrings(); //
|
||||
});
|
||||
this->clearCompletionModelTimer->start(60 * 1000);
|
||||
this->clearCompletionModelTimer.start(60 * 1000);
|
||||
}
|
||||
|
||||
Channel::~Channel()
|
||||
{
|
||||
this->destroyed.invoke();
|
||||
|
||||
this->clearCompletionModelTimer->stop();
|
||||
this->clearCompletionModelTimer->deleteLater();
|
||||
}
|
||||
|
||||
Channel::Type Channel::getType() const
|
||||
{
|
||||
return this->type;
|
||||
return this->type_;
|
||||
}
|
||||
|
||||
bool Channel::isTwitchChannel() const
|
||||
{
|
||||
return this->type >= Twitch && this->type < TwitchEnd;
|
||||
return this->type_ >= Type::Twitch && this->type_ < Type::TwitchEnd;
|
||||
}
|
||||
|
||||
bool Channel::isEmpty() const
|
||||
|
@ -54,7 +50,7 @@ bool Channel::isEmpty() const
|
|||
|
||||
LimitedQueueSnapshot<MessagePtr> Channel::getMessageSnapshot()
|
||||
{
|
||||
return this->messages.getSnapshot();
|
||||
return this->messages_.getSnapshot();
|
||||
}
|
||||
|
||||
void Channel::addMessage(MessagePtr message)
|
||||
|
@ -73,7 +69,7 @@ void Channel::addMessage(MessagePtr message)
|
|||
app->logging->addMessage(this->name, message);
|
||||
}
|
||||
|
||||
if (this->messages.pushBack(message, deleted)) {
|
||||
if (this->messages_.pushBack(message, deleted)) {
|
||||
this->messageRemovedFromStart.invoke(deleted);
|
||||
}
|
||||
|
||||
|
@ -163,7 +159,7 @@ void Channel::disableAllMessages()
|
|||
|
||||
void Channel::addMessagesAtStart(std::vector<MessagePtr> &_messages)
|
||||
{
|
||||
std::vector<MessagePtr> addedMessages = this->messages.pushFront(_messages);
|
||||
std::vector<MessagePtr> addedMessages = this->messages_.pushFront(_messages);
|
||||
|
||||
if (addedMessages.size() != 0) {
|
||||
this->messagesAddedAtStart.invoke(addedMessages);
|
||||
|
@ -172,7 +168,7 @@ void Channel::addMessagesAtStart(std::vector<MessagePtr> &_messages)
|
|||
|
||||
void Channel::replaceMessage(MessagePtr message, MessagePtr replacement)
|
||||
{
|
||||
int index = this->messages.replaceItem(message, replacement);
|
||||
int index = this->messages_.replaceItem(message, replacement);
|
||||
|
||||
if (index >= 0) {
|
||||
this->messageReplaced.invoke((size_t)index, replacement);
|
||||
|
@ -211,7 +207,7 @@ bool Channel::hasModRights() const
|
|||
|
||||
std::shared_ptr<Channel> Channel::getEmpty()
|
||||
{
|
||||
static std::shared_ptr<Channel> channel(new Channel("", None));
|
||||
static std::shared_ptr<Channel> channel(new Channel("", Type::None));
|
||||
return channel;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,10 +17,8 @@ struct Message;
|
|||
|
||||
class Channel : public std::enable_shared_from_this<Channel>
|
||||
{
|
||||
QTimer *clearCompletionModelTimer;
|
||||
|
||||
public:
|
||||
enum Type {
|
||||
enum class Type {
|
||||
None,
|
||||
Direct,
|
||||
Twitch,
|
||||
|
@ -31,7 +29,7 @@ public:
|
|||
Misc
|
||||
};
|
||||
|
||||
explicit Channel(const QString &_name, Type type);
|
||||
explicit Channel(const QString &_name, Type type_);
|
||||
virtual ~Channel();
|
||||
|
||||
pajlada::Signals::Signal<const QString &, const QString &, bool &> sendMessageSignal;
|
||||
|
@ -48,7 +46,7 @@ public:
|
|||
LimitedQueueSnapshot<MessagePtr> getMessageSnapshot();
|
||||
|
||||
void addMessage(MessagePtr message);
|
||||
void addMessagesAtStart(std::vector<MessagePtr> &messages);
|
||||
void addMessagesAtStart(std::vector<MessagePtr> &messages_);
|
||||
void addOrReplaceTimeout(MessagePtr message);
|
||||
void disableAllMessages();
|
||||
void replaceMessage(MessagePtr message, MessagePtr replacement);
|
||||
|
@ -71,8 +69,9 @@ protected:
|
|||
virtual void onConnected();
|
||||
|
||||
private:
|
||||
LimitedQueue<MessagePtr> messages;
|
||||
Type type;
|
||||
LimitedQueue<MessagePtr> messages_;
|
||||
Type type_;
|
||||
QTimer clearCompletionModelTimer_;
|
||||
};
|
||||
|
||||
using ChannelPtr = std::shared_ptr<Channel>;
|
||||
|
@ -92,40 +91,41 @@ class IndirectChannel
|
|||
}
|
||||
};
|
||||
|
||||
std::shared_ptr<Data> data;
|
||||
|
||||
public:
|
||||
IndirectChannel(ChannelPtr channel, Channel::Type type = Channel::Direct)
|
||||
: data(new Data(channel, type))
|
||||
IndirectChannel(ChannelPtr channel, Channel::Type type = Channel::Type::Direct)
|
||||
: data_(new Data(channel, type))
|
||||
{
|
||||
}
|
||||
|
||||
ChannelPtr get()
|
||||
{
|
||||
return data->channel;
|
||||
return data_->channel;
|
||||
}
|
||||
|
||||
void update(ChannelPtr ptr)
|
||||
{
|
||||
assert(this->data->type != Channel::Direct);
|
||||
assert(this->data_->type != Channel::Type::Direct);
|
||||
|
||||
this->data->channel = ptr;
|
||||
this->data->changed.invoke();
|
||||
this->data_->channel = ptr;
|
||||
this->data_->changed.invoke();
|
||||
}
|
||||
|
||||
pajlada::Signals::NoArgSignal &getChannelChanged()
|
||||
{
|
||||
return this->data->changed;
|
||||
return this->data_->changed;
|
||||
}
|
||||
|
||||
Channel::Type getType()
|
||||
{
|
||||
if (this->data->type == Channel::Direct) {
|
||||
if (this->data_->type == Channel::Type::Direct) {
|
||||
return this->get()->getType();
|
||||
} else {
|
||||
return this->data->type;
|
||||
return this->data_->type;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<Data> data_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
namespace chatterino {
|
||||
|
||||
TwitchChannel::TwitchChannel(const QString &channelName, Communi::IrcConnection *_readConnection)
|
||||
: Channel(channelName, Channel::Twitch)
|
||||
: Channel(channelName, Channel::Type::Twitch)
|
||||
, bttvChannelEmotes(new EmoteMap)
|
||||
, ffzChannelEmotes(new EmoteMap)
|
||||
, subscriptionURL("https://www.twitch.tv/subs/" + name)
|
||||
|
|
|
@ -19,9 +19,9 @@ using namespace std::chrono_literals;
|
|||
namespace chatterino {
|
||||
|
||||
TwitchServer::TwitchServer()
|
||||
: whispersChannel(new Channel("/whispers", Channel::TwitchWhispers))
|
||||
, mentionsChannel(new Channel("/mentions", Channel::TwitchMentions))
|
||||
, watchingChannel(Channel::getEmpty(), Channel::TwitchWatching)
|
||||
: whispersChannel(new Channel("/whispers", Channel::Type::TwitchWhispers))
|
||||
, mentionsChannel(new Channel("/mentions", Channel::Type::TwitchMentions))
|
||||
, watchingChannel(Channel::getEmpty(), Channel::Type::TwitchWatching)
|
||||
{
|
||||
qDebug() << "init TwitchServer";
|
||||
}
|
||||
|
|
|
@ -417,17 +417,17 @@ void WindowManager::encodeChannel(IndirectChannel channel, QJsonObject &obj)
|
|||
assertInGuiThread();
|
||||
|
||||
switch (channel.getType()) {
|
||||
case Channel::Twitch: {
|
||||
case Channel::Type::Twitch: {
|
||||
obj.insert("type", "twitch");
|
||||
obj.insert("name", channel.get()->name);
|
||||
} break;
|
||||
case Channel::TwitchMentions: {
|
||||
case Channel::Type::TwitchMentions: {
|
||||
obj.insert("type", "mentions");
|
||||
} break;
|
||||
case Channel::TwitchWatching: {
|
||||
case Channel::Type::TwitchWatching: {
|
||||
obj.insert("type", "watching");
|
||||
} break;
|
||||
case Channel::TwitchWhispers: {
|
||||
case Channel::Type::TwitchWhispers: {
|
||||
obj.insert("type", "whispers");
|
||||
} break;
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ AttachedWindow *AttachedWindow::get(void *target, const GetArgs &args)
|
|||
}
|
||||
|
||||
if (show) {
|
||||
window->updateWindowRect_(window->target_);
|
||||
window->updateWindowRect(window->target_);
|
||||
window->show();
|
||||
}
|
||||
|
||||
|
@ -107,10 +107,10 @@ void AttachedWindow::setChannel(ChannelPtr channel)
|
|||
|
||||
void AttachedWindow::showEvent(QShowEvent *)
|
||||
{
|
||||
this->attachToHwnd_(this->target_);
|
||||
this->attachToHwnd(this->target_);
|
||||
}
|
||||
|
||||
void AttachedWindow::attachToHwnd_(void *_attachedPtr)
|
||||
void AttachedWindow::attachToHwnd(void *_attachedPtr)
|
||||
{
|
||||
#ifdef USEWINSDK
|
||||
if (this->attached_) {
|
||||
|
@ -145,13 +145,13 @@ void AttachedWindow::attachToHwnd_(void *_attachedPtr)
|
|||
this->validProcessName_ = true;
|
||||
}
|
||||
|
||||
this->updateWindowRect_(attached);
|
||||
this->updateWindowRect(attached);
|
||||
});
|
||||
this->timer_.start();
|
||||
#endif
|
||||
}
|
||||
|
||||
void AttachedWindow::updateWindowRect_(void *_attachedPtr)
|
||||
void AttachedWindow::updateWindowRect(void *_attachedPtr)
|
||||
{
|
||||
#ifdef USEWINSDK
|
||||
auto hwnd = HWND(this->winId());
|
||||
|
|
|
@ -47,8 +47,8 @@ private:
|
|||
Split *split;
|
||||
} ui_;
|
||||
|
||||
void attachToHwnd_(void *attached);
|
||||
void updateWindowRect_(void *attached);
|
||||
void attachToHwnd(void *attached);
|
||||
void updateWindowRect(void *attached);
|
||||
|
||||
struct Item {
|
||||
void *hwnd;
|
||||
|
|
|
@ -54,7 +54,7 @@ void EmotePopup::loadChannel(ChannelPtr _channel)
|
|||
return;
|
||||
}
|
||||
|
||||
ChannelPtr emoteChannel(new Channel("", Channel::None));
|
||||
ChannelPtr emoteChannel(new Channel("", Channel::Type::None));
|
||||
|
||||
auto addEmotes = [&](EmoteMap &map, const QString &title, const QString &emoteDesc) {
|
||||
// TITLE
|
||||
|
@ -134,7 +134,7 @@ void EmotePopup::loadEmojis()
|
|||
{
|
||||
auto &emojis = getApp()->emotes->emojis.emojis;
|
||||
|
||||
ChannelPtr emojiChannel(new Channel("", Channel::None));
|
||||
ChannelPtr emojiChannel(new Channel("", Channel::Type::None));
|
||||
|
||||
// title
|
||||
MessageBuilder builder1;
|
||||
|
|
|
@ -39,7 +39,7 @@ void LogsPopup::setInfo(ChannelPtr channel, QString userName)
|
|||
|
||||
void LogsPopup::setMessages(std::vector<MessagePtr> &messages)
|
||||
{
|
||||
ChannelPtr logsChannel(new Channel("logs", Channel::Misc));
|
||||
ChannelPtr logsChannel(new Channel("logs", Channel::Type::Misc));
|
||||
|
||||
logsChannel->addMessagesAtStart(messages);
|
||||
this->channelView_->setChannel(logsChannel);
|
||||
|
@ -68,7 +68,7 @@ void LogsPopup::getLogviewerLogs()
|
|||
req.getJSON([this, channelName](QJsonObject &data) {
|
||||
|
||||
std::vector<MessagePtr> messages;
|
||||
ChannelPtr logsChannel(new Channel("logs", Channel::None));
|
||||
ChannelPtr logsChannel(new Channel("logs", Channel::Type::None));
|
||||
|
||||
QJsonValue before = data.value("before");
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace chatterino {
|
|||
|
||||
NotificationPopup::NotificationPopup()
|
||||
: BaseWindow((QWidget *)nullptr, BaseWindow::Frameless)
|
||||
, channel(std::make_shared<Channel>("notifications", Channel::None))
|
||||
, channel(std::make_shared<Channel>("notifications", Channel::Type::None))
|
||||
|
||||
{
|
||||
this->channelView = new ChannelView(this);
|
||||
|
|
|
@ -151,20 +151,20 @@ void SelectChannelDialog::setSelectedChannel(IndirectChannel _channel)
|
|||
this->selectedChannel = channel;
|
||||
|
||||
switch (_channel.getType()) {
|
||||
case Channel::Twitch: {
|
||||
case Channel::Type::Twitch: {
|
||||
this->ui_.notebook->selectIndex(TAB_TWITCH);
|
||||
this->ui_.twitch.channel->setFocus();
|
||||
this->ui_.twitch.channelName->setText(channel->name);
|
||||
} break;
|
||||
case Channel::TwitchWatching: {
|
||||
case Channel::Type::TwitchWatching: {
|
||||
this->ui_.notebook->selectIndex(TAB_TWITCH);
|
||||
this->ui_.twitch.watching->setFocus();
|
||||
} break;
|
||||
case Channel::TwitchMentions: {
|
||||
case Channel::Type::TwitchMentions: {
|
||||
this->ui_.notebook->selectIndex(TAB_TWITCH);
|
||||
this->ui_.twitch.mentions->setFocus();
|
||||
} break;
|
||||
case Channel::TwitchWhispers: {
|
||||
case Channel::Type::TwitchWhispers: {
|
||||
this->ui_.notebook->selectIndex(TAB_TWITCH);
|
||||
this->ui_.twitch.whispers->setFocus();
|
||||
} break;
|
||||
|
|
|
@ -71,7 +71,7 @@ void SearchPopup::performSearch()
|
|||
{
|
||||
QString text = searchInput->text();
|
||||
|
||||
ChannelPtr channel(new Channel("search", Channel::None));
|
||||
ChannelPtr channel(new Channel("search", Channel::Type::None));
|
||||
|
||||
for (size_t i = 0; i < this->snapshot.getLength(); i++) {
|
||||
MessagePtr message = this->snapshot[i];
|
||||
|
|
|
@ -272,7 +272,7 @@ void LookPage::addLastReadMessageIndicatorPatternSelector(LayoutCreator<QVBoxLay
|
|||
|
||||
ChannelPtr LookPage::createPreviewChannel()
|
||||
{
|
||||
auto channel = ChannelPtr(new Channel("preview", Channel::Misc));
|
||||
auto channel = ChannelPtr(new Channel("preview", Channel::Type::Misc));
|
||||
|
||||
{
|
||||
auto message = MessagePtr(new Message());
|
||||
|
|
|
@ -311,7 +311,7 @@ void SplitHeader::updateChannelText()
|
|||
|
||||
QString title = channel->name;
|
||||
|
||||
if (indirectChannel.getType() == Channel::TwitchWatching) {
|
||||
if (indirectChannel.getType() == Channel::Type::TwitchWatching) {
|
||||
title = "watching: " + (title.isEmpty() ? "none" : title);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue