Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting for mention permissions #1732

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions NextcloudTalk/NCAPIControllerExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions NextcloudTalk/NCDatabaseManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion NextcloudTalk/NCDatabaseManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";

Expand Down
6 changes: 6 additions & 0 deletions NextcloudTalk/NCRoom.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions NextcloudTalk/NCRoom.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
70 changes: 69 additions & 1 deletion NextcloudTalk/RoomInfoTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
kConversationActionBannedActors,
kConversationActionListable,
kConversationActionListableForEveryone,
kConversationActionMentionPermission,
kConversationActionReadOnly,
kConversationActionShareLink
} ConversationAction;
Expand Down Expand Up @@ -103,6 +104,7 @@
kModificationErrorMessageExpiration,
kModificationErrorRoomDescription,
kModificationErrorBanActor,
kModificationErrorMentionPermissions,
} ModificationError;

typedef enum FileAction {
Expand All @@ -119,6 +121,7 @@ @interface RoomInfoTableViewController () <UITextFieldDelegate, AddParticipantsT
@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;
Expand Down Expand Up @@ -181,7 +184,10 @@ - (void)viewDidLoad

_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];

Expand Down Expand Up @@ -418,6 +424,11 @@ - (NSArray *)getConversationActions
}
}

// 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]];
Expand Down Expand Up @@ -600,6 +611,10 @@ - (void)showRoomModificationError:(ModificationError)error withMessage:(NSString
errorDescription = NSLocalizedString(@"Could not ban participant", nil);
break;

case kModificationErrorMentionPermissions:
errorDescription = NSLocalizedString(@"Could not change mention permissions of the conversation", nil);
break;

default:
break;
}
Expand Down Expand Up @@ -940,6 +955,28 @@ - (void)setListableScope:(NCRoomListableScope)scope
}];
}

- (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) {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions NextcloudTalk/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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";

Expand Down
Loading