summaryrefslogtreecommitdiff
path: root/Juick/Views/MessageCell.m
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-11-12 14:39:31 +0300
committerGravatar Vitaly Takmazov2018-11-12 14:39:31 +0300
commitb6dc38e5f6bb7a1b820cd23d761484610212c11d (patch)
tree2a2df5f2cf57df73a6b12f86c21607ae26294bad /Juick/Views/MessageCell.m
parent4dbf1bdf6ce14800bb4e67b6d0ee8bb782564f0f (diff)
Entities
Diffstat (limited to 'Juick/Views/MessageCell.m')
-rw-r--r--Juick/Views/MessageCell.m43
1 files changed, 42 insertions, 1 deletions
diff --git a/Juick/Views/MessageCell.m b/Juick/Views/MessageCell.m
index 851e097..99fb296 100644
--- a/Juick/Views/MessageCell.m
+++ b/Juick/Views/MessageCell.m
@@ -9,6 +9,7 @@
#import "MessageCell.h"
#import "ColorScheme.h"
#import "APIClient.h"
+#import "Entity.h"
@implementation MessageCell
@@ -70,7 +71,47 @@
} else {
self.summary.text = nil;
}
- self.text.text = [msg.text stringByDecodingHTMLEntities];
+ self.text.attributedText = nil;
+ if (msg.text) {
+ NSMutableAttributedString *txt = [[NSMutableAttributedString alloc] initWithString:[msg.text stringByDecodingHTMLEntities] 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];
+ 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];
+ }
+ if ([[entity objectForKey:@"type"] isEqualToString:@"q"]) {
+ [txt addAttribute:NSForegroundColorAttributeName value:[UIColor darkGrayColor] range:currentRange];
+ }
+ if ([[entity objectForKey:@"type"] isEqualToString:@"u"]) {
+ [txt addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:currentRange];
+ }
+ UIFontDescriptor* fontDescriptor = [UIFontDescriptor
+ preferredFontDescriptorWithTextStyle:UIFontTextStyleBody];
+ if ([[entity objectForKey:@"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"]) {
+ UIFontDescriptor* italicFontDescriptor = [fontDescriptor
+ fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitItalic];
+ UIFont* italicFont = [UIFont fontWithDescriptor:italicFontDescriptor size: 0.0];
+ [txt addAttribute:NSFontAttributeName value:italicFont range:currentRange];
+ }
+ }
+ [txt enumerateAttribute:@"displayText" inRange:NSMakeRange(0, [txt length]) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
+ if (value) {
+ [txt replaceCharactersInRange:range withString:value];
+ }
+ }];
+ [txt endEditing];
+ self.text.attributedText = txt;
+ }
[self.tags removeAllTags];
if ([msg.tags count] > 0) {
[msg.tags enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {