mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-19 06:02:12 +02:00
add_invite_rooms_section
Plug the join/reject button The join does not refresh properly the recents.
This commit is contained in:
@@ -21,6 +21,16 @@
|
||||
*/
|
||||
@interface RecentsDataSource : MXKInterleavedRecentsDataSource
|
||||
|
||||
/**
|
||||
The callback when a room invitation is rejected.
|
||||
*/
|
||||
@property (nonatomic, copy) void (^onRoomInvitationReject)(MXRoom*);
|
||||
|
||||
/**
|
||||
The callback when a room invitation is accepted.
|
||||
*/
|
||||
@property (nonatomic, copy) void (^onRoomInvitationAccept)(MXRoom*);
|
||||
|
||||
/**
|
||||
Return the header height from the section.
|
||||
*/
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
@end
|
||||
|
||||
@implementation RecentsDataSource
|
||||
@synthesize onRoomInvitationReject, onRoomInvitationAccept;
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
@@ -217,13 +218,32 @@
|
||||
((MXKInterleavedRecentTableViewCell*)cell).userFlag.backgroundColor = [UIColor clearColor];
|
||||
}
|
||||
|
||||
// on invite cell, add listeners on accept / reject buttons
|
||||
if ([cell isKindOfClass:[InviteRecentTableViewCell class]])
|
||||
{
|
||||
InviteRecentTableViewCell* inviteRecentTableViewCell = (InviteRecentTableViewCell*)cell;
|
||||
|
||||
inviteRecentTableViewCell.onRejectClick = ^(){
|
||||
if (self.onRoomInvitationReject)
|
||||
{
|
||||
self.onRoomInvitationReject(roomData.roomDataSource.room);
|
||||
}
|
||||
};
|
||||
|
||||
inviteRecentTableViewCell.onJoinClick = ^(){
|
||||
if (self.onRoomInvitationAccept)
|
||||
{
|
||||
self.onRoomInvitationAccept(roomData.roomDataSource.room);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
- (id<MXKRecentCellDataStoring>)cellDataAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
id<MXKRecentCellDataStoring> cellData = nil;
|
||||
|
||||
@@ -455,6 +455,28 @@
|
||||
|
||||
- (void)dataSource:(MXKDataSource *)dataSource didCellChange:(id)changes
|
||||
{
|
||||
if ([dataSource isKindOfClass:[RecentsDataSource class]])
|
||||
{
|
||||
RecentsDataSource* recentsDataSource = (RecentsDataSource*)dataSource;
|
||||
|
||||
recentsDataSource.onRoomInvitationReject = ^(MXRoom* room) {
|
||||
|
||||
[self.recentsTableView setEditing:NO];
|
||||
|
||||
[room leave:^{
|
||||
[self.recentsTableView reloadData];
|
||||
} failure:^(NSError *error) {
|
||||
NSLog(@"[RecentsViewController] Failed to reject an invited room (%@) failed: %@", room.state.roomId, error);
|
||||
}];
|
||||
|
||||
};
|
||||
|
||||
recentsDataSource.onRoomInvitationAccept = ^(MXRoom* room) {
|
||||
[self selectRoomWithId:room.state.roomId inMatrixSession:room.mxSession];
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
[self.recentsTableView reloadData];
|
||||
|
||||
if (shouldScrollToTopOnRefresh)
|
||||
@@ -663,6 +685,29 @@ static NSMutableDictionary* backgroundByImageNameDict;
|
||||
return [(RecentsDataSource*)self.dataSource heightForHeaderInSection:section];
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
if (self.delegate)
|
||||
{
|
||||
id<MXKRecentCellDataStoring> cellData = [self.dataSource cellDataAtIndexPath:indexPath];
|
||||
|
||||
// the invited rooms cannot be selected.
|
||||
// the invitation is accepted / rejected with dedicated buttons inside the cell.
|
||||
// cell.userInteractionEnabled = NO would also disable the button so
|
||||
// the cell selection is trapped.
|
||||
if (NSNotFound == [cellData.recentsDataSource.mxSession.invitedRooms indexOfObject:cellData.roomDataSource.room])
|
||||
{
|
||||
[self.delegate recentListViewController:self didSelectRoom:cellData.roomDataSource.roomId inMatrixSession:cellData.roomDataSource.mxSession];
|
||||
}
|
||||
}
|
||||
|
||||
// Hide the keyboard when user select a room
|
||||
// do not hide the searchBar until the view controller disappear
|
||||
// on tablets / iphone 6+, the user could expect to search again while looking at a room
|
||||
[self.recentsSearchBar resignFirstResponder];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Actions.
|
||||
|
||||
- (void)onNewRoomPressed
|
||||
|
||||
@@ -26,4 +26,14 @@
|
||||
@property (weak, nonatomic) IBOutlet UIButton *leftButton;
|
||||
@property (weak, nonatomic) IBOutlet UIButton *rightButton;
|
||||
|
||||
/**
|
||||
The user tap on the reject button
|
||||
*/
|
||||
@property (nonatomic, copy) void (^onRejectClick)();
|
||||
|
||||
/**
|
||||
The user tap on the join button
|
||||
*/
|
||||
@property (nonatomic, copy) void (^onJoinClick)();
|
||||
|
||||
@end
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#import "VectorDesignValues.h"
|
||||
|
||||
@implementation InviteRecentTableViewCell
|
||||
@synthesize onRejectClick, onJoinClick;
|
||||
|
||||
#pragma mark - Class methods
|
||||
|
||||
@@ -35,20 +36,39 @@
|
||||
self.leftButton.backgroundColor = VECTOR_GREEN_COLOR;
|
||||
[self.leftButton setTitle:NSLocalizedStringFromTable(@"join", @"Vector", nil) forState:UIControlStateNormal];
|
||||
[self.leftButton setTitle:NSLocalizedStringFromTable(@"join", @"Vector", nil) forState:UIControlStateHighlighted];
|
||||
[self.leftButton addTarget:self action:@selector(onJoinPressed:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
|
||||
[self.rightButton.layer setCornerRadius:5];
|
||||
self.rightButton.clipsToBounds = YES;
|
||||
self.rightButton.backgroundColor = VECTOR_GREEN_COLOR;
|
||||
[self.rightButton setTitle:NSLocalizedStringFromTable(@"reject", @"Vector", nil) forState:UIControlStateNormal];
|
||||
[self.rightButton setTitle:NSLocalizedStringFromTable(@"reject", @"Vector", nil) forState:UIControlStateHighlighted];
|
||||
|
||||
// the date is not displayed in the invitation cells.
|
||||
self.lastEventDate.hidden = YES;
|
||||
[self.rightButton addTarget:self action:@selector(onRejectedPressed:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
|
||||
- (void)onRejectedPressed:(id)sender
|
||||
{
|
||||
if (self.onRejectClick)
|
||||
{
|
||||
self.onRejectClick();
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onJoinPressed:(id)sender
|
||||
{
|
||||
if (self.onJoinClick)
|
||||
{
|
||||
self.onJoinClick();
|
||||
}
|
||||
}
|
||||
|
||||
- (void)render:(MXKCellData *)cellData
|
||||
{
|
||||
[super render:cellData];
|
||||
|
||||
// the date is not displayed in the invitation cells.
|
||||
self.lastEventDate.hidden = YES;
|
||||
}
|
||||
|
||||
+ (CGFloat)heightForCellData:(MXKCellData *)cellData withMaximumWidth:(CGFloat)maxWidth
|
||||
|
||||
Reference in New Issue
Block a user