+
+ // Cached per network
+ const NetworkId& netId = msg.bufferInfo().networkId();
+ const Network* net = Client::network(netId);
+
+ if (net && !net->myNick().isEmpty()) {
+ // Get current nick
+ QString currentNick = net->myNick();
+ // Get identity nicks
+ QStringList identityNicks = {};
+ const Identity* myIdentity = Client::identity(net->identity());
+ if (myIdentity) {
+ identityNicks = myIdentity->nicks();
+ }
+
+ // Get buffer name, message contents
+ QString bufferName = msg.bufferInfo().bufferName();
+ QString msgContents = msg.contents();
+ bool matches = false;
+
+ for (int i = 0; i < _highlightRuleList.count(); i++) {
+ auto& rule = _highlightRuleList.at(i);
+ if (!rule.isEnabled())
+ continue;
+
+ // Skip if channel name doesn't match and channel rule is not empty
+ //
+ // Match succeeds if...
+ // Channel name matches a defined rule
+ // Defined rule is empty
+ // And take the inverse of the above
+ if (!rule.chanNameMatcher().match(bufferName, true)) {
+ // A channel name rule is specified and does NOT match the current buffer name, skip
+ // this rule
+ continue;
+ }
+
+ // Check message according to specified rule, allowing empty rules to match
+ bool contentsMatch = rule.contentsMatcher().match(stripFormatCodes(msgContents), true);
+
+ // Support for sender matching can be added here
+
+ if (contentsMatch) {
+ // Support for inverse rules can be added here
+ matches = true;
+ }
+ }
+
+ if (matches) {
+ msg.setFlags(msg.flags() | Message::Highlight);
+ return;
+ }
+
+ // Check nicknames
+ if (_highlightNick != HighlightNickType::NoNick && !currentNick.isEmpty()) {
+ // Nickname matching allowed and current nickname is known
+ // Run the nickname matcher on the unformatted string
+ if (_nickMatcher.match(stripFormatCodes(msgContents), netId, currentNick, identityNicks)) {
+ msg.setFlags(msg.flags() | Message::Highlight);
+ return;
+ }
+ }