Merge pull request #1484 from nextcloud/get-elementcolor-only-when-needed

Only query for elementColor when really needed
This commit is contained in:
Ivan Sein 2024-01-10 17:25:41 +01:00 коммит произвёл GitHub
Родитель 9b3e2dcf8f 564f8ec8b1
Коммит e8cb87be6c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 14 добавлений и 2 удалений

Просмотреть файл

@ -475,7 +475,6 @@ NSString * const kSharedItemTypeRecording = @"recording";
}
UIColor *defaultColor = [NCAppBranding chatForegroundColor];
UIColor *highlightedColor = [NCAppBranding elementColor];
NSMutableAttributedString *attributedMessage = [[NSMutableAttributedString alloc] initWithString:parsedMessage];
[attributedMessage addAttribute:NSForegroundColorAttributeName value:defaultColor range:NSMakeRange(0, parsedMessage.length)];
@ -486,11 +485,24 @@ NSString * const kSharedItemTypeRecording = @"recording";
[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