From dda791707f178ea95ceb3af8116dbfb7c4394791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Sun, 28 Jul 2024 12:10:08 +0200 Subject: [PATCH] Add setting for mention permissions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- NextcloudTalk/NCAPIControllerExtensions.swift | 14 ++++ NextcloudTalk/NCDatabaseManager.h | 1 + NextcloudTalk/NCDatabaseManager.m | 3 +- NextcloudTalk/NCRoom.h | 6 ++ NextcloudTalk/NCRoom.m | 2 + NextcloudTalk/RoomInfoTableViewController.m | 70 ++++++++++++++++++- NextcloudTalk/en.lproj/Localizable.strings | 6 ++ 7 files changed, 100 insertions(+), 2 deletions(-) diff --git a/NextcloudTalk/NCAPIControllerExtensions.swift b/NextcloudTalk/NCAPIControllerExtensions.swift index e61fbef71..f931f9092 100644 --- a/NextcloudTalk/NCAPIControllerExtensions.swift +++ b/NextcloudTalk/NCAPIControllerExtensions.swift @@ -128,6 +128,20 @@ import Foundation } } + public func setMentionPermissions(_ permissions: NCRoomMentionPermissions, forRoom token: String, forAccount account: TalkAccount, completionBlock: @escaping (_ error: Error?) -> Void) { + guard let apiSessionManager = self.apiSessionManagers.object(forKey: account.accountId) as? NCAPISessionManager, + let encodedToken = token.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) + else { return } + + let apiVersion = self.conversationAPIVersion(for: account) + let urlString = self.getRequestURL(forEndpoint: "room/\(encodedToken)/mention-permissions", withAPIVersion: apiVersion, for: account) + let parameters: [String: Int] = ["mentionPermissions": permissions.rawValue] + + apiSessionManager.putOcs(urlString, account: account, parameters: parameters) { _, error in + completionBlock(error) + } + } + // MARK: - Federation public func acceptFederationInvitation(for accountId: String, with invitationId: Int, completionBlock: @escaping (_ success: Bool) -> Void) { diff --git a/NextcloudTalk/NCDatabaseManager.h b/NextcloudTalk/NCDatabaseManager.h index 5a55eae69..1c537a224 100644 --- a/NextcloudTalk/NCDatabaseManager.h +++ b/NextcloudTalk/NCDatabaseManager.h @@ -71,6 +71,7 @@ extern NSString * const kCapabilityDeleteMessagesUnlimited; extern NSString * const kCapabilityFederationV1; extern NSString * const kCapabilityChatReadLast; extern NSString * const kCapabilityBanV1; +extern NSString * const kCapabilityMentionPermissions; extern NSString * const kNotificationsCapabilityExists; diff --git a/NextcloudTalk/NCDatabaseManager.m b/NextcloudTalk/NCDatabaseManager.m index b901b835c..ad97ba601 100644 --- a/NextcloudTalk/NCDatabaseManager.m +++ b/NextcloudTalk/NCDatabaseManager.m @@ -16,7 +16,7 @@ NSString *const kTalkDatabaseFolder = @"Library/Application Support/Talk"; NSString *const kTalkDatabaseFileName = @"talk.realm"; -uint64_t const kTalkDatabaseSchemaVersion = 65; +uint64_t const kTalkDatabaseSchemaVersion = 66; NSString * const kCapabilitySystemMessages = @"system-messages"; NSString * const kCapabilityNotificationLevels = @"notification-levels"; @@ -72,6 +72,7 @@ NSString * const kCapabilityFederationV1 = @"federation-v1"; NSString * const kCapabilityChatReadLast = @"chat-read-last"; NSString * const kCapabilityBanV1 = @"ban-v1"; +NSString * const kCapabilityMentionPermissions = @"mention-permissions"; NSString * const kNotificationsCapabilityExists = @"exists"; diff --git a/NextcloudTalk/NCRoom.h b/NextcloudTalk/NCRoom.h index 6d9d516fb..8f0a65dd5 100644 --- a/NextcloudTalk/NCRoom.h +++ b/NextcloudTalk/NCRoom.h @@ -36,6 +36,11 @@ typedef NS_ENUM(NSInteger, NCRoomListableScope) { NCRoomListableScopeEveryone }; +typedef NS_ENUM(NSInteger, NCRoomMentionPermissions) { + NCRoomMentionPermissionsEveryone = 0, + NCRoomMentionPermissionsModeratorsOnly +}; + typedef NS_ENUM(NSInteger, NCRoomLobbyState) { NCRoomLobbyStateAllParticipants = 0, NCRoomLobbyStateModeratorsOnly @@ -137,6 +142,7 @@ extern NSString * const NCRoomObjectTypeRoom; @property (nonatomic, copy) NSString *remoteServer; @property (nonatomic, copy) NSString *remoteToken; @property (nonatomic, copy) NSString *lastReceivedProxyHash; +@property (nonatomic, assign) NSInteger mentionPermissions; + (instancetype)roomWithDictionary:(NSDictionary *)roomDict; + (instancetype)roomWithDictionary:(NSDictionary *)roomDict andAccountId:(NSString *)accountId; diff --git a/NextcloudTalk/NCRoom.m b/NextcloudTalk/NCRoom.m index 0bb9fcf58..99c36900c 100644 --- a/NextcloudTalk/NCRoom.m +++ b/NextcloudTalk/NCRoom.m @@ -61,6 +61,7 @@ + (instancetype)roomWithDictionary:(NSDictionary *)roomDict room.recordingConsent = [[roomDict objectForKey:@"recordingConsent"] integerValue]; room.remoteServer = [roomDict objectForKey:@"remoteServer"]; room.remoteToken = [roomDict objectForKey:@"remoteToken"]; + room.mentionPermissions = [[roomDict objectForKey:@"mentionPermissions"] integerValue]; // Local-only field -> update only if there's actually a value if ([roomDict objectForKey:@"pendingMessage"] != nil) { @@ -191,6 +192,7 @@ + (void)updateRoom:(NCRoom *)managedRoom withRoom:(NCRoom *)room managedRoom.recordingConsent = room.recordingConsent; managedRoom.remoteToken = room.remoteToken; managedRoom.remoteServer = room.remoteServer; + managedRoom.mentionPermissions = room.mentionPermissions; } + (NSString *)primaryKey { diff --git a/NextcloudTalk/RoomInfoTableViewController.m b/NextcloudTalk/RoomInfoTableViewController.m index 00de260a2..cb843e9e1 100644 --- a/NextcloudTalk/RoomInfoTableViewController.m +++ b/NextcloudTalk/RoomInfoTableViewController.m @@ -59,6 +59,7 @@ kConversationActionBannedActors, kConversationActionListable, kConversationActionListableForEveryone, + kConversationActionMentionPermission, kConversationActionReadOnly, kConversationActionShareLink } ConversationAction; @@ -103,6 +104,7 @@ kModificationErrorMessageExpiration, kModificationErrorRoomDescription, kModificationErrorBanActor, + kModificationErrorMentionPermissions, } ModificationError; typedef enum FileAction { @@ -119,6 +121,7 @@ @interface RoomInfoTableViewController () _room.token withCompletionBlock:nil]; + } else { + NSLog(@"Error setting room mention permissions state: %@", error.description); + [self.tableView reloadData]; + [self showRoomModificationError:kModificationErrorMentionPermissions]; + } + + self->_mentionPermissionsSwitch.enabled = true; + }]; +} + - (void)setReadOnlyState:(NCRoomReadOnlyState)state { if (state == _room.readOnlyState) { @@ -1455,6 +1492,18 @@ - (void)listableForEveryoneValueChanged:(id)sender } } +#pragma mark - Mention permissions switch + +- (void)mentionPermissionsValueChanged:(id)sender +{ + _mentionPermissionsSwitch.enabled = NO; + if (_mentionPermissionsSwitch.on) { + [self setMentionPermissions:NCRoomMentionPermissionsEveryone]; + } else { + [self setMentionPermissions:NCRoomMentionPermissionsModeratorsOnly]; + } +} + #pragma mark - ReadOnly switch @@ -1697,6 +1746,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N static NSString *bannedActorsCellIdentifier = @"BannedActorsCellIdentifier"; static NSString *listableCellIdentifier = @"ListableCellIdentifier"; static NSString *listableForEveryoneCellIdentifier = @"ListableForEveryoneCellIdentifier"; + static NSString *mentionPermissionsCellIdentifier = @"mentionPermissionsCellIdentifier"; static NSString *readOnlyStateCellIdentifier = @"ReadOnlyStateCellIdentifier"; NSArray *sections = [self getRoomInfoSections]; @@ -1986,6 +2036,24 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell.imageView.tintColor = [UIColor secondaryLabelColor]; [cell.imageView setHidden:YES]; + return cell; + } + break; + case kConversationActionMentionPermission: + { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:mentionPermissionsCellIdentifier]; + if (!cell) { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:mentionPermissionsCellIdentifier]; + } + + cell.textLabel.text = NSLocalizedString(@"Allow participants to mention @all", @"'@all' should not be translated"); + cell.textLabel.numberOfLines = 0; + cell.selectionStyle = UITableViewCellSelectionStyleNone; + cell.accessoryView = _mentionPermissionsSwitch; + _mentionPermissionsSwitch.on = (_room.mentionPermissions == NCRoomMentionPermissionsEveryone); + [cell.imageView setImage:[UIImage systemImageNamed:@"at.circle"]]; + cell.imageView.tintColor = [UIColor secondaryLabelColor]; + return cell; } break; diff --git a/NextcloudTalk/en.lproj/Localizable.strings b/NextcloudTalk/en.lproj/Localizable.strings index dc89d3c0a..6f2107a29 100644 --- a/NextcloudTalk/en.lproj/Localizable.strings +++ b/NextcloudTalk/en.lproj/Localizable.strings @@ -127,6 +127,9 @@ /* No comment provided by engineer. */ "Allow guests" = "Allow guests"; +/* '@all' should not be translated */ +"Allow participants to mention @all" = "Allow participants to mention @all"; + /* No comment provided by engineer. */ "Allow to dial-in without a pin" = "Allow to dial-in without a pin"; @@ -511,6 +514,9 @@ /* No comment provided by engineer. */ "Could not change lobby state of the conversation" = "Could not change lobby state of the conversation"; +/* No comment provided by engineer. */ +"Could not change mention permissions of the conversation" = "Could not change mention permissions of the conversation"; + /* No comment provided by engineer. */ "Could not change moderation permissions of the participant" = "Could not change moderation permissions of the participant";