Added system message on new date (#2748)

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
apa420 2021-05-09 18:44:57 +02:00 committed by GitHub
parent dcd65b5978
commit d59bb805bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 0 deletions

View file

@ -3,6 +3,7 @@
## Unversioned ## Unversioned
- Major: New split for channels going live! /live. (#1797) - Major: New split for channels going live! /live. (#1797)
- Minor: Added a message that displays a new date on new day. (#1016)
- Minor: Hosting messages are now clickable. (#2655) - Minor: Hosting messages are now clickable. (#2655)
- Minor: Messages held by automod are now shown to the user. (#2626) - Minor: Messages held by automod are now shown to the user. (#2626)
- Bugfix: Strip newlines from stream titles to prevent text going off of split header (#2755) - Bugfix: Strip newlines from stream titles to prevent text going off of split header (#2755)

View file

@ -24,6 +24,7 @@ namespace chatterino {
// //
Channel::Channel(const QString &name, Type type) Channel::Channel(const QString &name, Type type)
: completionModel(*this) : completionModel(*this)
, lastDate_(QDate::currentDate())
, name_(name) , name_(name)
, type_(type) , type_(type)
{ {

View file

@ -4,6 +4,7 @@
#include "common/FlagsEnum.hpp" #include "common/FlagsEnum.hpp"
#include "messages/LimitedQueue.hpp" #include "messages/LimitedQueue.hpp"
#include <QDate>
#include <QString> #include <QString>
#include <QTimer> #include <QTimer>
#include <boost/optional.hpp> #include <boost/optional.hpp>
@ -97,6 +98,7 @@ public:
static std::shared_ptr<Channel> getEmpty(); static std::shared_ptr<Channel> getEmpty();
CompletionModel completionModel; CompletionModel completionModel;
QDate lastDate_;
protected: protected:
virtual void onConnected(); virtual void onConnected();

View file

@ -744,6 +744,24 @@ void TwitchChannel::loadRecentMessages()
for (auto message : messages) for (auto message : messages)
{ {
if (message->tags().contains("rm-received-ts"))
{
QDate msgDate = QDateTime::fromMSecsSinceEpoch(
message->tags()
.value("rm-received-ts")
.toLongLong())
.date();
if (msgDate != shared.get()->lastDate_)
{
shared.get()->lastDate_ = msgDate;
auto msg = makeSystemMessage(
msgDate.toString(Qt::SystemLocaleLongDate),
QTime(0, 0));
msg->flags.set(MessageFlag::RecentMessage);
allBuiltMessages.emplace_back(msg);
}
}
for (auto builtMessage : for (auto builtMessage :
handler.parseMessage(shared.get(), message)) handler.parseMessage(shared.get(), message))
{ {

View file

@ -1,6 +1,7 @@
#include "ChannelView.hpp" #include "ChannelView.hpp"
#include <QClipboard> #include <QClipboard>
#include <QDate>
#include <QDebug> #include <QDebug>
#include <QDesktopServices> #include <QDesktopServices>
#include <QGraphicsBlurEffect> #include <QGraphicsBlurEffect>
@ -22,6 +23,7 @@
#include "messages/Emote.hpp" #include "messages/Emote.hpp"
#include "messages/LimitedQueueSnapshot.hpp" #include "messages/LimitedQueueSnapshot.hpp"
#include "messages/Message.hpp" #include "messages/Message.hpp"
#include "messages/MessageBuilder.hpp"
#include "messages/MessageElement.hpp" #include "messages/MessageElement.hpp"
#include "messages/layouts/MessageLayout.hpp" #include "messages/layouts/MessageLayout.hpp"
#include "messages/layouts/MessageLayoutElement.hpp" #include "messages/layouts/MessageLayoutElement.hpp"
@ -602,6 +604,15 @@ void ChannelView::setChannel(ChannelPtr underlyingChannel)
boost::optional<MessageFlags> overridingFlags) { boost::optional<MessageFlags> overridingFlags) {
if (this->shouldIncludeMessage(message)) if (this->shouldIncludeMessage(message))
{ {
if (this->channel_->lastDate_ != QDate::currentDate())
{
this->channel_->lastDate_ = QDate::currentDate();
auto msg =
makeSystemMessage(QDate::currentDate().toString(
Qt::SystemLocaleLongDate),
QTime(0, 0));
this->channel_->addMessage(msg);
}
// When the message was received in the underlyingChannel, // When the message was received in the underlyingChannel,
// logging will be handled. Prevent duplications. // logging will be handled. Prevent duplications.
if (overridingFlags) if (overridingFlags)