Merge pull request #1732 from nextcloud/prevent-at-all

Add setting for mention permissions
This commit is contained in:
Marcel Müller 2024-07-30 19:57:16 +02:00 коммит произвёл GitHub
Родитель 1f5514688e dda791707f
Коммит e8a7301b04
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
7 изменённых файлов: 100 добавлений и 2 удалений

Просмотреть файл

@ -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) {

Просмотреть файл

@ -72,6 +72,7 @@ extern NSString * const kCapabilityFederationV1;
extern NSString * const kCapabilityFederationV2;
extern NSString * const kCapabilityChatReadLast;
extern NSString * const kCapabilityBanV1;
extern NSString * const kCapabilityMentionPermissions;
extern NSString * const kNotificationsCapabilityExists;

Просмотреть файл

@ -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";
@ -73,6 +73,7 @@ NSString * const kCapabilityFederationV1 = @"federation-v1";
NSString * const kCapabilityFederationV2 = @"federation-v2";
NSString * const kCapabilityChatReadLast = @"chat-read-last";
NSString * const kCapabilityBanV1 = @"ban-v1";
NSString * const kCapabilityMentionPermissions = @"mention-permissions";
NSString * const kNotificationsCapabilityExists = @"exists";

Просмотреть файл

@ -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;

Просмотреть файл

@ -61,6 +61,7 @@ NSString * const NCRoomObjectTypeRoom = @"room";
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 @@ NSString * const NCRoomObjectTypeRoom = @"room";
managedRoom.recordingConsent = room.recordingConsent;
managedRoom.remoteToken = room.remoteToken;
managedRoom.remoteServer = room.remoteServer;
managedRoom.mentionPermissions = room.mentionPermissions;
}
+ (NSString *)primaryKey {

Просмотреть файл

@ -59,6 +59,7 @@ typedef enum ConversationAction {
kConversationActionBannedActors,
kConversationActionListable,
kConversationActionListableForEveryone,
kConversationActionMentionPermission,
kConversationActionReadOnly,
kConversationActionShareLink
} ConversationAction;
@ -103,6 +104,7 @@ typedef enum ModificationError {
kModificationErrorMessageExpiration,
kModificationErrorRoomDescription,
kModificationErrorBanActor,
kModificationErrorMentionPermissions,
} ModificationError;
typedef enum FileAction {
@ -119,6 +121,7 @@ typedef enum FileAction {
@property (nonatomic, strong) UISwitch *publicSwitch;
@property (nonatomic, strong) UISwitch *listableSwitch;
@property (nonatomic, strong) UISwitch *listableForEveryoneSwitch;
@property (nonatomic, strong) UISwitch *mentionPermissionsSwitch;
@property (nonatomic, strong) UISwitch *readOnlySwitch;
@property (nonatomic, strong) UISwitch *lobbySwitch;
@property (nonatomic, strong) UISwitch *sipSwitch;
@ -181,7 +184,10 @@ typedef enum FileAction {
_listableForEveryoneSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
[_listableForEveryoneSwitch addTarget: self action: @selector(listableForEveryoneValueChanged:) forControlEvents:UIControlEventValueChanged];
_mentionPermissionsSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
[_mentionPermissionsSwitch addTarget: self action: @selector(mentionPermissionsValueChanged:) forControlEvents:UIControlEventValueChanged];
_readOnlySwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
[_readOnlySwitch addTarget: self action: @selector(readOnlyValueChanged:) forControlEvents:UIControlEventValueChanged];
@ -418,6 +424,11 @@ typedef enum FileAction {
}
}
// Mention permission
if ([[NCDatabaseManager sharedInstance] serverHasTalkCapability:kCapabilityMentionPermissions]) {
[actions addObject:[NSNumber numberWithInt:kConversationActionMentionPermission]];
}
// Read only room action
if ([[NCDatabaseManager sharedInstance] serverHasTalkCapability:kCapabilityReadOnlyRooms]) {
[actions addObject:[NSNumber numberWithInt:kConversationActionReadOnly]];
@ -600,6 +611,10 @@ typedef enum FileAction {
errorDescription = NSLocalizedString(@"Could not ban participant", nil);
break;
case kModificationErrorMentionPermissions:
errorDescription = NSLocalizedString(@"Could not change mention permissions of the conversation", nil);
break;
default:
break;
}
@ -940,6 +955,28 @@ typedef enum FileAction {
}];
}
- (void)setMentionPermissions:(NCRoomMentionPermissions)permissions
{
if (permissions == _room.mentionPermissions) {
return;
}
[self setModifyingRoomUI];
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
[[NCAPIController sharedInstance] setMentionPermissions:permissions forRoom:_room.token forAccount:activeAccount completionBlock:^(NSError * _Nullable error) {
if (!error) {
[[NCRoomsManager sharedInstance] updateRoom:self->_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 @@ typedef enum FileAction {
}
}
#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 @@ typedef enum FileAction {
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 @@ typedef enum FileAction {
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;

Просмотреть файл

@ -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";