From d59bb805bba6aae3f17472755bd1d0439b05fafe Mon Sep 17 00:00:00 2001 From: apa420 <17131426+apa420@users.noreply.github.com> Date: Sun, 9 May 2021 18:44:57 +0200 Subject: [PATCH] Added system message on new date (#2748) Co-authored-by: pajlada --- CHANGELOG.md | 1 + src/common/Channel.cpp | 1 + src/common/Channel.hpp | 2 ++ src/providers/twitch/TwitchChannel.cpp | 18 ++++++++++++++++++ src/widgets/helper/ChannelView.cpp | 11 +++++++++++ 5 files changed, 33 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1e23665..5d4cc1ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unversioned - 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: 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) diff --git a/src/common/Channel.cpp b/src/common/Channel.cpp index 9d8b3ba6..887beb2a 100644 --- a/src/common/Channel.cpp +++ b/src/common/Channel.cpp @@ -24,6 +24,7 @@ namespace chatterino { // Channel::Channel(const QString &name, Type type) : completionModel(*this) + , lastDate_(QDate::currentDate()) , name_(name) , type_(type) { diff --git a/src/common/Channel.hpp b/src/common/Channel.hpp index 6b83c90e..0c324173 100644 --- a/src/common/Channel.hpp +++ b/src/common/Channel.hpp @@ -4,6 +4,7 @@ #include "common/FlagsEnum.hpp" #include "messages/LimitedQueue.hpp" +#include #include #include #include @@ -97,6 +98,7 @@ public: static std::shared_ptr getEmpty(); CompletionModel completionModel; + QDate lastDate_; protected: virtual void onConnected(); diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index de9392cc..b7115183 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -744,6 +744,24 @@ void TwitchChannel::loadRecentMessages() 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 : handler.parseMessage(shared.get(), message)) { diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 9c416cc5..64477525 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1,6 +1,7 @@ #include "ChannelView.hpp" #include +#include #include #include #include @@ -22,6 +23,7 @@ #include "messages/Emote.hpp" #include "messages/LimitedQueueSnapshot.hpp" #include "messages/Message.hpp" +#include "messages/MessageBuilder.hpp" #include "messages/MessageElement.hpp" #include "messages/layouts/MessageLayout.hpp" #include "messages/layouts/MessageLayoutElement.hpp" @@ -602,6 +604,15 @@ void ChannelView::setChannel(ChannelPtr underlyingChannel) boost::optional overridingFlags) { 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, // logging will be handled. Prevent duplications. if (overridingFlags)