mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Add system messages upon connecting/disconnecting
This commit is contained in:
parent
3cc19bd4ce
commit
87203c1120
6 changed files with 70 additions and 0 deletions
|
@ -136,4 +136,14 @@ WindowManager &ChannelManager::getWindowManager()
|
||||||
return this->windowManager;
|
return this->windowManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChannelManager::doOnAll(std::function<void(std::shared_ptr<TwitchChannel>)> func)
|
||||||
|
{
|
||||||
|
for (const auto &channel : this->twitchChannels) {
|
||||||
|
func(std::get<0>(channel));
|
||||||
|
}
|
||||||
|
|
||||||
|
func(this->whispersChannel);
|
||||||
|
func(this->mentionsChannel);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -32,6 +32,8 @@ public:
|
||||||
EmoteManager &getEmoteManager();
|
EmoteManager &getEmoteManager();
|
||||||
WindowManager &getWindowManager();
|
WindowManager &getWindowManager();
|
||||||
|
|
||||||
|
void doOnAll(std::function<void(std::shared_ptr<twitch::TwitchChannel>)> func);
|
||||||
|
|
||||||
// Special channels
|
// Special channels
|
||||||
const std::shared_ptr<twitch::TwitchChannel> whispersChannel;
|
const std::shared_ptr<twitch::TwitchChannel> whispersChannel;
|
||||||
const std::shared_ptr<twitch::TwitchChannel> mentionsChannel;
|
const std::shared_ptr<twitch::TwitchChannel> mentionsChannel;
|
||||||
|
|
|
@ -53,6 +53,11 @@ IrcManager::IrcManager(ChannelManager &_channelManager, Resources &_resources,
|
||||||
&IrcManager::messageReceived);
|
&IrcManager::messageReceived);
|
||||||
QObject::connect(this->readConnection.get(), &Communi::IrcConnection::privateMessageReceived,
|
QObject::connect(this->readConnection.get(), &Communi::IrcConnection::privateMessageReceived,
|
||||||
this, &IrcManager::privateMessageReceived);
|
this, &IrcManager::privateMessageReceived);
|
||||||
|
|
||||||
|
QObject::connect(this->readConnection.get(), &Communi::IrcConnection::connected, this,
|
||||||
|
&IrcManager::onConnected);
|
||||||
|
QObject::connect(this->readConnection.get(), &Communi::IrcConnection::disconnected, this,
|
||||||
|
&IrcManager::onDisconnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IrcManager::setUser(std::shared_ptr<twitch::TwitchUser> newAccount)
|
void IrcManager::setUser(std::shared_ptr<twitch::TwitchUser> newAccount)
|
||||||
|
@ -370,4 +375,24 @@ void IrcManager::removeIgnoredUser(QString const &username)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IrcManager::onConnected()
|
||||||
|
{
|
||||||
|
std::shared_ptr<Message> msg(Message::createSystemMessage("connected to chat"));
|
||||||
|
|
||||||
|
this->channelManager.doOnAll([msg](std::shared_ptr<twitch::TwitchChannel> channel) {
|
||||||
|
assert(channel);
|
||||||
|
channel->addMessage(msg);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void IrcManager::onDisconnected()
|
||||||
|
{
|
||||||
|
std::shared_ptr<Message> msg(Message::createSystemMessage("disconnected from chat"));
|
||||||
|
|
||||||
|
this->channelManager.doOnAll([msg](std::shared_ptr<twitch::TwitchChannel> channel) {
|
||||||
|
assert(channel);
|
||||||
|
channel->addMessage(msg);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -85,6 +85,9 @@ private:
|
||||||
void handleWhisperMessage(Communi::IrcMessage *message);
|
void handleWhisperMessage(Communi::IrcMessage *message);
|
||||||
void handleUserNoticeMessage(Communi::IrcMessage *message);
|
void handleUserNoticeMessage(Communi::IrcMessage *message);
|
||||||
void handleModeMessage(Communi::IrcMessage *message);
|
void handleModeMessage(Communi::IrcMessage *message);
|
||||||
|
|
||||||
|
void onConnected();
|
||||||
|
void onDisconnected();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -70,5 +70,33 @@ const QString &Message::getId() const
|
||||||
return this->id;
|
return this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Static
|
||||||
|
Message *Message::createSystemMessage(const QString &text)
|
||||||
|
{
|
||||||
|
Message *message = new Message;
|
||||||
|
|
||||||
|
std::time_t t;
|
||||||
|
time(&t);
|
||||||
|
char timeStampBuffer[69];
|
||||||
|
|
||||||
|
// Add word for timestamp with no seconds
|
||||||
|
strftime(timeStampBuffer, 69, "%H:%M", localtime(&t));
|
||||||
|
QString timestampNoSeconds(timeStampBuffer);
|
||||||
|
message->getWords().push_back(Word(timestampNoSeconds, Word::TimestampNoSeconds,
|
||||||
|
MessageColor(MessageColor::System), QString(), QString()));
|
||||||
|
|
||||||
|
// Add word for timestamp with seconds
|
||||||
|
strftime(timeStampBuffer, 69, "%H:%M:%S", localtime(&t));
|
||||||
|
QString timestampWithSeconds(timeStampBuffer);
|
||||||
|
message->getWords().push_back(Word(timestampWithSeconds, Word::TimestampWithSeconds,
|
||||||
|
MessageColor(MessageColor::System), QString(), QString()));
|
||||||
|
|
||||||
|
Word word(text, Word::Type::Default, MessageColor(MessageColor::Type::System), text, text);
|
||||||
|
|
||||||
|
message->getWords().push_back(word);
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace messages
|
} // namespace messages
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -33,6 +33,8 @@ public:
|
||||||
const QString text;
|
const QString text;
|
||||||
bool centered = false;
|
bool centered = false;
|
||||||
|
|
||||||
|
static Message *createSystemMessage(const QString &text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static LazyLoadedImage *badgeStaff;
|
static LazyLoadedImage *badgeStaff;
|
||||||
static LazyLoadedImage *badgeAdmin;
|
static LazyLoadedImage *badgeAdmin;
|
||||||
|
|
Loading…
Reference in a new issue