mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-25 02:52:45 +02:00
Finished rework, getting rooms with all the necessary information from MXStore
This commit is contained in:
@@ -27,6 +27,4 @@ typedef NS_ENUM(NSInteger, ShareDataSourceMode)
|
||||
|
||||
- (instancetype)initWithMode:(ShareDataSourceMode)dataSourceMode;
|
||||
|
||||
- (MXRoomSummary *)getRoomSummaryAtIndexPath:(NSIndexPath *)indexPath;
|
||||
|
||||
@end
|
||||
|
||||
@@ -17,13 +17,14 @@
|
||||
#import "ShareDataSource.h"
|
||||
#import "ShareExtensionManager.h"
|
||||
#import "RoomTableViewCell.h"
|
||||
#import "MXRoom+Riot.h"
|
||||
|
||||
@interface ShareDataSource ()
|
||||
|
||||
@property (nonatomic, readwrite) ShareDataSourceMode dataSourceMode;
|
||||
|
||||
@property NSMutableArray *recentRooms;
|
||||
@property NSMutableArray *recentPeople;
|
||||
@property NSArray <MXRoom *> *rooms;
|
||||
@property NSMutableArray <MXRoom *> *visibleRooms;
|
||||
|
||||
@end
|
||||
|
||||
@@ -31,11 +32,11 @@
|
||||
|
||||
- (instancetype)initWithMode:(ShareDataSourceMode)dataSourceMode
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
self.dataSourceMode = dataSourceMode;
|
||||
_recentRooms = [NSMutableArray array];
|
||||
_recentPeople = [NSMutableArray array];
|
||||
_rooms = [NSMutableArray array];
|
||||
[self updateRooms];
|
||||
}
|
||||
return self;
|
||||
@@ -46,50 +47,105 @@
|
||||
|
||||
- (void)updateRooms
|
||||
{
|
||||
[self.recentRooms removeAllObjects];
|
||||
[self.recentPeople removeAllObjects];
|
||||
|
||||
MXFileStore *fileStore = [[MXFileStore alloc] initWithCredentials:[ShareExtensionManager sharedManager].account.mxCredentials];
|
||||
MXSession *session = [[MXSession alloc] initWithMatrixRestClient:[[MXRestClient alloc] initWithCredentials:[ShareExtensionManager sharedManager].account.mxCredentials andOnUnrecognizedCertificateBlock:nil]];
|
||||
|
||||
__weak MXSession *weakSession = session;
|
||||
[session setStore:fileStore success:^{
|
||||
if (weakSession)
|
||||
{
|
||||
__strong MXSession *session = weakSession;
|
||||
[self getRoomsFromStore:fileStore session:session];
|
||||
}
|
||||
} failure:^(NSError *error) {
|
||||
NSLog(@"[ShareExtensionManager failed to set store]");
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)getRoomsFromStore:(MXFileStore *)fileStore session:(MXSession *)session
|
||||
{
|
||||
NSMutableArray *rooms = [NSMutableArray array];
|
||||
[fileStore asyncRoomsSummaries:^(NSArray<MXRoomSummary *> * _Nonnull roomsSummaries) {
|
||||
for (MXRoomSummary *roomSummary in roomsSummaries)
|
||||
{
|
||||
if (self.dataSourceMode == DataSourceModePeople)
|
||||
{
|
||||
if (roomSummary.isDirect)
|
||||
{
|
||||
[self.recentPeople addObject:roomSummary];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!roomSummary.isDirect)
|
||||
{
|
||||
[self.recentRooms addObject:roomSummary];
|
||||
}
|
||||
}
|
||||
[self.delegate dataSource:self didCellChange:nil];
|
||||
[fileStore asyncAccountDataOfRoom:roomSummary.roomId success:^(MXRoomAccountData * _Nonnull accountData) {
|
||||
[fileStore asyncStateEventsOfRoom:roomSummary.roomId success:^(NSArray<MXEvent *> * _Nonnull roomStateEvents) {
|
||||
|
||||
MXRoom *room = [[MXRoom alloc] initWithRoomId:roomSummary.roomId andMatrixSession:session andStateEvents:roomStateEvents andAccountData:accountData];
|
||||
|
||||
if ((self.dataSourceMode == DataSourceModeRooms) ^ roomSummary.isDirect)
|
||||
{
|
||||
[rooms addObject:room];
|
||||
}
|
||||
|
||||
if ([roomsSummaries indexOfObject:roomSummary] == roomsSummaries.count - 1)
|
||||
{
|
||||
self.rooms = rooms;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.delegate dataSource:self didCellChange:nil];
|
||||
});
|
||||
}
|
||||
|
||||
} failure:^(NSError * _Nonnull error) {
|
||||
NSLog(@"[ShareExtensionManager failed to get state events]");
|
||||
}];
|
||||
} failure:^(NSError * _Nonnull error) {
|
||||
NSLog(@"[ShareExtensionManager failed to get account data]");
|
||||
}];
|
||||
|
||||
}
|
||||
} failure:^(NSError * _Nonnull error) {
|
||||
NSLog(@"[ShareExtensionManager failed to get room summaries]");
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - MXKRecentsDataSource
|
||||
|
||||
- (MXRoomSummary *)getRoomSummaryAtIndexPath:(NSIndexPath *)indexPath
|
||||
- (void)dataSource:(MXKDataSource *)dataSource didCellChange:(id)changes
|
||||
{
|
||||
MXRoomSummary *room = nil;
|
||||
|
||||
if (self.dataSourceMode == DataSourceModePeople)
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.delegate dataSource:dataSource didCellChange:nil];
|
||||
});
|
||||
}
|
||||
|
||||
- (MXRoom *)getRoomAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
if (self.visibleRooms)
|
||||
{
|
||||
room = self.recentPeople[indexPath.row];
|
||||
return self.visibleRooms[indexPath.row];
|
||||
}
|
||||
return self.rooms[indexPath.row];
|
||||
}
|
||||
|
||||
- (void)searchWithPatterns:(NSArray *)patternsList
|
||||
{
|
||||
if (self.visibleRooms)
|
||||
{
|
||||
[self.visibleRooms removeAllObjects];
|
||||
}
|
||||
else
|
||||
{
|
||||
room = self.recentRooms[indexPath.row];
|
||||
self.visibleRooms = [NSMutableArray arrayWithCapacity:self.rooms.count];
|
||||
}
|
||||
|
||||
return room;
|
||||
if (patternsList.count)
|
||||
{
|
||||
for (MXRoom *room in self.rooms)
|
||||
{
|
||||
for (NSString* pattern in patternsList)
|
||||
{
|
||||
if (room.riotDisplayname && [room.riotDisplayname rangeOfString:pattern options:NSCaseInsensitiveSearch].location != NSNotFound)
|
||||
{
|
||||
[self.visibleRooms addObject:room];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self.visibleRooms = nil;
|
||||
}
|
||||
[self.delegate dataSource:self didCellChange:nil];
|
||||
}
|
||||
|
||||
#pragma mark - UITableViewDataSource
|
||||
@@ -101,28 +157,20 @@
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
if (self.dataSourceMode == DataSourceModePeople)
|
||||
if (self.visibleRooms)
|
||||
{
|
||||
return self.recentPeople.count;
|
||||
}
|
||||
else
|
||||
{
|
||||
return self.recentRooms.count;
|
||||
return self.visibleRooms.count;
|
||||
}
|
||||
return self.rooms.count;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
RoomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[RoomTableViewCell defaultReuseIdentifier]];
|
||||
|
||||
MXRoomSummary *roomSummary = [self getRoomSummaryAtIndexPath:indexPath];
|
||||
MXRoom *room = [self getRoomAtIndexPath:indexPath];
|
||||
|
||||
[cell renderWithSummary:roomSummary restClient:[ShareExtensionManager sharedManager].mxRestClient];
|
||||
|
||||
if (!roomSummary.displayname.length && !cell.titleLabel.text.length)
|
||||
{
|
||||
cell.titleLabel.text = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil);
|
||||
}
|
||||
[cell render:room];
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
@@ -45,9 +45,9 @@ extern NSString *const kShareExtensionManagerDidChangeMXSessionNotification;
|
||||
/**
|
||||
Called when the manager starts sending the content to a room
|
||||
@param extensionManager the ShareExtensionManager object that called the method
|
||||
@param roomID the ID of the room
|
||||
@param room the room where content will be sent
|
||||
*/
|
||||
- (void)shareExtensionManager:(ShareExtensionManager *)extensionManager didStartSendingContentToRoom:(NSString *)roomID;
|
||||
- (void)shareExtensionManager:(ShareExtensionManager *)extensionManager didStartSendingContentToRoom:(MXRoom *)room;
|
||||
|
||||
/**
|
||||
Called when the progress of the uploading media changes
|
||||
@@ -90,11 +90,11 @@ extern NSString *const kShareExtensionManagerDidChangeMXSessionNotification;
|
||||
|
||||
/**
|
||||
Send the content that the user has chosen to a room
|
||||
@param roomID the ID of the room to send the content to
|
||||
@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
|
||||
*/
|
||||
- (void)sendContentToRoom:(NSString *)roomID failureBlock:(void(^)())failureBlock;
|
||||
- (void)sendContentToRoom:(MXRoom *)room failureBlock:(void(^)())failureBlock;
|
||||
|
||||
/**
|
||||
Checks if there is an image in the user chosen content
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
distributed under the License is distributed on
|
||||
an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -33,10 +34,6 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
|
||||
@interface ShareExtensionManager ()
|
||||
|
||||
@property (nonatomic, readwrite) MXKAccount *account;
|
||||
@property (nonatomic, readwrite) MXRestClient *mxRestClient;
|
||||
|
||||
@property (nonatomic) NSArray *rooms;
|
||||
@property (nonatomic) NSArray *people;
|
||||
|
||||
@property (nonatomic) NSMutableArray <NSData *> *pendingImages;
|
||||
@property (nonatomic) NSMutableDictionary <NSString *, NSNumber *> *imageUploadProgresses;
|
||||
@@ -74,7 +71,6 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
|
||||
// Save the first active account
|
||||
sharedInstance.account = [MXKAccountManager sharedManager].activeAccounts.firstObject;
|
||||
|
||||
sharedInstance.mxRestClient = [[MXRestClient alloc] initWithCredentials:sharedInstance.account.mxCredentials andOnUnrecognizedCertificateBlock:nil];
|
||||
});
|
||||
return sharedInstance;
|
||||
}
|
||||
@@ -87,7 +83,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
|
||||
_shareExtensionContext = shareExtensionContext;
|
||||
}
|
||||
|
||||
- (void)sendContentToRoom:(NSString *)roomID failureBlock:(void(^)())failureBlock
|
||||
- (void)sendContentToRoom:(MXRoom *)room failureBlock:(void(^)())failureBlock
|
||||
{
|
||||
NSString *UTTypeText = (__bridge NSString *)kUTTypeText;
|
||||
NSString *UTTypeURL = (__bridge NSString *)kUTTypeURL;
|
||||
@@ -114,7 +110,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
|
||||
if (weakSelf)
|
||||
{
|
||||
typeof(self) self = weakSelf;
|
||||
//[self sendFileWithUrl:fileUrl toRoom:room extensionItem:item failureBlock:failureBlock];
|
||||
[self sendFileWithUrl:fileUrl toRoom:room extensionItem:item failureBlock:failureBlock];
|
||||
}
|
||||
|
||||
});
|
||||
@@ -131,7 +127,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
|
||||
if (weakSelf)
|
||||
{
|
||||
typeof(self) self = weakSelf;
|
||||
//[self sendText:text toRoom:room extensionItem:item failureBlock:failureBlock];
|
||||
[self sendText:text toRoom:room extensionItem:item failureBlock:failureBlock];
|
||||
}
|
||||
|
||||
});
|
||||
@@ -148,7 +144,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
|
||||
if (weakSelf)
|
||||
{
|
||||
typeof(self) self = weakSelf;
|
||||
//[self sendText:url.absoluteString toRoom:room extensionItem:item failureBlock:failureBlock];
|
||||
[self sendText:url.absoluteString toRoom:room extensionItem:item failureBlock:failureBlock];
|
||||
}
|
||||
|
||||
});
|
||||
@@ -169,7 +165,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
|
||||
{
|
||||
UIImage *firstImage = [UIImage imageWithData:self.pendingImages.firstObject];
|
||||
UIAlertController *compressionPrompt = [self compressionPromptForImage:firstImage shareBlock:^{
|
||||
//[self sendImages:self.pendingImages withProviders:item.attachments toRoom:room extensionItem:item failureBlock:failureBlock];
|
||||
[self sendImages:self.pendingImages withProviders:item.attachments toRoom:room extensionItem:item failureBlock:failureBlock];
|
||||
}];
|
||||
|
||||
[self.delegate shareExtensionManager:self showImageCompressionPrompt:compressionPrompt];
|
||||
@@ -187,7 +183,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
|
||||
if (weakSelf)
|
||||
{
|
||||
typeof(self) self = weakSelf;
|
||||
//[self sendVideo:videoLocalUrl toRoom:room extensionItem:item failureBlock:failureBlock];
|
||||
[self sendVideo:videoLocalUrl toRoom:room extensionItem:item failureBlock:failureBlock];
|
||||
}
|
||||
|
||||
});
|
||||
@@ -204,7 +200,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
|
||||
if (weakSelf)
|
||||
{
|
||||
typeof(self) self = weakSelf;
|
||||
//[self sendVideo:videoLocalUrl toRoom:room extensionItem:item failureBlock:failureBlock];
|
||||
[self sendVideo:videoLocalUrl toRoom:room extensionItem:item failureBlock:failureBlock];
|
||||
}
|
||||
|
||||
});
|
||||
@@ -232,8 +228,6 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
|
||||
|
||||
- (void)terminateExtensionCanceled:(BOOL)canceled
|
||||
{
|
||||
//[self suspendSession];
|
||||
|
||||
if (canceled)
|
||||
{
|
||||
[self.shareExtensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXUserCancelErrorDomain" code:4201 userInfo:nil]];
|
||||
@@ -407,11 +401,11 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
|
||||
return compressionPrompt;
|
||||
}
|
||||
|
||||
- (void)didStartSendingToRoom:(NSString *)roomID
|
||||
- (void)didStartSendingToRoom:(MXRoom *)room
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(shareExtensionManager:didStartSendingContentToRoom:)])
|
||||
{
|
||||
[self.delegate shareExtensionManager:self didStartSendingContentToRoom:roomID];
|
||||
[self.delegate shareExtensionManager:self didStartSendingContentToRoom:room];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -452,9 +446,9 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
|
||||
|
||||
#pragma mark - Sharing
|
||||
|
||||
- (void)sendText:(NSString *)text toRoom:(NSString *)roomID extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)())failureBlock
|
||||
- (void)sendText:(NSString *)text toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)())failureBlock
|
||||
{
|
||||
[self didStartSendingToRoom:roomID];
|
||||
[self didStartSendingToRoom:room];
|
||||
if (!text)
|
||||
{
|
||||
NSLog(@"[ShareExtensionManager] loadItemForTypeIdentifier: failed.");
|
||||
@@ -466,8 +460,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
|
||||
}
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
|
||||
[self.mxRestClient sendTextMessageToRoom:roomID text:text success:^(NSString *eventId) {
|
||||
[room sendTextMessage:text success:^(NSString *eventId) {
|
||||
if (weakSelf)
|
||||
{
|
||||
typeof(self) self = weakSelf;
|
||||
@@ -482,9 +475,9 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)sendFileWithUrl:(NSURL *)fileUrl toRoom:(NSString *)roomID extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)())failureBlock
|
||||
- (void)sendFileWithUrl:(NSURL *)fileUrl toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)())failureBlock
|
||||
{
|
||||
[self didStartSendingToRoom:roomID];
|
||||
[self didStartSendingToRoom:room];
|
||||
if (!fileUrl)
|
||||
{
|
||||
NSLog(@"[ShareExtensionManager] loadItemForTypeIdentifier: failed.");
|
||||
@@ -502,11 +495,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
|
||||
//self.mxRestClient send
|
||||
|
||||
|
||||
|
||||
/*[room sendFile:fileUrl mimeType:mimeType localEcho:nil success:^(NSString *eventId) {
|
||||
[room sendFile:fileUrl mimeType:mimeType localEcho:nil success:^(NSString *eventId) {
|
||||
if (weakSelf)
|
||||
{
|
||||
typeof(self) self = weakSelf;
|
||||
@@ -518,7 +507,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
|
||||
{
|
||||
failureBlock();
|
||||
}
|
||||
} keepActualFilename:YES];*/
|
||||
} keepActualFilename:YES];
|
||||
}
|
||||
|
||||
|
||||
@@ -596,7 +585,6 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
|
||||
|
||||
if (!imageDatas.count)
|
||||
{
|
||||
//[self suspendSession];
|
||||
[self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user