зеркало из https://github.com/nextcloud/talk-ios.git
Allow to set room's message expiration time.
Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Родитель
bfff426217
Коммит
16cc7e75dc
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "baseline_auto_delete_black_24pt_1x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"filename" : "baseline_auto_delete_black_24pt_2x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"filename" : "baseline_auto_delete_black_24pt_3x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
Двоичные данные
NextcloudTalk/Images.xcassets/auto-delete.imageset/baseline_auto_delete_black_24pt_1x.png
поставляемый
Normal file
Двоичные данные
NextcloudTalk/Images.xcassets/auto-delete.imageset/baseline_auto_delete_black_24pt_1x.png
поставляемый
Normal file
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 246 B |
Двоичные данные
NextcloudTalk/Images.xcassets/auto-delete.imageset/baseline_auto_delete_black_24pt_2x.png
поставляемый
Normal file
Двоичные данные
NextcloudTalk/Images.xcassets/auto-delete.imageset/baseline_auto_delete_black_24pt_2x.png
поставляемый
Normal file
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 432 B |
Двоичные данные
NextcloudTalk/Images.xcassets/auto-delete.imageset/baseline_auto_delete_black_24pt_3x.png
поставляемый
Normal file
Двоичные данные
NextcloudTalk/Images.xcassets/auto-delete.imageset/baseline_auto_delete_black_24pt_3x.png
поставляемый
Normal file
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 668 B |
|
@ -49,6 +49,7 @@ typedef void (^ReadOnlyCompletionBlock)(NSError *error);
|
|||
typedef void (^SetLobbyStateCompletionBlock)(NSError *error);
|
||||
typedef void (^SetSIPStateCompletionBlock)(NSError *error);
|
||||
typedef void (^ListableCompletionBlock)(NSError *error);
|
||||
typedef void (^MessageExpirationCompletionBlock)(NSError *error);
|
||||
|
||||
typedef void (^GetParticipantsFromRoomCompletionBlock)(NSMutableArray *participants, NSError *error);
|
||||
typedef void (^LeaveRoomCompletionBlock)(NSInteger errorCode, NSError *error);
|
||||
|
@ -149,6 +150,7 @@ extern NSInteger const kReceivedChatMessagesLimit;
|
|||
- (NSURLSessionDataTask *)setLobbyState:(NCRoomLobbyState)state withTimer:(NSInteger)timer forRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(SetLobbyStateCompletionBlock)block;
|
||||
- (NSURLSessionDataTask *)setSIPEnabled:(BOOL)enabled forRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(SetSIPStateCompletionBlock)block;
|
||||
- (NSURLSessionDataTask *)setListableScope:(NCRoomListableScope)scope forRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(ListableCompletionBlock)block;
|
||||
- (NSURLSessionDataTask *)setMessageExpiration:(NCMessageExpiration)messageExpiration forRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(MessageExpirationCompletionBlock)block;
|
||||
|
||||
// Participants Controller
|
||||
- (NSURLSessionDataTask *)getParticipantsFromRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(GetParticipantsFromRoomCompletionBlock)block;
|
||||
|
|
|
@ -760,6 +760,30 @@ NSInteger const kReceivedChatMessagesLimit = 100;
|
|||
return task;
|
||||
}
|
||||
|
||||
- (NSURLSessionDataTask *)setMessageExpiration:(NCMessageExpiration)messageExpiration forRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(MessageExpirationCompletionBlock)block
|
||||
{
|
||||
NSString *encodedToken = [token stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
|
||||
NSString *endpoint = [NSString stringWithFormat:@"room/%@/message-expiration", encodedToken];
|
||||
NSInteger conversationAPIVersion = [self conversationAPIVersionForAccount:account];
|
||||
NSString *URLString = [self getRequestURLForEndpoint:endpoint withAPIVersion:conversationAPIVersion forAccount:account];
|
||||
NSDictionary *parameters = @{@"seconds" : @(messageExpiration)};
|
||||
|
||||
NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId];
|
||||
NSURLSessionDataTask *task = [apiSessionManager POST:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
||||
if (block) {
|
||||
block(nil);
|
||||
}
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
NSInteger statusCode = [self getResponseStatusCode:task.response];
|
||||
[self checkResponseStatusCode:statusCode forAccount:account];
|
||||
if (block) {
|
||||
block(error);
|
||||
}
|
||||
}];
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
#pragma mark - Participants Controller
|
||||
|
||||
- (NSURLSessionDataTask *)getParticipantsFromRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(GetParticipantsFromRoomCompletionBlock)block
|
||||
|
|
|
@ -68,6 +68,15 @@ typedef enum NCPermission {
|
|||
NCPermissionChat = 128,
|
||||
} NCPermission;
|
||||
|
||||
typedef enum NCMessageExpiration {
|
||||
NCMessageExpirationOff = 0,
|
||||
NCMessageExpiration1Hour = 3600,
|
||||
NCMessageExpiration8Hours = 28800,
|
||||
NCMessageExpiration1Day = 86400,
|
||||
NCMessageExpiration1Week = 604800,
|
||||
NCMessageExpiration4Weeks = 2419200,
|
||||
} NCMessageExpiration;
|
||||
|
||||
extern NSString * const NCRoomObjectTypeFile;
|
||||
extern NSString * const NCRoomObjectTypeSharePassword;
|
||||
|
||||
|
@ -137,6 +146,8 @@ extern NSString * const NCRoomObjectTypeSharePassword;
|
|||
- (NSString *)deletionMessage;
|
||||
- (NSString *)notificationLevelString;
|
||||
- (NSString *)stringForNotificationLevel:(NCRoomNotificationLevel)level;
|
||||
- (NSString *)messageExpirationString;
|
||||
- (NSString *)stringForMessageExpiration:(NSInteger)messageExpiration;
|
||||
- (NSString *)lastMessageString;
|
||||
- (NCChatMessage *)lastMessage;
|
||||
|
||||
|
|
|
@ -266,6 +266,36 @@ NSString * const NCRoomObjectTypeSharePassword = @"share:password";
|
|||
return levelString;
|
||||
}
|
||||
|
||||
- (NSString *)messageExpirationString
|
||||
{
|
||||
return [self stringForMessageExpiration:self.messageExpiration];
|
||||
}
|
||||
|
||||
- (NSString *)stringForMessageExpiration:(NSInteger)messageExpiration
|
||||
{
|
||||
NSString *levelString = NSLocalizedString(@"Off", nil);
|
||||
switch (messageExpiration) {
|
||||
case NCMessageExpiration4Weeks:
|
||||
levelString = NSLocalizedString(@"4 weeks", nil);
|
||||
break;
|
||||
case NCMessageExpiration1Week:
|
||||
levelString = NSLocalizedString(@"1 week", nil);
|
||||
break;
|
||||
case NCMessageExpiration1Day:
|
||||
levelString = NSLocalizedString(@"1 day", nil);
|
||||
break;
|
||||
case NCMessageExpiration8Hours:
|
||||
levelString = NSLocalizedString(@"8 hours", nil);
|
||||
break;
|
||||
case NCMessageExpiration1Hour:
|
||||
levelString = NSLocalizedString(@"1 hour", nil);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return levelString;
|
||||
}
|
||||
|
||||
- (NSString *)lastMessageString
|
||||
{
|
||||
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
|
||||
|
|
|
@ -76,7 +76,8 @@ typedef enum GuestAction {
|
|||
} GuestAction;
|
||||
|
||||
typedef enum ConversationAction {
|
||||
kConversationActionListable = 0,
|
||||
kConversationActionMessageExpiration = 0,
|
||||
kConversationActionListable,
|
||||
kConversationActionListableForEveryone,
|
||||
kConversationActionReadOnly
|
||||
} ConversationAction;
|
||||
|
@ -116,7 +117,8 @@ typedef enum ModificationError {
|
|||
kModificationErrorDelete,
|
||||
kModificationErrorClearHistory,
|
||||
kModificationErrorListable,
|
||||
kModificationErrorReadOnly
|
||||
kModificationErrorReadOnly,
|
||||
kModificationErrorMessageExpiration
|
||||
} ModificationError;
|
||||
|
||||
typedef enum FileAction {
|
||||
|
@ -418,6 +420,11 @@ typedef enum FileAction {
|
|||
- (NSArray *)getConversationActions
|
||||
{
|
||||
NSMutableArray *actions = [[NSMutableArray alloc] init];
|
||||
// Message expiration action
|
||||
if ([[NCDatabaseManager sharedInstance] serverHasTalkCapability:kCapabilityMessageExpiration]) {
|
||||
[actions addObject:[NSNumber numberWithInt:kConversationActionMessageExpiration]];
|
||||
}
|
||||
|
||||
// Listable room action
|
||||
if ([[NCDatabaseManager sharedInstance] serverHasTalkCapability:kCapabilityListableRooms]) {
|
||||
[actions addObject:[NSNumber numberWithInt:kConversationActionListable]];
|
||||
|
@ -577,6 +584,10 @@ typedef enum FileAction {
|
|||
errorDescription = NSLocalizedString(@"Could not change read-only state of the conversation", nil);
|
||||
break;
|
||||
|
||||
case kModificationErrorMessageExpiration:
|
||||
errorDescription = NSLocalizedString(@"Could not set message expiration time", nil);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -667,6 +678,40 @@ typedef enum FileAction {
|
|||
return action;
|
||||
}
|
||||
|
||||
- (void)presentMessageExpirationSelector
|
||||
{
|
||||
UIAlertController *optionsActionSheet =
|
||||
[UIAlertController alertControllerWithTitle:NSLocalizedString(@"Message expiration time", nil)
|
||||
message:nil
|
||||
preferredStyle:UIAlertControllerStyleActionSheet];
|
||||
[optionsActionSheet addAction:[self actionForMessageExpiration:NCMessageExpirationOff]];
|
||||
[optionsActionSheet addAction:[self actionForMessageExpiration:NCMessageExpiration4Weeks]];
|
||||
[optionsActionSheet addAction:[self actionForMessageExpiration:NCMessageExpiration1Week]];
|
||||
[optionsActionSheet addAction:[self actionForMessageExpiration:NCMessageExpiration1Day]];
|
||||
[optionsActionSheet addAction:[self actionForMessageExpiration:NCMessageExpiration8Hours]];
|
||||
[optionsActionSheet addAction:[self actionForMessageExpiration:NCMessageExpiration1Hour]];
|
||||
[optionsActionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil]];
|
||||
|
||||
// Presentation on iPads
|
||||
optionsActionSheet.popoverPresentationController.sourceView = self.tableView;
|
||||
optionsActionSheet.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:[self getIndexPathForNotificationAction:kNotificationActionChatNotifications]];
|
||||
|
||||
[self presentViewController:optionsActionSheet animated:YES completion:nil];
|
||||
}
|
||||
|
||||
- (UIAlertAction *)actionForMessageExpiration:(NCMessageExpiration)messageExpiration
|
||||
{
|
||||
UIAlertAction *action = [UIAlertAction actionWithTitle:[_room stringForMessageExpiration:messageExpiration]
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^void (UIAlertAction *action) {
|
||||
[self setMessageExpiration:messageExpiration];
|
||||
}];
|
||||
if (_room.messageExpiration == messageExpiration) {
|
||||
[action setValue:[[UIImage imageNamed:@"checkmark"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"];
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
#pragma mark - Room Manager notifications
|
||||
|
||||
- (void)didUpdateRoom:(NSNotification *)notification
|
||||
|
@ -733,6 +778,23 @@ typedef enum FileAction {
|
|||
}];
|
||||
}
|
||||
|
||||
- (void)setMessageExpiration:(NCMessageExpiration)messageExpiration
|
||||
{
|
||||
if (messageExpiration == _room.messageExpiration) {
|
||||
return;
|
||||
}
|
||||
[self setModifyingRoomUI];
|
||||
[[NCAPIController sharedInstance] setMessageExpiration:messageExpiration forRoom:_room.token forAccount:[[NCDatabaseManager sharedInstance] activeAccount] withCompletionBlock:^(NSError *error) {
|
||||
if (!error) {
|
||||
[[NCRoomsManager sharedInstance] updateRoom:self->_room.token];
|
||||
} else {
|
||||
NSLog(@"Error setting message expiration time: %@", error.description);
|
||||
[self.tableView reloadData];
|
||||
[self showRoomModificationError:kModificationErrorMessageExpiration];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setCallNotificationEnabled:(BOOL)enabled
|
||||
{
|
||||
[self setModifyingRoomUI];
|
||||
|
@ -1614,6 +1676,7 @@ typedef enum FileAction {
|
|||
static NSString *leaveRoomCellIdentifier = @"LeaveRoomCellIdentifier";
|
||||
static NSString *deleteRoomCellIdentifier = @"DeleteRoomCellIdentifier";
|
||||
static NSString *sharedItemsCellIdentifier = @"SharedItemsCellIdentifier";
|
||||
static NSString *messageExpirationCellIdentifier = @"MessageExpirationCellIdentifier";
|
||||
static NSString *listableCellIdentifier = @"ListableCellIdentifier";
|
||||
static NSString *listableForEveryoneCellIdentifier = @"ListableForEveryoneCellIdentifier";
|
||||
static NSString *readOnlyStateCellIdentifier = @"ReadOnlyStateCellIdentifier";
|
||||
|
@ -1873,6 +1936,21 @@ typedef enum FileAction {
|
|||
NSArray *actions = [self getConversationActions];
|
||||
ConversationAction action = [[actions objectAtIndex:indexPath.row] intValue];
|
||||
switch (action) {
|
||||
case kConversationActionMessageExpiration:
|
||||
{
|
||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:messageExpirationCellIdentifier];
|
||||
if (!cell) {
|
||||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:messageExpirationCellIdentifier];
|
||||
}
|
||||
|
||||
cell.textLabel.text = NSLocalizedString(@"Message expiration", nil);
|
||||
cell.detailTextLabel.text = _room.messageExpirationString;
|
||||
[cell.imageView setImage:[[UIImage imageNamed:@"auto-delete"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
|
||||
cell.imageView.tintColor = [UIColor colorWithRed:0.43 green:0.43 blue:0.45 alpha:1];
|
||||
|
||||
return cell;
|
||||
}
|
||||
break;
|
||||
case kConversationActionListable:
|
||||
{
|
||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:listableCellIdentifier];
|
||||
|
@ -2217,6 +2295,19 @@ typedef enum FileAction {
|
|||
}
|
||||
}
|
||||
break;
|
||||
case kRoomInfoSectionConversation:
|
||||
{
|
||||
NSArray *actions = [self getConversationActions];
|
||||
ConversationAction action = [[actions objectAtIndex:indexPath.row] intValue];
|
||||
switch (action) {
|
||||
case kConversationActionMessageExpiration:
|
||||
[self presentMessageExpirationSelector];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case kRoomInfoSectionParticipants:
|
||||
{
|
||||
NCRoomParticipant *participant = [_roomParticipants objectAtIndex:indexPath.row];
|
||||
|
|
Загрузка…
Ссылка в новой задаче