Share extension mxstore rework

- Create the MXRoom instance only when the room is selected.
This commit is contained in:
Giom Foret 2017-09-29 10:37:54 +02:00
parent 6d2401971f
commit 038d4d50da
11 changed files with 211 additions and 122 deletions

View file

@ -494,6 +494,10 @@
F0A4A1671EF7CB66003630DB /* members_list_icon.png in Resources */ = {isa = PBXBuildFile; fileRef = F0A4A1641EF7CB66003630DB /* members_list_icon.png */; };
F0A4A1681EF7CB66003630DB /* members_list_icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0A4A1651EF7CB66003630DB /* members_list_icon@2x.png */; };
F0A4A1691EF7CB66003630DB /* members_list_icon@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0A4A1661EF7CB66003630DB /* members_list_icon@3x.png */; };
F0A8955F1F7D1FEA00BD6C2A /* MXRoomSummary+Riot.m in Sources */ = {isa = PBXBuildFile; fileRef = F0D2ADA01F6AA5FD00A7097D /* MXRoomSummary+Riot.m */; };
F0A895601F7D404B00BD6C2A /* e2e_verified.png in Resources */ = {isa = PBXBuildFile; fileRef = F083BB681E7009EC00A9B29C /* e2e_verified.png */; };
F0A895611F7D404E00BD6C2A /* e2e_verified@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F083BB691E7009EC00A9B29C /* e2e_verified@2x.png */; };
F0A895621F7D405000BD6C2A /* e2e_verified@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = F083BB6A1E7009EC00A9B29C /* e2e_verified@3x.png */; };
F0B4CBA51F418D0B008E99C5 /* WebViewViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F0B4CBA41F418D0B008E99C5 /* WebViewViewController.m */; };
F0B4CBA71F41CA44008E99C5 /* DeviceView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F0B4CBA61F41CA44008E99C5 /* DeviceView.xib */; };
F0B4CBAA1F41E71A008E99C5 /* RiotNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = F0B4CBA91F41E71A008E99C5 /* RiotNavigationController.m */; };
@ -2512,12 +2516,15 @@
24EEE5B51F2607C500B3C705 /* SegmentedViewController.xib in Resources */,
24EEE5A91F25529900B3C705 /* cancel@2x.png in Resources */,
F0B7A8B11F475783006E27D2 /* RoomsListViewController.xib in Resources */,
F0A895621F7D405000BD6C2A /* e2e_verified@3x.png in Resources */,
2435179C1F375B9400D0683E /* Info.plist in Resources */,
24EEE5A81F25529600B3C705 /* cancel@3x.png in Resources */,
2466B73E1F2DFAC100AE27B0 /* animatedLogo-4.png in Resources */,
2435179F1F375C0F00D0683E /* Vector.strings in Resources */,
24EEE5AF1F25F0F500B3C705 /* Images.xcassets in Resources */,
F0A895611F7D404E00BD6C2A /* e2e_verified@2x.png in Resources */,
24EEE5AA1F25529C00B3C705 /* cancel.png in Resources */,
F0A895601F7D404B00BD6C2A /* e2e_verified.png in Resources */,
24D6B35E1F3CA03E00FC7A71 /* FallbackViewController.xib in Resources */,
24EEE5A41F24C06E00B3C705 /* BuildFile in Resources */,
2439DD641F6BBEA50090F42D /* RecentRoomTableViewCell.xib in Resources */,
@ -3061,6 +3068,7 @@
24D6B35D1F3CA03A00FC7A71 /* FallbackViewController.m in Sources */,
24EEE5A11F23A09A00B3C705 /* RiotDesignValues.m in Sources */,
24EEE5A21F23A8B400B3C705 /* MXRoom+Riot.m in Sources */,
F0A8955F1F7D1FEA00BD6C2A /* MXRoomSummary+Riot.m in Sources */,
2439DD621F6BBE760090F42D /* RecentRoomTableViewCell.m in Sources */,
245FC3ED1F3D079A00603C6A /* ShareExtensionManager.m in Sources */,
24EEE5B41F2607C000B3C705 /* SegmentedViewController.m in Sources */,

View file

@ -106,7 +106,6 @@
"auth_reset_password_error_not_found" = "Your email address does not appear to be associated with a Matrix ID on this Homeserver.";
"auth_reset_password_success_message" = "Your password has been reset.\n\nYou have been logged out of all devices and will no longer receive push notifications. To re-enable notifications, re-log in on each device.";
"auth_add_email_and_phone_warning" = "Registration with email and phone number at once is not supported yet until the api exists. Only the phone number will be taken into account. You may add your email to your profile in settings.";
"auth_share_extension_prompt" = "Login in the main app to share content";
// Chat creation
"room_creation_title" = "New Chat";
@ -529,3 +528,7 @@
"widget_integration_missing_user_id" = "Missing user_id in request.";
"widget_integration_room_not_visible" = "Room %@ is not visible.";
// Share extension
"share_extension_auth_prompt" = "Login in the main app to share content";
"share_extension_failed_to_encrypt" = "Failed to send. Check in the main app the encryption settings for this room";

View file

@ -27,4 +27,12 @@ typedef NS_ENUM(NSInteger, ShareDataSourceMode)
- (instancetype)initWithMode:(ShareDataSourceMode)dataSourceMode;
/**
Returns the cell data at the index path
@param indexPath the index of the cell
@return the MXKRecentCellData instance if it exists
*/
- (MXKRecentCellData *)cellDataAtIndexPath:(NSIndexPath *)indexPath;
@end

View file

@ -17,7 +17,6 @@
#import "ShareDataSource.h"
#import "ShareExtensionManager.h"
#import "RecentRoomTableViewCell.h"
//#import "MXRoom+Riot.h"
@interface ShareDataSource ()
@ -36,81 +35,73 @@
if (self)
{
self.dataSourceMode = dataSourceMode;
_recentCellDatas = [NSMutableArray array];
[self updateRooms];
[self loadCellData];
}
return self;
}
- (void)destroy
{
[super destroy];
_recentCellDatas = nil;
_visibleRoomCellDatas = nil;
}
#pragma mark - Private
- (void)updateRooms
- (void)loadCellData
{
MXFileStore *fileStore = [[MXFileStore alloc] initWithCredentials:[ShareExtensionManager sharedManager].userAccount.mxCredentials];
MXSession *session = [[MXSession alloc] initWithMatrixRestClient:[[MXRestClient alloc] initWithCredentials:[ShareExtensionManager sharedManager].userAccount.mxCredentials andOnUnrecognizedCertificateBlock:nil]];
[[ShareExtensionManager sharedManager].fileStore asyncRoomsSummaries:^(NSArray<MXRoomSummary *> * _Nonnull roomsSummaries) {
__weak MXSession *weakSession = session;
[session setStore:fileStore success:^{
if (weakSession)
{
//__strong MXSession *session = weakSession;
[self getCellDatasFromStore:fileStore];
}
} failure:^(NSError *error) {
NSLog(@"[ShareDataSource failed to set store]");
}];
}
NSMutableArray *cellData = [NSMutableArray array];
- (void)getCellDatasFromStore:(MXFileStore *)fileStore
{
NSMutableArray *cellDatas = [NSMutableArray array];
[fileStore asyncRoomsSummaries:^(NSArray<MXRoomSummary *> * _Nonnull roomsSummaries) {
for (MXRoomSummary *roomSummary in roomsSummaries)
{
MXKRecentCellData *recentCellData = [[MXKRecentCellData alloc] initWithRoomSummary:roomSummary andRecentListDataSource:nil];
if ((self.dataSourceMode == DataSourceModeRooms) ^ roomSummary.isDirect)
{
[cellDatas addObject:recentCellData];
[cellData addObject:recentCellData];
}
}
if ([roomsSummaries indexOfObject:roomSummary] == roomsSummaries.count - 1)
{
self.recentCellDatas = cellDatas;
// TODO: Sort rooms by origin_server_ts
// NSComparator comparator = ^NSComparisonResult(MXKRecentCellData *recentCellData1, MXKRecentCellData *recentCellData2) {
//
// NSComparisonResult result = NSOrderedAscending;
// if (recentCellData2.lastEvent.originServerTs > recentCellData1.lastEvent.originServerTs)
// {
// result = NSOrderedDescending;
// }
// else if (recentCellData2.lastEvent.originServerTs == recentCellData1.lastEvent.originServerTs)
// {
// result = NSOrderedSame;
// }
// return result;
// };
// [cellData sortUsingComparator:comparator];
self.recentCellDatas = cellData;
dispatch_async(dispatch_get_main_queue(), ^{
[self.delegate dataSource:self didCellChange:nil];
});
}
}
[self.delegate dataSource:self didCellChange:nil];
});
} failure:^(NSError * _Nonnull error) {
NSLog(@"[ShareDataSource failed to get room summaries]");
}];
}
#pragma mark - MXKRecentsDataSource
- (void)dataSource:(MXKDataSource *)dataSource didCellChange:(id)changes
- (MXKRecentCellData *)cellDataAtIndexPath:(NSIndexPath *)indexPath
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.delegate dataSource:dataSource didCellChange:nil];
});
}
- (MXRoom *)getRoomAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"vori");
/*if (self.visibleRoomCellDatas)
{
return self.visibleRoomCellDatas[indexPath.row];
}
return self.visibleRoomCellDatas[indexPath.row];*/
return nil;
}
- (id<MXKRecentCellDataStoring>)cellDataAtIndexPath:(NSIndexPath *)indexPath {
if (self.visibleRoomCellDatas)
{
return self.visibleRoomCellDatas[indexPath.row];

View file

@ -20,6 +20,12 @@
@class ShareExtensionManager;
@class SharePresentingViewController;
/**
Posted when the matrix user account and his data has been checked and updated.
The notification object is the MXKAccount instance.
*/
extern NSString *const kShareExtensionManagerDidUpdateAccountDataNotification;
/**
The protocol for the manager's delegate
@ -75,6 +81,11 @@
*/
@property (nonatomic, readonly) MXKAccount *userAccount;
/**
The shared file store
*/
@property (nonatomic, readonly) MXFileStore *fileStore;
/**
A delegate used to notify about needed UI changes when sharing
*/
@ -89,9 +100,9 @@
Send the content that the user has chosen to a room
@param room the room to send the content to
@param failureBlock the code to be executed when sharing has failed for whatever reason
note: there is no "successBlock" parameter because when the sharing succeds, the extension needs to close itself
note: there is no "successBlock" parameter because when the sharing succeeds, the extension needs to close itself
*/
- (void)sendContentToRoom:(MXRoom *)room failureBlock:(void(^)())failureBlock;
- (void)sendContentToRoom:(MXRoom *)room failureBlock:(void(^)(NSError *error))failureBlock;
/**
Checks if there is an image in the user chosen content

View file

@ -20,6 +20,7 @@
@import MobileCoreServices;
#import "objc/runtime.h"
NSString *const kShareExtensionManagerDidUpdateAccountDataNotification = @"kShareExtensionManagerDidUpdateAccountDataNotification";
typedef NS_ENUM(NSInteger, ImageCompressionMode)
{
@ -51,6 +52,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
static ShareExtensionManager *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
sharedInstance.pendingImages = [NSMutableArray array];
@ -69,12 +71,8 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
sdkOptions.applicationGroupIdentifier = @"group.im.vector";
// Disable identicon use
sdkOptions.disableIdenticonUseForUserAvatar = YES;
// Force account manager to reload account from the local storage.
[[MXKAccountManager sharedManager] forceReloadAccounts];
// Save the first active account
sharedInstance.userAccount = [MXKAccountManager sharedManager].activeAccounts.firstObject;
// Enable e2e encryption for newly created MXSession
sdkOptions.enableCryptoWhenStartingMXSession = YES;
});
return sharedInstance;
@ -98,22 +96,40 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
}
}
if (self.userAccount)
if (!self.userAccount)
{
// Resume the matrix session
[self.userAccount resume];
}
// We consider the first enabled account.
// TODO: Handle multiple accounts
self.userAccount = [MXKAccountManager sharedManager].activeAccounts.firstObject;
}
// Reset the file store to reload the room data.
if (_fileStore)
{
[_fileStore close];
_fileStore = nil;
}
if (self.userAccount)
{
_fileStore = [[MXFileStore alloc] initWithCredentials:self.userAccount.mxCredentials];
}
// Post notification
[[NSNotificationCenter defaultCenter] postNotificationName:kShareExtensionManagerDidUpdateAccountDataNotification object:self.userAccount userInfo:nil];
}
#pragma mark - Public
- (void)setShareExtensionContext:(NSExtensionContext *)shareExtensionContext
{
_shareExtensionContext = shareExtensionContext;
// Check the current matrix user.
[self checkUserAccount];
}
- (void)sendContentToRoom:(MXRoom *)room failureBlock:(void(^)())failureBlock
- (void)sendContentToRoom:(MXRoom *)room failureBlock:(void(^)(NSError *error))failureBlock
{
NSString *UTTypeText = (__bridge NSString *)kUTTypeText;
NSString *UTTypeURL = (__bridge NSString *)kUTTypeURL;
@ -488,7 +504,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
#pragma mark - Sharing
- (void)sendText:(NSString *)text toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)())failureBlock
- (void)sendText:(NSString *)text toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)(NSError *error))failureBlock
{
[self didStartSendingToRoom:room];
if (!text)
@ -496,7 +512,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
NSLog(@"[ShareExtensionManager] loadItemForTypeIdentifier: failed.");
if (failureBlock)
{
failureBlock();
failureBlock(nil);
}
return;
}
@ -512,12 +528,12 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
NSLog(@"[ShareExtensionManager] sendTextMessage failed.");
if (failureBlock)
{
failureBlock();
failureBlock(error);
}
}];
}
- (void)sendFileWithUrl:(NSURL *)fileUrl toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)())failureBlock
- (void)sendFileWithUrl:(NSURL *)fileUrl toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)(NSError *error))failureBlock
{
[self didStartSendingToRoom:room];
if (!fileUrl)
@ -525,7 +541,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
NSLog(@"[ShareExtensionManager] loadItemForTypeIdentifier: failed.");
if (failureBlock)
{
failureBlock();
failureBlock(nil);
}
return;
}
@ -547,13 +563,13 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
NSLog(@"[ShareExtensionManager] sendFile failed.");
if (failureBlock)
{
failureBlock();
failureBlock(error);
}
} keepActualFilename:YES];
}
- (void)sendImages:(NSMutableArray *)imageDatas withProviders:(NSArray*)itemProviders toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:( void(^)())failureBlock
- (void)sendImages:(NSMutableArray *)imageDatas withProviders:(NSArray*)itemProviders toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)(NSError *error))failureBlock
{
[self didStartSendingToRoom:room];
@ -568,7 +584,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
NSLog(@"[ShareExtensionManager] loadItemForTypeIdentifier: failed.");
if (failureBlock)
{
failureBlock();
failureBlock(nil);
failureBlock = nil;
}
return;
@ -639,7 +655,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
{
if (failureBlock)
{
failureBlock();
failureBlock(error);
}
}
@ -648,7 +664,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
}
- (void)sendVideo:(NSURL *)videoLocalUrl toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)())failureBlock
- (void)sendVideo:(NSURL *)videoLocalUrl toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)(NSError *error))failureBlock
{
[self didStartSendingToRoom:room];
if (!videoLocalUrl)
@ -656,7 +672,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
NSLog(@"[ShareExtensionManager] loadItemForTypeIdentifier: failed.");
if (failureBlock)
{
failureBlock();
failureBlock(nil);
}
return;
}
@ -683,7 +699,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
NSLog(@"[ShareExtensionManager] sendVideo failed.");
if (failureBlock)
{
failureBlock();
failureBlock(error);
}
}];
}

View file

@ -30,7 +30,7 @@
[super viewDidLoad];
self.titleLabel.textColor = kRiotSecondaryTextColor;
self.titleLabel.text = NSLocalizedStringFromTable(@"auth_share_extension_prompt", @"Vector", nil);
self.titleLabel.text = NSLocalizedStringFromTable(@"share_extension_auth_prompt", @"Vector", nil);
}
- (void)didReceiveMemoryWarning

View file

@ -23,8 +23,6 @@
#import "MXKPieChartView.h"
#import "MXKPieChartHUD.h"
@interface RoomsListViewController () <ShareExtensionManagerDelegate>
@property (nonatomic) MXKPieChartHUD *hudView;
@ -35,7 +33,6 @@
@end
@implementation RoomsListViewController
#pragma mark - Class methods
@ -130,36 +127,78 @@
- (void)showShareAlertForRoomPath:(NSIndexPath *)indexPath
{
// @TODO: the room should be instanciated here (only the room summary should be available from dataSource).
NSString *receipantName = [self.dataSource getRoomAtIndexPath:indexPath].summary.displayname;
if (!receipantName.length)
MXKRecentCellData *recentCellData = [self.dataSource cellDataAtIndexPath:indexPath];
NSString *roomName = recentCellData.roomSummary.displayname;
if (!roomName.length)
{
receipantName = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil);
roomName = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil);
}
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:NSLocalizedStringFromTable(@"send_to", @"Vector", nil), receipantName] message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:NSLocalizedStringFromTable(@"send_to", @"Vector", nil), roomName] message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] style:UIAlertActionStyleCancel handler:nil];
[alertController addAction:cancelAction];
UIAlertAction *sendAction = [UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"send"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
MXRoom *selectedRoom = [self.dataSource getRoomAtIndexPath:indexPath];
// The selected room is instanciated here.
[[ShareExtensionManager sharedManager].fileStore asyncAccountDataOfRoom:recentCellData.roomSummary.roomId success:^(MXRoomAccountData * _Nonnull accountData) {
[[ShareExtensionManager sharedManager].fileStore asyncStateEventsOfRoom:recentCellData.roomSummary.roomId success:^(NSArray<MXEvent *> * _Nonnull roomStateEvents) {
MXSession *session = [[MXSession alloc] initWithMatrixRestClient:[[MXRestClient alloc] initWithCredentials:[ShareExtensionManager sharedManager].userAccount.mxCredentials andOnUnrecognizedCertificateBlock:nil]];
// To handle correctly the crypto, we have to set a store (use a fake store)
__weak MXSession *weakSession = session;
[session setStore:[[MXNoStore alloc] init] success:^{
if (weakSession)
{
__strong MXSession *session = weakSession;
MXRoom *selectedRoom = [[MXRoom alloc] initWithRoomId:recentCellData.roomSummary.roomId andMatrixSession:session andStateEvents:roomStateEvents andAccountData:accountData];
[ShareExtensionManager sharedManager].delegate = self;
[[ShareExtensionManager sharedManager] sendContentToRoom:selectedRoom failureBlock:^{
[self showFailureAlert];
[[ShareExtensionManager sharedManager] sendContentToRoom:selectedRoom failureBlock:^(NSError* error) {
NSString *title;
if ([error.domain isEqualToString:MXEncryptingErrorDomain])
{
title = NSLocalizedStringFromTable(@"share_extension_failed_to_encrypt", @"Vector", nil);
}
[self showFailureAlert:title];
}];
}
} failure:^(NSError *error) {
NSLog(@"[RoomsListViewController] failed to prepare matrix session]");
}];
} failure:^(NSError * _Nonnull error) {
NSLog(@"[RoomsListViewController] failed to get state events");
}];
} failure:^(NSError * _Nonnull error) {
NSLog(@"[RoomsListViewController] failed to get account data");
}];
}];
[alertController addAction:sendAction];
[self presentViewController:alertController animated:YES completion:nil];
}
- (void)showFailureAlert
- (void)showFailureAlert:(NSString *)title
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"room_event_failed_to_send", @"Vector", nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title.length ? title : NSLocalizedStringFromTable(@"room_event_failed_to_send", @"Vector", nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if (self.failureBlock)
{

View file

@ -30,7 +30,7 @@
@property (nonatomic) SegmentedViewController *segmentedViewController;
@property (nonatomic) id shareExtensionManagerDidChangeMXSessionObserver;
@property (nonatomic) id shareExtensionManagerDidUpdateAccountDataObserver;
@end
@ -43,6 +43,13 @@
- (void)viewDidLoad
{
[super viewDidLoad];
self.shareExtensionManagerDidUpdateAccountDataObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kShareExtensionManagerDidUpdateAccountDataNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
[self configureViews];
}];
[self configureViews];
}
@ -50,10 +57,10 @@
{
[super destroy];
if (self.shareExtensionManagerDidChangeMXSessionObserver)
if (self.shareExtensionManagerDidUpdateAccountDataObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:self.shareExtensionManagerDidChangeMXSessionObserver];
self.shareExtensionManagerDidChangeMXSessionObserver = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self.shareExtensionManagerDidUpdateAccountDataObserver];
self.shareExtensionManagerDidUpdateAccountDataObserver = nil;
}
[self resetContentView];

View file

@ -16,6 +16,8 @@
#import "RecentRoomTableViewCell.h"
#import "MXRoomSummary+Riot.h"
@interface RecentRoomTableViewCell ()
@property (weak, nonatomic) IBOutlet MXKImageView *avatarImageView;
@ -23,8 +25,6 @@
@property (weak, nonatomic) IBOutlet UILabel *roomTitleLabel;
@property (weak, nonatomic) IBOutlet UIImageView *encryptedRoomIcon;
@end
@implementation RecentRoomTableViewCell
@ -44,18 +44,35 @@
return nil;
}
- (void)render:(MXKRecentCellData *)cellData
- (void)layoutSubviews
{
[super layoutSubviews];
//NSString *imageUrl = [self.matrixRestClient urlOfContentThumbnail:cellData toFitViewSize:mxkImageView.frame.size withMethod:MXThumbnailingMethodCrop];
//[self.avatarImageView setImageURL:nil withType:nil andImageOrientation:UIImageOrientationUp previewImage:nil];
// Round room avatars
[self.avatarImageView.layer setCornerRadius:self.avatarImageView.frame.size.width / 2];
self.avatarImageView.clipsToBounds = YES;
}
self.roomTitleLabel.text = cellData.roomDisplayname;
- (void)render:(MXKCellData *)cellData
{
// Sanity check: accept only object of MXKRecentCellData classes or sub-classes
NSParameterAssert([cellData isKindOfClass:[MXKRecentCellData class]]);
self.directRoomBorderView.hidden = !cellData.roomSummary.isDirect;
roomCellData = (id<MXKRecentCellDataStoring>)cellData;
if (roomCellData)
{
[roomCellData.roomSummary setRoomAvatarImageIn:self.avatarImageView];
self.encryptedRoomIcon.hidden = !cellData.roomSummary.isEncrypted;
self.roomTitleLabel.text = roomCellData.roomSummary.displayname;
if (!self.roomTitleLabel.text.length)
{
self.roomTitleLabel.text = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil);
}
self.directRoomBorderView.hidden = !roomCellData.roomSummary.isDirect;
self.encryptedRoomIcon.hidden = !roomCellData.roomSummary.isEncrypted;
}
}
+ (CGFloat)cellHeight
@ -63,15 +80,4 @@
return 74;
}
/*- (void)render:(MXRoom *)room
{
[room setRoomAvatarImageIn:self.avatarImageView];
self.titleLabel.text = room.riotDisplayname;
self.directRoomBorderView.hidden = !room.isDirect;
self.encryptedRoomIcon.hidden = !room.state.isEncrypted;
}*/
@end

View file

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>