From d60f49d8fa532f68bd028811e70555c6947fa005 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Tue, 1 Mar 2016 16:53:08 -0500 Subject: [PATCH] Improve display of a contact's URLs Ensure the URL is valid and begins with a schema. --- UI/Contacts/UIxContactView.m | 39 +++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/UI/Contacts/UIxContactView.m b/UI/Contacts/UIxContactView.m index 758209d2a..096e0054b 100644 --- a/UI/Contacts/UIxContactView.m +++ b/UI/Contacts/UIxContactView.m @@ -560,6 +560,43 @@ return categories; } +- (NSArray *) urls +{ + NSMutableArray *urls; + NSMutableDictionary *attrs; + NSArray *values; + NSString *type, *value; + NSURL *url; + CardElement *element; + NSUInteger count, max; + + values = [card childrenWithTag: @"url"]; + max = [values count]; + if (max > 0) + { + urls = [NSMutableArray arrayWithCapacity: max]; + for (count = 0; count < max; count++) + { + attrs = [NSMutableDictionary dictionary]; + element = [values objectAtIndex: count]; + type = [element value: 0 ofAttribute: @"type"]; + if ([type length]) + [attrs setObject: type forKey: @"type"]; + value = [element flattenedValuesForKey: @""]; + url = [NSURL URLWithString: value]; + if (![url scheme] && [value length] > 0) + url = [NSURL URLWithString: [NSString stringWithFormat: @"http://%@", value]]; + [attrs setObject: [url absoluteString] forKey: @"value"]; + + [urls addObject: attrs]; + } + } + else + urls = nil; + + return urls; +} + - (NSArray *) deliveryAddresses { NSMutableArray *addresses; @@ -853,7 +890,7 @@ if ([o count]) [data setObject: o forKey: @"categories"]; o = [self deliveryAddresses]; if ([o count] > 0) [data setObject: o forKey: @"addresses"]; - o = [card childrenWithTag: @"url"]; + o = [self urls]; if ([o count]) [data setObject: o forKey: @"urls"]; o = [self note];