From 973b7a3bdd1231f44b997731b59b1785e7d3671c Mon Sep 17 00:00:00 2001 From: pajlada Date: Sat, 13 Jul 2024 13:15:11 +0200 Subject: [PATCH] Add extra context to messages that are added to channels, allowing the logging controller to take more responsibility in what messages to log (#5499) Co-auhtored-by: James Upjohn --- CHANGELOG.md | 1 + src/Application.cpp | 38 +++++++++------- src/common/Channel.cpp | 45 ++++++++----------- src/common/Channel.hpp | 11 ++++- src/common/ChannelChatters.cpp | 6 ++- .../commands/builtin/chatterino/Debugging.cpp | 2 +- .../commands/builtin/twitch/Chatters.cpp | 2 +- .../commands/builtin/twitch/GetModerators.cpp | 2 +- .../commands/builtin/twitch/GetVIPs.cpp | 2 +- .../commands/builtin/twitch/SendWhisper.cpp | 10 ++--- .../notifications/NotificationController.cpp | 3 +- src/controllers/plugins/PluginController.cpp | 4 +- src/controllers/plugins/api/ChannelRef.cpp | 2 +- src/providers/irc/AbstractIrcServer.cpp | 6 +-- src/providers/irc/IrcChannel2.cpp | 14 +++++- src/providers/irc/IrcChannel2.hpp | 2 +- src/providers/irc/IrcServer.cpp | 14 +++--- src/providers/twitch/IrcMessageHandler.cpp | 33 ++++++++------ src/providers/twitch/TwitchChannel.cpp | 23 +++++----- src/singletons/ImageUploader.cpp | 2 +- src/singletons/Logging.cpp | 1 + src/widgets/dialogs/EmotePopup.cpp | 18 ++++---- src/widgets/dialogs/ReplyThreadPopup.cpp | 29 ++++++------ src/widgets/dialogs/UserInfoPopup.cpp | 7 +-- src/widgets/helper/ChannelView.cpp | 23 ++++------ src/widgets/helper/SearchPopup.cpp | 2 +- 26 files changed, 163 insertions(+), 139 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7674de6d..25dc4e7ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - Bugfix: Fixed message history occasionally not loading after a sleep. (#5457) - Bugfix: Fixed a crash when tab completing while having an invalid plugin loaded. (#5401) - Bugfix: Fixed windows on Windows not saving correctly when snapping them to the edges. (#5478) +- Bugfix: Fixed user info card popups adding duplicate line to log files. (#5499) - Bugfix: Fixed `/clearmessages` not working with more than one window. (#5489) - Bugfix: Fixed splits staying paused after unfocusing Chatterino in certain configurations. (#5504) - Dev: Update Windows build from Qt 6.5.0 to Qt 6.7.1. (#5420) diff --git a/src/Application.cpp b/src/Application.cpp index cf4e6f07a..2c97b8fd2 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -664,7 +664,7 @@ void Application::initPubSub() postToThread([chan, action] { MessageBuilder msg(action); msg->flags.set(MessageFlag::PubSub); - chan->addMessage(msg.release()); + chan->addMessage(msg.release(), MessageContext::Original); }); }); @@ -703,7 +703,7 @@ void Application::initPubSub() } if (!replaced) { - chan->addMessage(msg); + chan->addMessage(msg, MessageContext::Original); } }); }); @@ -720,7 +720,7 @@ void Application::initPubSub() auto msg = MessageBuilder(action).release(); postToThread([chan, msg] { - chan->addMessage(msg); + chan->addMessage(msg, MessageContext::Original); }); }); @@ -770,8 +770,10 @@ void Application::initPubSub() TwitchMessageBuilder::makeLowTrustUserMessage( action, twitchChannel->getName(), twitchChannel.get()); - twitchChannel->addMessage(p.first); - twitchChannel->addMessage(p.second); + twitchChannel->addMessage(p.first, + MessageContext::Original); + twitchChannel->addMessage(p.second, + MessageContext::Original); }); }); @@ -809,7 +811,7 @@ void Application::initPubSub() postToThread([chan, action] { auto msg = TwitchMessageBuilder::makeLowTrustUpdateMessage(action); - chan->addMessage(msg); + chan->addMessage(msg, MessageContext::Original); }); }); @@ -891,28 +893,32 @@ void Application::initPubSub() const auto p = TwitchMessageBuilder::makeAutomodMessage( action, chan->getName()); - chan->addMessage(p.first); - chan->addMessage(p.second); + chan->addMessage(p.first, MessageContext::Original); + chan->addMessage(p.second, + MessageContext::Original); getIApp() ->getTwitch() ->getAutomodChannel() - ->addMessage(p.first); + ->addMessage(p.first, MessageContext::Original); getIApp() ->getTwitch() ->getAutomodChannel() - ->addMessage(p.second); + ->addMessage(p.second, + MessageContext::Original); if (getSettings()->showAutomodInMentions) { getIApp() ->getTwitch() ->getMentionsChannel() - ->addMessage(p.first); + ->addMessage(p.first, + MessageContext::Original); getIApp() ->getTwitch() ->getMentionsChannel() - ->addMessage(p.second); + ->addMessage(p.second, + MessageContext::Original); } }); } @@ -939,8 +945,8 @@ void Application::initPubSub() postToThread([chan, action] { const auto p = TwitchMessageBuilder::makeAutomodMessage( action, chan->getName()); - chan->addMessage(p.first); - chan->addMessage(p.second); + chan->addMessage(p.first, MessageContext::Original); + chan->addMessage(p.second, MessageContext::Original); }); }); @@ -961,7 +967,7 @@ void Application::initPubSub() auto msg = MessageBuilder(action).release(); postToThread([chan, msg] { - chan->addMessage(msg); + chan->addMessage(msg, MessageContext::Original); }); chan->deleteMessage(msg->id); }); @@ -978,7 +984,7 @@ void Application::initPubSub() postToThread([chan, action] { const auto p = TwitchMessageBuilder::makeAutomodInfoMessage(action); - chan->addMessage(p); + chan->addMessage(p, MessageContext::Original); }); }); diff --git a/src/common/Channel.cpp b/src/common/Channel.cpp index 38d4014aa..afdc99c0b 100644 --- a/src/common/Channel.cpp +++ b/src/common/Channel.cpp @@ -32,6 +32,12 @@ Channel::Channel(const QString &name, Type type) , messages_(getSettings()->scrollbackSplitLimit) , type_(type) { + if (this->isTwitchChannel()) + { + this->platform_ = "twitch"; + } + + // Irc platform is set through IrcChannel2 ctor } Channel::~Channel() @@ -79,37 +85,24 @@ LimitedQueueSnapshot Channel::getMessageSnapshot() return this->messages_.getSnapshot(); } -void Channel::addMessage(MessagePtr message, +void Channel::addMessage(MessagePtr message, MessageContext context, std::optional overridingFlags) { MessagePtr deleted; - if (!overridingFlags || !overridingFlags->has(MessageFlag::DoNotLog)) + if (context == MessageContext::Original) { - QString channelPlatform("other"); - if (this->type_ == Type::Irc) + // Only log original messages + auto isDoNotLogSet = + (overridingFlags && overridingFlags->has(MessageFlag::DoNotLog)) || + message->flags.has(MessageFlag::DoNotLog); + + if (!isDoNotLogSet) { - auto *irc = dynamic_cast(this); - if (irc != nullptr) - { - auto *ircServer = irc->server(); - if (ircServer != nullptr) - { - channelPlatform = QString("irc-%1").arg( - irc->server()->userFriendlyIdentifier()); - } - else - { - channelPlatform = "irc-unknown"; - } - } + // Only log messages where the `DoNotLog` flag is not set + getIApp()->getChatLogger()->addMessage(this->name_, message, + this->platform_); } - else if (this->isTwitchChannel()) - { - channelPlatform = "twitch"; - } - getIApp()->getChatLogger()->addMessage(this->name_, message, - channelPlatform); } if (this->messages_.pushBack(message, deleted)) @@ -123,7 +116,7 @@ void Channel::addMessage(MessagePtr message, void Channel::addSystemMessage(const QString &contents) { auto msg = makeSystemMessage(contents); - this->addMessage(msg); + this->addMessage(msg, MessageContext::Original); } void Channel::addOrReplaceTimeout(MessagePtr message) @@ -134,7 +127,7 @@ void Channel::addOrReplaceTimeout(MessagePtr message) this->replaceMessage(msg, replacement); }, [this](auto msg) { - this->addMessage(msg); + this->addMessage(msg, MessageContext::Original); }, true); diff --git a/src/common/Channel.hpp b/src/common/Channel.hpp index aaea98621..ad4af5114 100644 --- a/src/common/Channel.hpp +++ b/src/common/Channel.hpp @@ -28,6 +28,14 @@ enum class TimeoutStackStyle : int { Default = DontStackBeyondUserMessage, }; +/// Context of the message being added to a channel +enum class MessageContext { + /// This message is the original + Original, + /// This message is a repost of a message that has already been added in a channel + Repost, +}; + class Channel : public std::enable_shared_from_this { public: @@ -79,7 +87,7 @@ public: // 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, + void addMessage(MessagePtr message, MessageContext context, std::optional overridingFlags = std::nullopt); void addMessagesAtStart(const std::vector &messages_); @@ -120,6 +128,7 @@ public: protected: virtual void onConnected(); virtual void messageRemovedFromStart(const MessagePtr &msg); + QString platform_{"other"}; private: const QString name_; diff --git a/src/common/ChannelChatters.cpp b/src/common/ChannelChatters.cpp index d65ae931b..3bb785a0a 100644 --- a/src/common/ChannelChatters.cpp +++ b/src/common/ChannelChatters.cpp @@ -43,7 +43,8 @@ void ChannelChatters::addJoinedUser(const QString &user) TwitchMessageBuilder::listOfUsersSystemMessage( "Users joined:", *joinedUsers, &this->channel_, &builder); builder->flags.set(MessageFlag::Collapsed); - this->channel_.addMessage(builder.release()); + this->channel_.addMessage(builder.release(), + MessageContext::Original); joinedUsers->clear(); this->joinedUsersMergeQueued_ = false; @@ -68,7 +69,8 @@ void ChannelChatters::addPartedUser(const QString &user) TwitchMessageBuilder::listOfUsersSystemMessage( "Users parted:", *partedUsers, &this->channel_, &builder); builder->flags.set(MessageFlag::Collapsed); - this->channel_.addMessage(builder.release()); + this->channel_.addMessage(builder.release(), + MessageContext::Original); partedUsers->clear(); this->partedUsersMergeQueued_ = false; diff --git a/src/controllers/commands/builtin/chatterino/Debugging.cpp b/src/controllers/commands/builtin/chatterino/Debugging.cpp index 52ec87967..1097143a3 100644 --- a/src/controllers/commands/builtin/chatterino/Debugging.cpp +++ b/src/controllers/commands/builtin/chatterino/Debugging.cpp @@ -90,7 +90,7 @@ QString listEnvironmentVariables(const CommandContext &ctx) builder.emplace(QTime::currentTime()); builder.emplace(str, MessageElementFlag::Text, MessageColor::System); - channel->addMessage(builder.release()); + channel->addMessage(builder.release(), MessageContext::Original); } return ""; } diff --git a/src/controllers/commands/builtin/twitch/Chatters.cpp b/src/controllers/commands/builtin/twitch/Chatters.cpp index 0daa75086..602da9cc9 100644 --- a/src/controllers/commands/builtin/twitch/Chatters.cpp +++ b/src/controllers/commands/builtin/twitch/Chatters.cpp @@ -129,7 +129,7 @@ QString testChatters(const CommandContext &ctx) TwitchMessageBuilder::listOfUsersSystemMessage( prefix, entries, twitchChannel, &builder); - channel->addMessage(builder.release()); + channel->addMessage(builder.release(), MessageContext::Original); }, [channel{ctx.channel}](auto error, auto message) { auto errorMessage = formatChattersError(error, message); diff --git a/src/controllers/commands/builtin/twitch/GetModerators.cpp b/src/controllers/commands/builtin/twitch/GetModerators.cpp index b3a1bbe18..8a70f8fa6 100644 --- a/src/controllers/commands/builtin/twitch/GetModerators.cpp +++ b/src/controllers/commands/builtin/twitch/GetModerators.cpp @@ -81,7 +81,7 @@ QString getModerators(const CommandContext &ctx) TwitchMessageBuilder::listOfUsersSystemMessage( "The moderators of this channel are", result, twitchChannel, &builder); - channel->addMessage(builder.release()); + channel->addMessage(builder.release(), MessageContext::Original); }, [channel{ctx.channel}](auto error, auto message) { auto errorMessage = formatModsError(error, message); diff --git a/src/controllers/commands/builtin/twitch/GetVIPs.cpp b/src/controllers/commands/builtin/twitch/GetVIPs.cpp index 94f7d82bb..3b6b98e01 100644 --- a/src/controllers/commands/builtin/twitch/GetVIPs.cpp +++ b/src/controllers/commands/builtin/twitch/GetVIPs.cpp @@ -110,7 +110,7 @@ QString getVIPs(const CommandContext &ctx) TwitchMessageBuilder::listOfUsersSystemMessage( messagePrefix, vipList, twitchChannel, &builder); - channel->addMessage(builder.release()); + channel->addMessage(builder.release(), MessageContext::Original); }, [channel{ctx.channel}](auto error, auto message) { auto errorMessage = formatGetVIPsError(error, message); diff --git a/src/controllers/commands/builtin/twitch/SendWhisper.cpp b/src/controllers/commands/builtin/twitch/SendWhisper.cpp index 694647c8f..aa30e2f15 100644 --- a/src/controllers/commands/builtin/twitch/SendWhisper.cpp +++ b/src/controllers/commands/builtin/twitch/SendWhisper.cpp @@ -177,18 +177,16 @@ bool appendWhisperMessageWordsLocally(const QStringList &words) b->flags.set(MessageFlag::Whisper); auto messagexD = b.release(); - getIApp()->getTwitch()->getWhispersChannel()->addMessage(messagexD); - - auto overrideFlags = std::optional(messagexD->flags); - overrideFlags->set(MessageFlag::DoNotLog); + getIApp()->getTwitch()->getWhispersChannel()->addMessage( + messagexD, MessageContext::Original); if (getSettings()->inlineWhispers && !(getSettings()->streamerModeSuppressInlineWhispers && getIApp()->getStreamerMode()->isEnabled())) { app->getTwitchAbstract()->forEachChannel( - [&messagexD, overrideFlags](ChannelPtr _channel) { - _channel->addMessage(messagexD, overrideFlags); + [&messagexD](ChannelPtr _channel) { + _channel->addMessage(messagexD, MessageContext::Repost); }); } diff --git a/src/controllers/notifications/NotificationController.cpp b/src/controllers/notifications/NotificationController.cpp index cfab7242f..1e30a7497 100644 --- a/src/controllers/notifications/NotificationController.cpp +++ b/src/controllers/notifications/NotificationController.cpp @@ -202,7 +202,8 @@ void NotificationController::checkStream(bool live, QString channelName) } MessageBuilder builder; TwitchMessageBuilder::liveMessage(channelName, &builder); - getIApp()->getTwitch()->getLiveChannel()->addMessage(builder.release()); + getIApp()->getTwitch()->getLiveChannel()->addMessage( + builder.release(), MessageContext::Original); // Indicate that we have pushed notifications for this stream fakeTwitchChannels.push_back(channelName); diff --git a/src/controllers/plugins/PluginController.cpp b/src/controllers/plugins/PluginController.cpp index 2fa2865f4..64e2a96b0 100644 --- a/src/controllers/plugins/PluginController.cpp +++ b/src/controllers/plugins/PluginController.cpp @@ -380,8 +380,8 @@ QString PluginController::tryExecPluginCommand(const QString &commandName, auto res = lua_pcall(L, 1, 0, 0); if (res != LUA_OK) { - ctx.channel->addMessage(makeSystemMessage( - "Lua error: " + lua::humanErrorText(L, res))); + ctx.channel->addSystemMessage("Lua error: " + + lua::humanErrorText(L, res)); return ""; } return ""; diff --git a/src/controllers/plugins/api/ChannelRef.cpp b/src/controllers/plugins/api/ChannelRef.cpp index 1e592d0db..64b146f55 100644 --- a/src/controllers/plugins/api/ChannelRef.cpp +++ b/src/controllers/plugins/api/ChannelRef.cpp @@ -200,7 +200,7 @@ int ChannelRef::add_system_message(lua_State *L) } ChannelPtr that = ChannelRef::getOrError(L); text = text.replace('\n', ' '); - that->addMessage(makeSystemMessage(text)); + that->addSystemMessage(text); return 0; } diff --git a/src/providers/irc/AbstractIrcServer.cpp b/src/providers/irc/AbstractIrcServer.cpp index 5880f2f6a..948a2962d 100644 --- a/src/providers/irc/AbstractIrcServer.cpp +++ b/src/providers/irc/AbstractIrcServer.cpp @@ -156,7 +156,7 @@ void AbstractIrcServer::addGlobalSystemMessage(const QString &messageText) continue; } - chan->addMessage(message); + chan->addMessage(message, MessageContext::Original); } } @@ -329,7 +329,7 @@ void AbstractIrcServer::onReadConnected(IrcConnection *connection) } else { - chan->addMessage(connectedMsg); + chan->addMessage(connectedMsg, MessageContext::Original); } } @@ -357,7 +357,7 @@ void AbstractIrcServer::onDisconnected() continue; } - chan->addMessage(disconnectedMsg); + chan->addMessage(disconnectedMsg, MessageContext::Original); if (auto *channel = dynamic_cast(chan.get())) { diff --git a/src/providers/irc/IrcChannel2.cpp b/src/providers/irc/IrcChannel2.cpp index 0ab537a73..2a2a3be93 100644 --- a/src/providers/irc/IrcChannel2.cpp +++ b/src/providers/irc/IrcChannel2.cpp @@ -17,6 +17,16 @@ IrcChannel::IrcChannel(const QString &name, IrcServer *server) , ChannelChatters(*static_cast(this)) , server_(server) { + auto *ircServer = this->server(); + if (ircServer != nullptr) + { + this->platform_ = + QString("irc-%1").arg(ircServer->userFriendlyIdentifier()); + } + else + { + this->platform_ = "irc-unknown"; + } } void IrcChannel::sendMessage(const QString &message) @@ -70,7 +80,7 @@ void IrcChannel::sendMessage(const QString &message) builder.message().messageText = message; builder.message().searchText = username + ": " + message; - this->addMessage(builder.release()); + this->addMessage(builder.release(), MessageContext::Original); } else { @@ -79,7 +89,7 @@ void IrcChannel::sendMessage(const QString &message) } } -IrcServer *IrcChannel::server() +IrcServer *IrcChannel::server() const { assertInGuiThread(); diff --git a/src/providers/irc/IrcChannel2.hpp b/src/providers/irc/IrcChannel2.hpp index 3e26200dc..75ff40ea4 100644 --- a/src/providers/irc/IrcChannel2.hpp +++ b/src/providers/irc/IrcChannel2.hpp @@ -16,7 +16,7 @@ public: void sendMessage(const QString &message) override; // server may be nullptr - IrcServer *server(); + IrcServer *server() const; // Channel methods bool canReconnect() const override; diff --git a/src/providers/irc/IrcServer.cpp b/src/providers/irc/IrcServer.cpp index 45b073f0e..24b8c39e1 100644 --- a/src/providers/irc/IrcServer.cpp +++ b/src/providers/irc/IrcServer.cpp @@ -111,7 +111,8 @@ void IrcServer::initializeConnectionSignals(IrcConnection *connection, { if (auto shared = weak.lock()) { - shared->addMessage(msg); + shared->addMessage(msg, + MessageContext::Original); } } }); @@ -218,7 +219,7 @@ void IrcServer::privateMessageReceived(Communi::IrcPrivateMessage *message) { if (auto shared = weak.lock()) { - shared->addMessage(msg); + shared->addMessage(msg, MessageContext::Original); } } return; @@ -236,7 +237,7 @@ void IrcServer::privateMessageReceived(Communi::IrcPrivateMessage *message) { auto msg = builder.build(); - channel->addMessage(msg); + channel->addMessage(msg, MessageContext::Original); builder.triggerHighlights(); const auto highlighted = msg->flags.has(MessageFlag::Highlighted); const auto showInMentions = @@ -244,7 +245,8 @@ void IrcServer::privateMessageReceived(Communi::IrcPrivateMessage *message) if (highlighted && showInMentions) { - getIApp()->getTwitch()->getMentionsChannel()->addMessage(msg); + getIApp()->getTwitch()->getMentionsChannel()->addMessage( + msg, MessageContext::Original); } } else @@ -332,7 +334,7 @@ void IrcServer::readConnectionMessageReceived(Communi::IrcMessage *message) { if (auto shared = weak.lock()) { - shared->addMessage(msg); + shared->addMessage(msg, MessageContext::Original); } } }; @@ -366,7 +368,7 @@ void IrcServer::sendWhisper(const QString &target, const QString &message) { if (auto shared = weak.lock()) { - shared->addMessage(msg); + shared->addMessage(msg, MessageContext::Original); } } } diff --git a/src/providers/twitch/IrcMessageHandler.cpp b/src/providers/twitch/IrcMessageHandler.cpp index d42325262..74bc00035 100644 --- a/src/providers/twitch/IrcMessageHandler.cpp +++ b/src/providers/twitch/IrcMessageHandler.cpp @@ -721,7 +721,7 @@ void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message, auto ptr = TwitchMessageBuilder::buildHypeChatMessage(message); if (ptr) { - chan->addMessage(ptr); + chan->addMessage(ptr, MessageContext::Original); } } } @@ -812,7 +812,8 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message) if (clearChat.disableAllMessages) { chan->disableAllMessages(); - chan->addMessage(std::move(clearChat.message)); + chan->addMessage(std::move(clearChat.message), + MessageContext::Original); return; } @@ -868,7 +869,7 @@ void IrcMessageHandler::handleClearMessageMessage(Communi::IrcMessage *message) { MessageBuilder builder; TwitchMessageBuilder::deletionMessage(msg, &builder); - chan->addMessage(builder.release()); + chan->addMessage(builder.release(), MessageContext::Original); } } @@ -966,10 +967,11 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *ircMessage) if (message->flags.has(MessageFlag::ShowInMentions)) { - getIApp()->getTwitch()->getMentionsChannel()->addMessage(message); + getIApp()->getTwitch()->getMentionsChannel()->addMessage( + message, MessageContext::Original); } - c->addMessage(message); + c->addMessage(message, MessageContext::Original); auto overrideFlags = std::optional(message->flags); overrideFlags->set(MessageFlag::DoNotTriggerNotification); @@ -981,7 +983,8 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *ircMessage) { getIApp()->getTwitchAbstract()->forEachChannel( [&message, overrideFlags](ChannelPtr channel) { - channel->addMessage(message, overrideFlags); + channel->addMessage(message, MessageContext::Repost, + overrideFlags); }); } } @@ -1098,7 +1101,7 @@ void IrcMessageHandler::handleUserNoticeMessage( if (!chan->isEmpty()) { - chan->addMessage(newMessage); + chan->addMessage(newMessage, MessageContext::Original); } } } @@ -1117,7 +1120,7 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message) // channels getIApp()->getTwitch()->forEachChannelAndSpecialChannels( [msg](const auto &c) { - c->addMessage(msg); + c->addMessage(msg, MessageContext::Original); }); return; @@ -1167,7 +1170,7 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message) MessageBuilder builder; TwitchMessageBuilder::hostingSystemMessage(hostedChannelName, &builder, hostOn); - channel->addMessage(builder.release()); + channel->addMessage(builder.release(), MessageContext::Original); } else if (tags == "room_mods" || tags == "vips_success") { @@ -1196,11 +1199,11 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message) users.sort(Qt::CaseInsensitive); TwitchMessageBuilder::listOfUsersSystemMessage(msgParts.at(0), users, tc, &builder); - channel->addMessage(builder.release()); + channel->addMessage(builder.release(), MessageContext::Original); } else { - channel->addMessage(msg); + channel->addMessage(msg, MessageContext::Original); } } } @@ -1249,7 +1252,8 @@ void IrcMessageHandler::handlePartMessage(Communi::IrcMessage *message) if (message->nick() == selfAccountName) { - channel->addMessage(generateBannedMessage(false)); + channel->addMessage(generateBannedMessage(false), + MessageContext::Original); } } @@ -1460,10 +1464,11 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message, if (highlighted && showInMentions) { - server.getMentionsChannel()->addMessage(msg); + server.getMentionsChannel()->addMessage(msg, + MessageContext::Original); } - chan->addMessage(msg); + chan->addMessage(msg, MessageContext::Original); if (auto *chatters = dynamic_cast(chan.get())) { chatters->addRecentChatter(msg->displayName); diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index 4216dfd26..f57081c86 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -161,7 +161,7 @@ TwitchChannel::TwitchChannel(const QString &name) TwitchMessageBuilder::liveSystemMessage(this->getDisplayName(), &builder); builder.message().id = this->roomId(); - this->addMessage(builder.release()); + this->addMessage(builder.release(), MessageContext::Original); // Message in /live channel MessageBuilder builder2; @@ -169,7 +169,7 @@ TwitchChannel::TwitchChannel(const QString &name) &builder2); builder2.message().id = this->roomId(); getIApp()->getTwitch()->getLiveChannel()->addMessage( - builder2.release()); + builder2.release(), MessageContext::Original); // Notify on all channels with a ping sound if (getSettings()->notificationOnAnyChannel && @@ -187,7 +187,7 @@ TwitchChannel::TwitchChannel(const QString &name) MessageBuilder builder; TwitchMessageBuilder::offlineSystemMessage(this->getDisplayName(), &builder); - this->addMessage(builder.release()); + this->addMessage(builder.release(), MessageContext::Original); // "delete" old 'CHANNEL is live' message LimitedQueueSnapshot snapshot = @@ -395,7 +395,7 @@ void TwitchChannel::addChannelPointReward(const ChannelPointReward &reward) MessageBuilder builder; TwitchMessageBuilder::appendChannelPointRewardMessage( reward, &builder, this->isMod(), this->isBroadcaster()); - this->addMessage(builder.release()); + this->addMessage(builder.release(), MessageContext::Original); return; } @@ -566,7 +566,7 @@ void TwitchChannel::showLoginMessage() linkColor) ->setLink(accountsLink); - this->addMessage(builder.release()); + this->addMessage(builder.release(), MessageContext::Original); } void TwitchChannel::roomIdChanged() @@ -925,7 +925,7 @@ void TwitchChannel::updateBttvEmote( auto builder = MessageBuilder(liveUpdatesUpdateEmoteMessage, "BTTV", QString() /* actor */, newEmote->name.string, oldEmote->name.string); - this->addMessage(builder.release()); + this->addMessage(builder.release(), MessageContext::Original); } void TwitchChannel::removeBttvEmote( @@ -964,7 +964,7 @@ void TwitchChannel::updateSeventvEmote( auto builder = MessageBuilder(liveUpdatesUpdateEmoteMessage, "7TV", dispatch.actorName, dispatch.emoteName, dispatch.oldEmoteName); - this->addMessage(builder.release()); + this->addMessage(builder.release(), MessageContext::Original); } void TwitchChannel::removeSeventvEmote( @@ -1002,7 +1002,8 @@ void TwitchChannel::updateSeventvUser( auto builder = MessageBuilder(liveUpdatesUpdateEmoteSetMessage, "7TV", dispatch.actorName, name); - this->addMessage(builder.release()); + this->addMessage(builder.release(), + MessageContext::Original); } }); }, @@ -1085,7 +1086,7 @@ void TwitchChannel::addOrReplaceLiveUpdatesAddRemove(bool isEmoteAdd, this->lastLiveUpdateEmotePlatform_ = platform; this->lastLiveUpdateMessage_ = msg; this->lastLiveUpdateEmoteActor_ = actor; - this->addMessage(msg); + this->addMessage(msg, MessageContext::Original); } bool TwitchChannel::tryReplaceLastLiveUpdateAddOrRemove( @@ -1650,7 +1651,7 @@ void TwitchChannel::createClip() MessageColor::Link) ->setLink(Link(Link::Url, clip.editUrl)); - this->addMessage(builder.release()); + this->addMessage(builder.release(), MessageContext::Original); }, // failureCallback [this](auto error) { @@ -1699,7 +1700,7 @@ void TwitchChannel::createClip() builder.message().messageText = text; builder.message().searchText = text; - this->addMessage(builder.release()); + this->addMessage(builder.release(), MessageContext::Original); }, // finallyCallback - this will always execute, so clip creation won't ever be stuck [this] { diff --git a/src/singletons/ImageUploader.cpp b/src/singletons/ImageUploader.cpp index f0b920464..b6a191e85 100644 --- a/src/singletons/ImageUploader.cpp +++ b/src/singletons/ImageUploader.cpp @@ -239,7 +239,7 @@ void ImageUploader::handleSuccessfulUpload(const NetworkResult &result, auto timeToUpload = this->uploadQueue_.size() * (UPLOAD_DELAY / 1000 + 1); MessageBuilder builder(imageUploaderResultMessage, link, deletionLink, this->uploadQueue_.size(), timeToUpload); - channel->addMessage(builder.release()); + channel->addMessage(builder.release(), MessageContext::Original); if (this->uploadQueue_.empty()) { this->uploadMutex_.unlock(); diff --git a/src/singletons/Logging.cpp b/src/singletons/Logging.cpp index 8ea65289c..d8bb57127 100644 --- a/src/singletons/Logging.cpp +++ b/src/singletons/Logging.cpp @@ -1,5 +1,6 @@ #include "singletons/Logging.hpp" +#include "messages/Message.hpp" #include "singletons/helper/LoggingChannel.hpp" #include "singletons/Paths.hpp" #include "singletons/Settings.hpp" diff --git a/src/widgets/dialogs/EmotePopup.cpp b/src/widgets/dialogs/EmotePopup.cpp index 989233ff7..d771008ca 100644 --- a/src/widgets/dialogs/EmotePopup.cpp +++ b/src/widgets/dialogs/EmotePopup.cpp @@ -145,7 +145,7 @@ void addTwitchEmoteSets( auto currentChannelPair = mapOfSets[currentChannelName]; for (const auto &message : currentChannelPair.second) { - subChannel.addMessage(message); + subChannel.addMessage(message, MessageContext::Original); } mapOfSets.remove(currentChannelName); @@ -154,7 +154,7 @@ void addTwitchEmoteSets( auto &channel = pair.first ? globalChannel : subChannel; for (const auto &message : pair.second) { - channel.addMessage(message); + channel.addMessage(message, MessageContext::Original); } } } @@ -162,14 +162,16 @@ void addTwitchEmoteSets( void addEmotes(Channel &channel, const EmoteMap &map, const QString &title, const MessageElementFlag &emoteFlag) { - channel.addMessage(makeTitleMessage(title)); - channel.addMessage(makeEmoteMessage(map, emoteFlag)); + channel.addMessage(makeTitleMessage(title), MessageContext::Original); + channel.addMessage(makeEmoteMessage(map, emoteFlag), + MessageContext::Original); } void loadEmojis(ChannelView &view, const std::vector &emojiMap) { ChannelPtr emojiChannel(new Channel("", Channel::Type::None)); - emojiChannel->addMessage(makeEmojiMessage(emojiMap)); + emojiChannel->addMessage(makeEmojiMessage(emojiMap), + MessageContext::Original); view.setChannel(emojiChannel); } @@ -177,8 +179,8 @@ void loadEmojis(ChannelView &view, const std::vector &emojiMap) void loadEmojis(Channel &channel, const std::vector &emojiMap, const QString &title) { - channel.addMessage(makeTitleMessage(title)); - channel.addMessage(makeEmojiMessage(emojiMap)); + channel.addMessage(makeTitleMessage(title), MessageContext::Original); + channel.addMessage(makeEmojiMessage(emojiMap), MessageContext::Original); } // Create an emote @@ -454,7 +456,7 @@ void EmotePopup::loadChannel(ChannelPtr channel) builder.emplace("no subscription emotes available", MessageElementFlag::Text, MessageColor::System); - subChannel->addMessage(builder.release()); + subChannel->addMessage(builder.release(), MessageContext::Original); } } diff --git a/src/widgets/dialogs/ReplyThreadPopup.cpp b/src/widgets/dialogs/ReplyThreadPopup.cpp index 4d3dd3a83..fb35e9818 100644 --- a/src/widgets/dialogs/ReplyThreadPopup.cpp +++ b/src/widgets/dialogs/ReplyThreadPopup.cpp @@ -244,7 +244,8 @@ void ReplyThreadPopup::addMessagesFromThread() std::optional(this->thread_->root()->flags); rootOverrideFlags->set(MessageFlag::DoNotLog); - this->virtualChannel_->addMessage(this->thread_->root(), rootOverrideFlags); + this->virtualChannel_->addMessage( + this->thread_->root(), MessageContext::Repost, rootOverrideFlags); for (const auto &msgRef : this->thread_->replies()) { if (auto msg = msgRef.lock()) @@ -252,24 +253,26 @@ void ReplyThreadPopup::addMessagesFromThread() auto overrideFlags = std::optional(msg->flags); overrideFlags->set(MessageFlag::DoNotLog); - this->virtualChannel_->addMessage(msg, overrideFlags); + this->virtualChannel_->addMessage(msg, MessageContext::Repost, + overrideFlags); } } this->messageConnection_ = std::make_unique( - sourceChannel->messageAppended.connect([this](MessagePtr &message, - auto) { - if (message->replyThread == this->thread_) - { - auto overrideFlags = - std::optional(message->flags); - overrideFlags->set(MessageFlag::DoNotLog); + sourceChannel->messageAppended.connect( + [this](MessagePtr &message, auto) { + if (message->replyThread == this->thread_) + { + auto overrideFlags = + std::optional(message->flags); + overrideFlags->set(MessageFlag::DoNotLog); - // same reply thread, add message - this->virtualChannel_->addMessage(message, overrideFlags); - } - })); + // same reply thread, add message + this->virtualChannel_->addMessage( + message, MessageContext::Repost, overrideFlags); + } + })); } void ReplyThreadPopup::updateInputUI() diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index 683cba271..afd28d4fb 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -112,12 +112,9 @@ namespace { { MessagePtr message = snapshot[i]; - auto overrideFlags = std::optional(message->flags); - overrideFlags->set(MessageFlag::DoNotLog); - if (checkMessageUserName(userName, message)) { - channelPtr->addMessage(message, overrideFlags); + channelPtr->addMessage(message, MessageContext::Repost); } } @@ -787,7 +784,7 @@ void UserInfoPopup::updateLatestMessages() { // display message in ChannelView this->ui_.latestMessages->channel()->addMessage( - message); + message, MessageContext::Repost); } else { diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 00469e0a9..26e31c9bf 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -925,26 +925,17 @@ void ChannelView::setChannel(const ChannelPtr &underlyingChannel) { if (this->channel_->lastDate_ != QDate::currentDate()) { + // Day change message this->channel_->lastDate_ = QDate::currentDate(); auto msg = makeSystemMessage( QLocale().toString(QDate::currentDate(), QLocale::LongFormat), QTime(0, 0)); - this->channel_->addMessage(msg); + msg->flags.set(MessageFlag::DoNotLog); + this->channel_->addMessage(msg, MessageContext::Original); } - // When the message was received in the underlyingChannel, - // logging will be handled. Prevent duplications. - if (overridingFlags) - { - overridingFlags->set(MessageFlag::DoNotLog); - } - else - { - overridingFlags = MessageFlags(message->flags); - overridingFlags->set(MessageFlag::DoNotLog); - } - - this->channel_->addMessage(message, overridingFlags); + this->channel_->addMessage(message, MessageContext::Repost, + overridingFlags); } }); @@ -1010,7 +1001,9 @@ void ChannelView::setChannel(const ChannelPtr &underlyingChannel) } this->messages_.pushBack(messageLayout); - this->channel_->addMessage(msg); + + this->channel_->addMessage(msg, MessageContext::Repost); + nMessagesAdded++; if (this->showScrollbarHighlights()) { diff --git a/src/widgets/helper/SearchPopup.cpp b/src/widgets/helper/SearchPopup.cpp index 1f7347626..fb8dfee8b 100644 --- a/src/widgets/helper/SearchPopup.cpp +++ b/src/widgets/helper/SearchPopup.cpp @@ -55,7 +55,7 @@ ChannelPtr SearchPopup::filter(const QString &text, const QString &channelName, auto overrideFlags = std::optional(message->flags); overrideFlags->set(MessageFlag::DoNotLog); - channel->addMessage(message, overrideFlags); + channel->addMessage(message, MessageContext::Repost, overrideFlags); } }