diff --git a/matrixConsole/Base.lproj/Main.storyboard b/matrixConsole/Base.lproj/Main.storyboard index d17f3987e..33c802e92 100644 --- a/matrixConsole/Base.lproj/Main.storyboard +++ b/matrixConsole/Base.lproj/Main.storyboard @@ -1360,27 +1360,27 @@ - + - + - + - - + + - + @@ -1408,9 +1408,9 @@ - + - + diff --git a/matrixConsole/Model/ConsoleContact.h b/matrixConsole/Model/ConsoleContact.h index 1dc60b059..b90fea8a4 100644 --- a/matrixConsole/Model/ConsoleContact.h +++ b/matrixConsole/Model/ConsoleContact.h @@ -44,7 +44,14 @@ extern NSString *const kConsoleContactThumbnailUpdateNotification; - (id)initWithABRecord:(ABRecordRef)record; +// return thumbnail with a prefered size +// if the thumbnail is already loaded, this method returns this one +// if the thumbnail must trigger a server request, the expected size will be size +// self.thumbnail triggered a request with a 256 X 256 pixels +- (UIImage*)thumbnailWithPreferedSize:(CGSize)size; + // check if there is any matrix identifier updates - (void)checkMatrixIdentifiers; + @end \ No newline at end of file diff --git a/matrixConsole/Model/ConsoleContact.m b/matrixConsole/Model/ConsoleContact.m index 443ceaa3f..f06c59ef5 100644 --- a/matrixConsole/Model/ConsoleContact.m +++ b/matrixConsole/Model/ConsoleContact.m @@ -75,12 +75,8 @@ NSString *const kConsoleContactThumbnailUpdateNotification = @"kConsoleContactTh lbl = (__bridge NSString*)localizedLblRef; } } - - ConsolePhoneNumber* pn = [[ConsolePhoneNumber alloc] init]; - pn.type = lbl; - pn.textNumber = phoneVal; - - [pns addObject:pn]; + + [pns addObject:[[ConsolePhoneNumber alloc] initWithTextNumber:phoneVal andType:lbl within:self.contactID]]; if (lblRef) { CFRelease(lblRef); @@ -131,8 +127,7 @@ NSString *const kConsoleContactThumbnailUpdateNotification = @"kConsoleContactTh } } - ConsoleEmail* email = [[ConsoleEmail alloc] initWithEmailAddress:emailVal andType:lbl within:self.contactID]; - [emails addObject: email]; + [emails addObject: [[ConsoleEmail alloc] initWithEmailAddress:emailVal andType:lbl within:self.contactID]]; if (lblRef) { CFRelease(lblRef); @@ -185,7 +180,11 @@ NSString *const kConsoleContactThumbnailUpdateNotification = @"kConsoleContactTh return identifiers; } -- (UIImage*)thumbnail { +// return thumbnail with a prefered size +// if the thumbnail is already loaded, this method returns this one +// if the thumbnail must trigger a server request, the expected size will be size +// self.thumbnail triggered a request with a 256 X 256 pixels +- (UIImage*)thumbnailWithPreferedSize:(CGSize)size { // already found a matrix thumbnail if (matrixThumbnail) { return matrixThumbnail; @@ -211,7 +210,7 @@ NSString *const kConsoleContactThumbnailUpdateNotification = @"kConsoleContactTh // try to load the first email one if (firstEmail) { // should be retrieved by the cell info - [firstEmail loadAvatarWithSize:CGSizeMake(80, 80)]; + [firstEmail loadAvatarWithSize:size]; } } @@ -219,6 +218,10 @@ NSString *const kConsoleContactThumbnailUpdateNotification = @"kConsoleContactTh } } +- (UIImage*)thumbnail { + return [self thumbnailWithPreferedSize:CGSizeMake(256, 256)]; +} + - (void)checkMatrixIdentifiers { for(ConsoleEmail* email in self.emailAddresses) { [email getMatrixID]; diff --git a/matrixConsole/Model/ConsoleEmail.h b/matrixConsole/Model/ConsoleEmail.h index f476ec920..58f85c224 100644 --- a/matrixConsole/Model/ConsoleEmail.h +++ b/matrixConsole/Model/ConsoleEmail.h @@ -16,17 +16,17 @@ #import -@interface ConsoleEmail : NSObject { - BOOL pendingMatrixIDRequest; - BOOL gotMatrixID; -} +@interface ConsoleEmail : NSObject -@property (nonatomic, readwrite) NSString *type; -@property (nonatomic, readwrite) NSString *emailAddress; -@property (nonatomic, readwrite) NSString *contactID; -@property (nonatomic, readwrite) NSString *matrixUserID; -@property (nonatomic, readwrite) NSString *avatarURL; -@property (nonatomic, readwrite) UIImage *avatarImage; +// email info +@property (nonatomic, readonly) NSString *type; +@property (nonatomic, readonly) NSString *emailAddress; +// contact ID where the email has been found +@property (nonatomic, readonly) NSString *contactID; +// linked matrix account +@property (nonatomic, readonly) NSString *matrixUserID; +@property (nonatomic, readonly) NSString *avatarURL; +@property (nonatomic, readonly) UIImage *avatarImage; - (id)initWithEmailAddress:(NSString*)anEmailAddress andType:(NSString*)aType within:(NSString*)aContactID; diff --git a/matrixConsole/Model/ConsoleEmail.m b/matrixConsole/Model/ConsoleEmail.m index 82e52a3c1..859880038 100644 --- a/matrixConsole/Model/ConsoleEmail.m +++ b/matrixConsole/Model/ConsoleEmail.m @@ -21,6 +21,20 @@ #import "MediaManager.h" +@interface ConsoleEmail() { + BOOL pendingMatrixIDRequest; + BOOL gotMatrixID; +} + +@property (nonatomic, readwrite) NSString *type; +@property (nonatomic, readwrite) NSString *emailAddress; +@property (nonatomic, readwrite) NSString *contactID; +@property (nonatomic, readwrite) NSString *matrixUserID; +@property (nonatomic, readwrite) NSString *avatarURL; +@property (nonatomic, readwrite) UIImage *avatarImage; + +@end + @implementation ConsoleEmail @synthesize type, emailAddress, contactID, matrixUserID, avatarImage, avatarURL; @@ -131,12 +145,12 @@ if (mxHandler.mxRestClient) { [mxHandler.mxRestClient avatarUrlForUser:self.matrixUserID - success:^(NSString *avatarUrl) { - self.avatarURL = [mxHandler thumbnailURLForContent:avatarUrl inViewSize:avatarSize withMethod:MXThumbnailingMethodCrop]; - [self downloadAvatarImage]; - } + success:^(NSString *avatarUrl) { + self.avatarURL = [mxHandler thumbnailURLForContent:avatarUrl inViewSize:avatarSize withMethod:MXThumbnailingMethodCrop]; + [self downloadAvatarImage]; + } failure:^(NSError *error) { - // + // }]; } } diff --git a/matrixConsole/Model/ConsolePhoneNumber.h b/matrixConsole/Model/ConsolePhoneNumber.h index 0167ed7ff..bced8d4b8 100644 --- a/matrixConsole/Model/ConsolePhoneNumber.h +++ b/matrixConsole/Model/ConsolePhoneNumber.h @@ -17,9 +17,12 @@ @interface ConsolePhoneNumber : NSObject -@property (nonatomic, readwrite) NSString *type; -@property (nonatomic, readwrite) NSString *textNumber; -@property (nonatomic, readwrite) NSString *contactID; +// phonenumber info +@property (nonatomic, readonly) NSString *type; +@property (nonatomic, readonly) NSString *textNumber; +// contact ID where the phonenumber has been found +@property (nonatomic, readonly) NSString *contactID; - (id)initWithTextNumber:(NSString*)textNumber andType:(NSString*)aType within:(NSString*)aContactID; + @end \ No newline at end of file diff --git a/matrixConsole/Model/ConsolePhoneNumber.m b/matrixConsole/Model/ConsolePhoneNumber.m index e15e2073c..bc7f83977 100644 --- a/matrixConsole/Model/ConsolePhoneNumber.m +++ b/matrixConsole/Model/ConsolePhoneNumber.m @@ -16,6 +16,12 @@ #import "ConsolePhoneNumber.h" +@interface ConsolePhoneNumber() +@property (nonatomic, readwrite) NSString *type; +@property (nonatomic, readwrite) NSString *textNumber; +@property (nonatomic, readwrite) NSString *contactID; +@end + @implementation ConsolePhoneNumber @synthesize type, textNumber, contactID; diff --git a/matrixConsole/View/ContactTableCell.h b/matrixConsole/View/ContactTableCell.h index b0c011819..be6005fd4 100644 --- a/matrixConsole/View/ContactTableCell.h +++ b/matrixConsole/View/ContactTableCell.h @@ -20,8 +20,8 @@ @interface ContactTableCell : UITableViewCell -@property (strong, nonatomic) IBOutlet CustomImageView *thumbnail; -@property (strong, nonatomic) IBOutlet UILabel *contactDisplayName; +@property (strong, nonatomic) IBOutlet CustomImageView *thumbnailView; +@property (strong, nonatomic) IBOutlet UILabel *contactDisplayNameLabel; @property (strong, nonatomic) IBOutlet UIImageView *matrixUserIconView; // reference to the linked message diff --git a/matrixConsole/View/ContactTableCell.m b/matrixConsole/View/ContactTableCell.m index 8fa4bf038..5ecd2776a 100644 --- a/matrixConsole/View/ContactTableCell.m +++ b/matrixConsole/View/ContactTableCell.m @@ -52,11 +52,10 @@ [mxHandler.mxSession removeListener:membersListener]; membersListener = nil; } - self.thumbnail.layer.borderWidth = 0; - - // add contact update info - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMatrixIdUpdate:) name:kConsoleContactMatrixIdentifierUpdateNotification object:nil]; + self.thumbnailView.layer.borderWidth = 0; + // be warned when the matrix ID and the thumbnail is updated + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMatrixIdUpdate:) name:kConsoleContactMatrixIdentifierUpdateNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onThumbnailUpdate:) name:kConsoleContactThumbnailUpdateNotification object:nil]; // Register a listener for events that concern room members @@ -82,7 +81,10 @@ } }]; - [self refreshUserPresence]; + // init the contact info + self.contactDisplayNameLabel.text = _contact.displayName; + [self refreshContactThumbnail]; + [self manageMatrixIcon]; } - (void)refreshUserPresence { @@ -100,51 +102,62 @@ // check if already known as a Matrix user MXUser* mxUser = [mxHandler.mxSession userWithUserId:matrixUserID]; - // unknown user - if (!mxUser) { - // request his presence - [mxHandler.mxRestClient presence:matrixUserID - success:^(MXPresenceResponse *presence) { - [self refreshPresenceUserRing:presence.presenceStatus]; - } - failure:^ (NSError *error) { - } - ]; - - } else { - [self refreshPresenceUserRing:mxUser.presence]; + // check if the mxUser is known + // if it is not known, the presence cannot be retrieved + if (mxUser) { + [self refreshPresenceUserRing:mxUser.presence]; + // we know that this user is a matrix one + self.matrixUserIconView.hidden = NO; } } } +- (void)refreshContactThumbnail { + self.thumbnailView.image = [self.contact thumbnailWithPreferedSize:self.thumbnailView.frame.size]; + + if (!self.thumbnailView.image) { + self.thumbnailView.image = [UIImage imageNamed:@"default-profile"]; + } + + // display the thumbnail in a circle + if (self.thumbnailView.layer.cornerRadius != self.thumbnailView.frame.size.width / 2) { + self.thumbnailView.layer.cornerRadius = self.thumbnailView.frame.size.width / 2; + self.thumbnailView.clipsToBounds = YES; + } +} + - (void)refreshPresenceUserRing:(MXPresence)presenceStatus { UIColor* ringColor = [[MatrixHandler sharedHandler] getPresenceRingColor:presenceStatus]; // if the thumbnail is defined if (ringColor) { - self.thumbnail.layer.borderWidth = 2; - self.thumbnail.layer.borderColor = ringColor.CGColor; + self.thumbnailView.layer.borderWidth = 2; + self.thumbnailView.layer.borderColor = ringColor.CGColor; } else { // remove the border // else it draws black border - self.thumbnail.layer.borderWidth = 0; + self.thumbnailView.layer.borderWidth = 0; } } +- (void)manageMatrixIcon { + self.matrixUserIconView.hidden = (0 == _contact.matrixIdentifiers.count); + + // try to update the thumbnail with the matrix thumbnail + if (_contact.matrixIdentifiers) { + [self refreshContactThumbnail]; + } + + [self refreshUserPresence]; +} + - (void)onMatrixIdUpdate:(NSNotification *)notif { // sanity check if ([notif.object isKindOfClass:[NSString class]]) { NSString* matrixID = notif.object; if ([matrixID isEqualToString:self.contact.contactID]) { - self.matrixUserIconView.hidden = (0 == _contact.matrixIdentifiers.count); - - // try to update the thumbnail with the matrix thumbnail - if (_contact.matrixIdentifiers) { - self.matrixUserIconView.image = self.contact.thumbnail; - } - - [self refreshUserPresence]; + [self manageMatrixIcon]; } } } @@ -155,7 +168,8 @@ NSString* matrixID = notif.object; if ([matrixID isEqualToString:self.contact.contactID]) { - self.thumbnail.image = self.contact.thumbnail; + [self refreshContactThumbnail]; + self.matrixUserIconView.hidden = (0 == _contact.matrixIdentifiers.count); } } } diff --git a/matrixConsole/ViewController/ContactsViewController.m b/matrixConsole/ViewController/ContactsViewController.m index 0d9e79618..b0e5d7e3b 100644 --- a/matrixConsole/ViewController/ContactsViewController.m +++ b/matrixConsole/ViewController/ContactsViewController.m @@ -58,6 +58,10 @@ return [[sectionedContacts.sectionedContacts objectAtIndex:section] count]; } +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { + return 50; +} + - (NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section { if (sectionedContacts.sectionTitles.count <= section) { return nil; @@ -123,20 +127,7 @@ } cell.contact = contact; - - // set the thumbnail - if (contact.thumbnail) { - cell.thumbnail.image = contact.thumbnail; - } else { - cell.thumbnail.image = [UIImage imageNamed:@"default-profile"]; - } - - cell.thumbnail.layer.cornerRadius = cell.thumbnail.frame.size.width / 2; - cell.thumbnail.clipsToBounds = YES; - - // and the displayname - cell.contactDisplayName.text = contact.displayName; - + return cell; }