mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 09:32:52 +02:00
Feature/2792 function accounts s1
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
#define TABLEVIEW_ROW_CELL_HEIGHT 46
|
||||
#define TABLEVIEW_SECTION_HEADER_HEIGHT 28
|
||||
|
||||
@interface RoomMemberDetailsViewController () <UIGestureRecognizerDelegate, DeviceTableViewCellDelegate, RoomMemberTitleViewDelegate, KeyVerificationCoordinatorBridgePresenterDelegate>
|
||||
@interface RoomMemberDetailsViewController () <UIGestureRecognizerDelegate, DeviceTableViewCellDelegate, RoomMemberTitleViewDelegate, KeyVerificationCoordinatorBridgePresenterDelegate, UITextFieldDelegate>
|
||||
{
|
||||
RoomMemberTitleView* memberTitleView;
|
||||
|
||||
@@ -58,6 +58,12 @@
|
||||
NSMutableArray<NSString*> *directChatsArray;
|
||||
NSInteger directChatsIndex;
|
||||
|
||||
/**
|
||||
List of the direct chats (room ids) with this member.
|
||||
*/
|
||||
NSMutableArray<NSNumber*> *bwiUserLabelsArray;
|
||||
NSInteger bwiUserLabelsIndex;
|
||||
|
||||
/**
|
||||
Devices
|
||||
*/
|
||||
@@ -80,6 +86,9 @@
|
||||
The current visibility of the status bar in this view controller.
|
||||
*/
|
||||
BOOL isStatusBarHidden;
|
||||
|
||||
UITextField *bwiUserLabelTextField;
|
||||
UIButton *bwiUserLabelButton;
|
||||
}
|
||||
|
||||
@property (weak, nonatomic) IBOutlet UIView *roomMemberAvatarHeaderBackground;
|
||||
@@ -107,6 +116,8 @@
|
||||
|
||||
@property(nonatomic) AnalyticsScreenTracker *screenTracker;
|
||||
|
||||
|
||||
@property(nonatomic, strong) UserLabelDefaultService *bwiUserLabelService;
|
||||
@end
|
||||
|
||||
@implementation RoomMemberDetailsViewController
|
||||
@@ -139,6 +150,7 @@
|
||||
adminActionsArray = [[NSMutableArray alloc] init];
|
||||
otherActionsArray = [[NSMutableArray alloc] init];
|
||||
directChatsArray = [[NSMutableArray alloc] init];
|
||||
bwiUserLabelsArray = [[NSMutableArray alloc] init];
|
||||
|
||||
// Keep visible the status bar by default.
|
||||
isStatusBarHidden = NO;
|
||||
@@ -225,6 +237,8 @@
|
||||
{
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
|
||||
[self updateUserLabelTheme];
|
||||
|
||||
[self setNeedsStatusBarAppearanceUpdate];
|
||||
}
|
||||
@@ -291,6 +305,7 @@
|
||||
otherActionsArray = nil;
|
||||
directChatsArray = nil;
|
||||
devicesArray = nil;
|
||||
bwiUserLabelsArray = nil;
|
||||
|
||||
if (UIApplicationWillChangeStatusBarOrientationNotificationObserver)
|
||||
{
|
||||
@@ -331,6 +346,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)displayRoomMember:(MXRoomMember*)roomMember withMatrixRoom:(MXRoom*)room
|
||||
{
|
||||
[super displayRoomMember:roomMember withMatrixRoom:room];
|
||||
|
||||
self.bwiUserLabelService = [[UserLabelDefaultService alloc] init];
|
||||
[self.bwiUserLabelService setRoom:self.mxRoom];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (UIImage*)picturePlaceholder
|
||||
@@ -413,6 +436,10 @@
|
||||
[directChatsArray addObject:directRoomId];
|
||||
}
|
||||
}
|
||||
|
||||
if (BwiBuildSettings.bwiUserLabelsMemberDetailsVisible) {
|
||||
self.roomMemberUserIdLabel.text = [self tmpUserLabel];
|
||||
}
|
||||
}
|
||||
|
||||
// Complete data update and reload table view
|
||||
@@ -519,6 +546,7 @@
|
||||
|
||||
[adminActionsArray removeAllObjects];
|
||||
[otherActionsArray removeAllObjects];
|
||||
[bwiUserLabelsArray removeAllObjects];
|
||||
|
||||
// Consider the case of the user himself
|
||||
if (self.isRoomMemberCurrentUser)
|
||||
@@ -672,9 +700,13 @@
|
||||
{
|
||||
securityActionsArray = @[@(MXKRoomMemberDetailsActionSecurity)];
|
||||
}
|
||||
|
||||
if ( BwiBuildSettings.bwiUserLabelsAdminSettingsVisible && oneSelfPowerLevel >= RoomPowerLevelAdmin) {
|
||||
[bwiUserLabelsArray addObject:@(MXKRoomMemberDetailsActionBwiUserLabelDescription)];
|
||||
[bwiUserLabelsArray addObject:@(MXKRoomMemberDetailsActionBwiUserLabel)];
|
||||
}
|
||||
|
||||
securityIndex = adminToolsIndex = otherActionsIndex = directChatsIndex = devicesIndex = -1;
|
||||
|
||||
securityIndex = adminToolsIndex = otherActionsIndex = directChatsIndex = devicesIndex = bwiUserLabelsIndex = -1;
|
||||
|
||||
if (securityActionsArray.count)
|
||||
{
|
||||
@@ -685,6 +717,12 @@
|
||||
{
|
||||
otherActionsIndex = sectionCount++;
|
||||
}
|
||||
|
||||
if (bwiUserLabelsArray.count && !self.mxRoom.isDirect)
|
||||
{
|
||||
bwiUserLabelsIndex = sectionCount++;
|
||||
}
|
||||
|
||||
if (adminActionsArray.count && !self.mxRoom.isDirect)
|
||||
{
|
||||
adminToolsIndex = sectionCount++;
|
||||
@@ -725,6 +763,10 @@
|
||||
{
|
||||
return (devicesArray.count);
|
||||
}
|
||||
else if (section == bwiUserLabelsIndex)
|
||||
{
|
||||
return (bwiUserLabelsArray.count);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -751,6 +793,10 @@
|
||||
{
|
||||
return [VectorL10n roomParticipantsActionSectionDevices];
|
||||
}
|
||||
else if (section == bwiUserLabelsIndex)
|
||||
{
|
||||
return [NSString stringWithFormat:NSLocalizedStringFromTable(@"bwi_room_member_section_userlabels", @"Bwi", nil), self.mxRoom.summary.displayname];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
@@ -820,6 +866,12 @@
|
||||
case MXKRoomMemberDetailsActionPermalink:
|
||||
title = [VectorL10n roomParticipantsActionPermalink];
|
||||
break;
|
||||
case MXKRoomMemberDetailsActionBwiUserLabelDescription:
|
||||
title = @"bwi functions desc";
|
||||
break;
|
||||
case MXKRoomMemberDetailsActionBwiUserLabel:
|
||||
title = NSLocalizedStringFromTable(@"bwi_room_participants_action_userlabels", @"Bwi", nil);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -998,6 +1050,16 @@
|
||||
|
||||
cell = roomCell;
|
||||
}
|
||||
else if (indexPath.section == bwiUserLabelsIndex)
|
||||
{
|
||||
NSNumber *actionNumber = bwiUserLabelsArray[indexPath.row];
|
||||
|
||||
if (actionNumber.unsignedIntegerValue == MXKRoomMemberDetailsActionBwiUserLabelDescription) {
|
||||
cell = [self bwiCellForFunctionDescription:tableView withIndex:indexPath];
|
||||
} else {
|
||||
cell = [self bwiCellForFunction:tableView withIndex:indexPath];
|
||||
}
|
||||
}
|
||||
else if (indexPath.section == devicesIndex)
|
||||
{
|
||||
DeviceTableViewCell *deviceCell = [tableView dequeueReusableCellWithIdentifier:[DeviceTableViewCell defaultReuseIdentifier] forIndexPath:indexPath];
|
||||
@@ -1434,4 +1496,115 @@
|
||||
keyVerificationCoordinatorBridgePresenter = nil;
|
||||
}
|
||||
|
||||
#pragma mark - bwi functions
|
||||
|
||||
- (UITableViewCell*)bwiCellForFunctionDescription:(UITableView*)tableView withIndex:(NSIndexPath*)indexPath {
|
||||
MXKTableViewCell *functionDescriptionCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCell defaultReuseIdentifier] forIndexPath:indexPath];
|
||||
|
||||
functionDescriptionCell.textLabel.backgroundColor = [UIColor clearColor];
|
||||
functionDescriptionCell.textLabel.numberOfLines = 0;
|
||||
functionDescriptionCell.textLabel.text = NSLocalizedStringFromTable(@"bwi_room_member_userlabels_description", @"Bwi", nil);
|
||||
functionDescriptionCell.textLabel.font = [UIFont systemFontOfSize:14.0];
|
||||
functionDescriptionCell.textLabel.textColor = ThemeService.shared.theme.headerTextPrimaryColor;
|
||||
|
||||
functionDescriptionCell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||
functionDescriptionCell.accessoryType = UITableViewCellAccessoryNone;
|
||||
functionDescriptionCell.contentView.backgroundColor = ThemeService.shared.theme.headerBackgroundColor;
|
||||
functionDescriptionCell.backgroundColor = ThemeService.shared.theme.headerBackgroundColor;
|
||||
|
||||
// extend background color to safe area
|
||||
UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
|
||||
bgView.backgroundColor = ThemeService.shared.theme.headerBackgroundColor;
|
||||
functionDescriptionCell.backgroundView = bgView;
|
||||
|
||||
return functionDescriptionCell;
|
||||
}
|
||||
|
||||
- (UITableViewCell*)bwiCellForFunction:(UITableView*)tableView withIndex:(NSIndexPath*)indexPath {
|
||||
MXKTableViewCellWithTextFieldAndButton *functionCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithTextFieldAndButton defaultReuseIdentifier]];
|
||||
if (!functionCell)
|
||||
{
|
||||
functionCell = [[MXKTableViewCellWithTextFieldAndButton alloc] init];
|
||||
}
|
||||
|
||||
functionCell.mxkTextField.text = [self tmpUserLabel];
|
||||
functionCell.mxkTextField.keyboardType = UIKeyboardTypeDefault;
|
||||
functionCell.mxkTextField.clearButtonMode = UITextFieldViewModeAlways;
|
||||
functionCell.mxkTextField.rightViewMode = UITextFieldViewModeAlways;
|
||||
functionCell.mxkButton.enabled = YES;
|
||||
|
||||
[functionCell.mxkButton addTarget:self action:@selector(onBwiUserLabelButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
bwiUserLabelTextField = functionCell.mxkTextField;
|
||||
bwiUserLabelTextField.delegate = self;
|
||||
|
||||
bwiUserLabelButton = functionCell.mxkButton;
|
||||
|
||||
[self updateUserLabelButtonText];
|
||||
[self updateUserLabelTheme];
|
||||
|
||||
return functionCell;
|
||||
}
|
||||
|
||||
- (void)onBwiUserLabelButtonPressed:(id)sender {
|
||||
NSString* permFunction = [self.bwiUserLabelService getUserLabelWithUser:self.mxRoomMember.userId];
|
||||
|
||||
MXWeakify(self);
|
||||
|
||||
[self.bwiUserLabelService setCompletion:^(BOOL success) {
|
||||
if (success) {
|
||||
[weakself updateUserLabelButtonText];
|
||||
[weakself updateMemberInfo];
|
||||
}
|
||||
}];
|
||||
|
||||
if (permFunction && [permFunction isEqualToString:bwiUserLabelTextField.text]) {
|
||||
[self.bwiUserLabelService setUserLabelWithUserLabel:nil user:self.mxRoomMember.userId];
|
||||
bwiUserLabelTextField.text = nil;
|
||||
} else {
|
||||
[self.bwiUserLabelService setUserLabelWithUserLabel:bwiUserLabelTextField.text user:self.mxRoomMember.userId];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateUserLabelTheme {
|
||||
bwiUserLabelTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:NSLocalizedStringFromTable(@"bwi_room_member_userlabels_textfield_placeholder", @"Bwi", nil) attributes:@{NSForegroundColorAttributeName: ThemeService.shared.theme.textQuinaryColor}];
|
||||
|
||||
bwiUserLabelTextField.textColor = ThemeService.shared.theme.textSecondaryColor;
|
||||
bwiUserLabelTextField.tintColor = ThemeService.shared.theme.tintColor;
|
||||
bwiUserLabelTextField.backgroundColor = ThemeService.shared.theme.backgroundColor;
|
||||
}
|
||||
|
||||
- (NSString*)tmpUserLabel {
|
||||
NSString* label;
|
||||
if (bwiUserLabelTextField && bwiUserLabelTextField.text.length > 0) {
|
||||
label = bwiUserLabelTextField.text;
|
||||
} else {
|
||||
label = [self.bwiUserLabelService getUserLabelWithUser:self.mxRoomMember.userId];
|
||||
}
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
- (void)updateUserLabelButtonText {
|
||||
NSString* tmpFunction = bwiUserLabelTextField.text;
|
||||
NSString* permFunction = [self.bwiUserLabelService getUserLabelWithUser:self.mxRoomMember.userId];
|
||||
|
||||
NSString* title;
|
||||
|
||||
if (permFunction && [permFunction isEqualToString:tmpFunction]) {
|
||||
title = NSLocalizedStringFromTable(@"bwi_room_member_userlabels_button_delete", @"Bwi", nil);
|
||||
} else {
|
||||
title = NSLocalizedStringFromTable(@"bwi_room_member_userlabels_button_save", @"Bwi", nil);
|
||||
}
|
||||
|
||||
[bwiUserLabelButton setTitle:title forState:UIControlStateNormal];
|
||||
[bwiUserLabelButton setTitle:title forState:UIControlStateHighlighted];
|
||||
}
|
||||
|
||||
#pragma mark bwi textfield delegate
|
||||
|
||||
-(void) textFieldDidChangeSelection:(UITextField *)textField {
|
||||
[self updateUserLabelButtonText];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user