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 <jupjohn@jammeh.co.nz>
This commit is contained in:
+19
-26
@@ -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<MessagePtr> Channel::getMessageSnapshot()
|
||||
return this->messages_.getSnapshot();
|
||||
}
|
||||
|
||||
void Channel::addMessage(MessagePtr message,
|
||||
void Channel::addMessage(MessagePtr message, MessageContext context,
|
||||
std::optional<MessageFlags> 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<IrcChannel *>(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);
|
||||
|
||||
|
||||
+10
-1
@@ -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<Channel>
|
||||
{
|
||||
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<MessageFlags> overridingFlags = std::nullopt);
|
||||
void addMessagesAtStart(const std::vector<MessagePtr> &messages_);
|
||||
|
||||
@@ -120,6 +128,7 @@ public:
|
||||
protected:
|
||||
virtual void onConnected();
|
||||
virtual void messageRemovedFromStart(const MessagePtr &msg);
|
||||
QString platform_{"other"};
|
||||
|
||||
private:
|
||||
const QString name_;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user