Skip to content

Commit

Permalink
Only query for elementColor when really needed
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <[email protected]>
  • Loading branch information
SystemKeeper committed Jan 9, 2024
1 parent 84201dc commit 564f8ec
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 564f8ec

Please sign in to comment.