summaryrefslogtreecommitdiff
path: root/Juick/Views
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-11-29 23:12:11 +0300
committerGravatar Vitaly Takmazov2018-11-29 23:12:11 +0300
commit322d043149fb11a9545af90df78553d6d4edf1d5 (patch)
tree3945f4eb482e7908c255709f3ed76265cf0e4b23 /Juick/Views
parente8e91d0aedc0fec47258089911d49c900e55a5f5 (diff)
Fix crash when entity text is empty
Diffstat (limited to 'Juick/Views')
-rw-r--r--Juick/Views/MessageCell.m19
1 files changed, 10 insertions, 9 deletions
diff --git a/Juick/Views/MessageCell.m b/Juick/Views/MessageCell.m
index b82d0a1..faf3492 100644
--- a/Juick/Views/MessageCell.m
+++ b/Juick/Views/MessageCell.m
@@ -78,14 +78,15 @@
attributes:@{NSFontAttributeName:[UIFont preferredFontForTextStyle:UIFontTextStyleBody]}];
[txt beginEditing];
for (NSDictionary *entity in msg.entities) {
- NSUInteger start = [[entity objectForKey:@"start"] unsignedIntegerValue];
- NSUInteger end = [[entity objectForKey:@"end"] unsignedIntegerValue];
+ NSUInteger start = [entity[@"start"] unsignedIntegerValue];
+ NSUInteger end = [entity[@"end"] unsignedIntegerValue];
+ NSString *text = entity[@"text"] ? entity[@"text"] : @"";
NSRange currentRange = NSMakeRange(start, end - start);
- [txt addAttribute:@"displayText" value:[entity objectForKey:@"text"] range:currentRange];
- if ([[entity objectForKey:@"type"] isEqualToString:@"a"]) {
- [txt addAttribute:NSLinkAttributeName value:[entity objectForKey:@"url"] range:currentRange];
+ [txt addAttribute:@"displayText" value:text range:currentRange];
+ if ([entity[@"type"] isEqualToString:@"a"]) {
+ [txt addAttribute:NSLinkAttributeName value:entity[@"url"] range:currentRange];
}
- if ([[entity objectForKey:@"type"] isEqualToString:@"q"]) {
+ if ([entity[@"type"] isEqualToString:@"q"]) {
[txt addAttribute:NSForegroundColorAttributeName value:[UIColor darkGrayColor] range:currentRange];
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.firstLineHeadIndent = 12.0f;
@@ -93,18 +94,18 @@
paragraphStyle.paragraphSpacing = 12.0f;
[txt addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:currentRange];
}
- if ([[entity objectForKey:@"type"] isEqualToString:@"u"]) {
+ if ([entity[@"type"] isEqualToString:@"u"]) {
[txt addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:currentRange];
}
UIFontDescriptor* fontDescriptor = [UIFontDescriptor
preferredFontDescriptorWithTextStyle:UIFontTextStyleBody];
- if ([[entity objectForKey:@"type"] isEqualToString:@"b"]) {
+ if ([entity[@"type"] isEqualToString:@"b"]) {
UIFontDescriptor* boldFontDescriptor = [fontDescriptor
fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold];
UIFont* boldFont = [UIFont fontWithDescriptor:boldFontDescriptor size: 0.0];
[txt addAttribute:NSFontAttributeName value:boldFont range:currentRange];
}
- if ([[entity objectForKey:@"type"] isEqualToString:@"i"]) {
+ if ([entity[@"type"] isEqualToString:@"i"]) {
UIFontDescriptor* italicFontDescriptor = [fontDescriptor
fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitItalic];
UIFont* italicFont = [UIFont fontWithDescriptor:italicFontDescriptor size: 0.0];