Skip to content

Commit

Permalink
Merge pull request #1484 from nextcloud/get-elementcolor-only-when-ne…
Browse files Browse the repository at this point in the history
…eded

Only query for elementColor when really needed
  • Loading branch information
Ivansss authored Jan 10, 2024
2 parents 9b3e2dc + 564f8ec commit e8cb87b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions NextcloudTalk/NCChatMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ - (NSMutableAttributedString *)parsedMessage
}

UIColor *defaultColor = [NCAppBranding chatForegroundColor];
UIColor *highlightedColor = [NCAppBranding elementColor];

NSMutableAttributedString *attributedMessage = [[NSMutableAttributedString alloc] initWithString:parsedMessage];
[attributedMessage addAttribute:NSForegroundColorAttributeName value:defaultColor range:NSMakeRange(0, parsedMessage.length)];
Expand All @@ -486,11 +485,24 @@ - (NSMutableAttributedString *)parsedMessage
[attributedMessage addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16.0f] range:NSMakeRange(0, parsedMessage.length)];
}

UIColor *highlightedColor = nil;

for (NCMessageParameter *param in parameters) {
//Set color for mentions
if ([param.type isEqualToString:@"user"] || [param.type isEqualToString:@"guest"] ||
[param.type isEqualToString:@"user-group"] || [param.type isEqualToString:@"call"]) {
[attributedMessage addAttribute:NSForegroundColorAttributeName value:(param.shouldBeHighlighted) ? highlightedColor : defaultColor range:param.range];

if (param.shouldBeHighlighted) {
if (!highlightedColor) {
// Only get the elementColor if we really need it to reduce realm queries
highlightedColor = [NCAppBranding elementColor];
}

[attributedMessage addAttribute:NSForegroundColorAttributeName value:highlightedColor range:param.range];
} else {
[attributedMessage addAttribute:NSForegroundColorAttributeName value:defaultColor range:param.range];
}

[attributedMessage addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:16.0f] range:param.range];
}
//Create a link if parameter contains a link
Expand Down

0 comments on commit e8cb87b

Please sign in to comment.