mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 01:22:46 +02:00
MESSENGER-4743 fix removing room avatar
This commit is contained in:
@@ -132,6 +132,8 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
|
||||
{
|
||||
// The updated user data
|
||||
NSMutableDictionary<NSString*, id> *updatedItemsDict;
|
||||
// bwi #4743: remove room avatar
|
||||
BOOL shouldRemoveRoomAvatarImage;
|
||||
|
||||
// The current table items
|
||||
UITextField* nameTextField;
|
||||
@@ -1342,7 +1344,7 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
|
||||
[self dismissFirstResponder];
|
||||
|
||||
// Check whether some changes have been done
|
||||
if (updatedItemsDict.count)
|
||||
if (updatedItemsDict.count|| shouldRemoveRoomAvatarImage)
|
||||
{
|
||||
[self promptUserToSaveChanges];
|
||||
}
|
||||
@@ -1408,7 +1410,7 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
|
||||
|
||||
- (IBAction)onSave:(id)sender
|
||||
{
|
||||
if (updatedItemsDict.count)
|
||||
if (updatedItemsDict.count || shouldRemoveRoomAvatarImage)
|
||||
{
|
||||
[self startActivityIndicator];
|
||||
|
||||
@@ -1417,6 +1419,42 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
|
||||
// check if there is some updates related to room state
|
||||
if (mxRoomState)
|
||||
{
|
||||
// bwi #4743: remove room avatar
|
||||
if (shouldRemoveRoomAvatarImage) {
|
||||
shouldRemoveRoomAvatarImage = false;
|
||||
[updatedItemsDict removeObjectForKey:kRoomSettingsAvatarKey];
|
||||
pendingOperation = [mxRoom setAvatar:@"" success:^{
|
||||
if (weakSelf)
|
||||
{
|
||||
typeof(self) self = weakSelf;
|
||||
|
||||
self->pendingOperation = nil;
|
||||
|
||||
[self onSave:nil];
|
||||
}
|
||||
} failure:^(NSError *error) {
|
||||
MXLogDebug(@"[RoomSettingsViewController] reset image failed");
|
||||
|
||||
if (weakSelf)
|
||||
{
|
||||
typeof(self) self = weakSelf;
|
||||
|
||||
self->pendingOperation = nil;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
NSString* message = error.localizedDescription;
|
||||
if (!message.length)
|
||||
{
|
||||
message = [VectorL10n roomDetailsFailToUpdateAvatar];
|
||||
}
|
||||
[self onSaveFailed:message withKeys:@[kRoomSettingsAvatarKey]];
|
||||
|
||||
});
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
if (updatedItemsDict[kRoomSettingsAvatarKey])
|
||||
{
|
||||
// Retrieve the current picture and make sure its orientation is up
|
||||
@@ -2226,6 +2264,11 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
|
||||
{
|
||||
roomPhotoCell.mxkImageView.image = (UIImage*) updatedItemsDict[kRoomSettingsAvatarKey];
|
||||
}
|
||||
else if (shouldRemoveRoomAvatarImage) {
|
||||
// bwi #4743: remove room avatar
|
||||
NSString *roomName = mxRoom.summary.displayName;
|
||||
roomPhotoCell.mxkImageView.image = [AvatarGenerator generateAvatarForMatrixItem:mxRoom.roomId withDisplayName:roomName];
|
||||
}
|
||||
else
|
||||
{
|
||||
// bwi if the room is a personal notes room use a local image
|
||||
@@ -3254,6 +3297,8 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
|
||||
if (!mxRoom.isDirect || BWIBuildSettings.shared.showUnrelatedRoomSettingsForDirectMessages) {
|
||||
SingleImagePickerPresenter *singleImagePickerPresenter = [[SingleImagePickerPresenter alloc] initWithSession:self.mainSession];
|
||||
singleImagePickerPresenter.delegate = self;
|
||||
// bwi #4743: remove room avatar
|
||||
singleImagePickerPresenter.allowsRemoveImage = (updatedItemsDict[kRoomSettingsAvatarKey] != nil || (mxRoom.summary.avatar != nil && ![mxRoom.summary.avatar isEqual: @""]));
|
||||
|
||||
UIView *sourceView;
|
||||
|
||||
@@ -3679,6 +3724,12 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
|
||||
// This method should never be called here because room settings should not show the remove image option. But nevertheless we do a nice cleanup also for this delegate call
|
||||
[presenter dismissWithAnimated:YES completion:nil];
|
||||
self.imagePickerPresenter = nil;
|
||||
|
||||
// bwi #4743: the room avatar should be removable
|
||||
[updatedItemsDict removeObjectForKey:kRoomSettingsAvatarKey];
|
||||
shouldRemoveRoomAvatarImage = true;
|
||||
[self getNavigationItem].rightBarButtonItem.enabled = YES;
|
||||
[self refreshRoomSettings];
|
||||
}
|
||||
|
||||
#pragma mark - TableViewSectionsDelegate
|
||||
|
||||
Reference in New Issue
Block a user