From bb1d160373e20da1995d075f162172d0f78a783f Mon Sep 17 00:00:00 2001 From: Christophe Deschamps Date: Fri, 17 Sep 2021 10:28:14 +0200 Subject: [PATCH] Ephemeral messages in session mode --- Classes/ChatConversationView.m | 13 ++++++++++--- Classes/PhoneMainView.m | 5 ++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 0a4517f9b..0761a3c08 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -1628,6 +1628,13 @@ void on_chat_room_conference_alert(LinphoneChatRoom *cr, const LinphoneEventLog // Popup menu +-(BOOL) canAdminEphemeral:(LinphoneChatRoom *)cr { + return linphone_chat_room_has_capability(cr, LinphoneChatRoomCapabilitiesEphemeral) && ( + (linphone_chat_room_params_get_ephemeral_mode(linphone_chat_room_get_current_params(cr)) == LinphoneChatRoomEphemeralModeDeviceManaged) || + (linphone_chat_room_params_get_ephemeral_mode(linphone_chat_room_get_current_params(cr)) == LinphoneChatRoomEphemeralModeAdminManaged && linphone_participant_is_admin(linphone_chat_room_get_me(cr))) + ); +} + - (void) setupPopupMenu { _popupMenu.dataSource = self; @@ -1652,7 +1659,7 @@ void on_chat_room_conference_alert(LinphoneChatRoom *cr, const LinphoneEventLog [_tableController onEditClick:nil]; [self onEditionChangeClick:nil]; } - if ([ConfigManager.instance lpConfigBoolForKeyWithKey:@"ephemeral_feature" defaultValue:false]) { + if ([ConfigManager.instance lpConfigBoolForKeyWithKey:@"ephemeral_feature" defaultValue:false] && [self canAdminEphemeral:_chatRoom]) { if (indexPath.row == 2) { EphemeralSettingsView *view = VIEW(EphemeralSettingsView); view.room = _chatRoom; @@ -1666,7 +1673,7 @@ void on_chat_room_conference_alert(LinphoneChatRoom *cr, const LinphoneEventLog } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return [ConfigManager.instance lpConfigBoolForKeyWithKey:@"ephemeral_feature" defaultValue:false] ? 3 : 2; + return [ConfigManager.instance lpConfigBoolForKeyWithKey:@"ephemeral_feature" defaultValue:false] && [self canAdminEphemeral:_chatRoom] ? 3 : 2; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { @@ -1680,7 +1687,7 @@ void on_chat_room_conference_alert(LinphoneChatRoom *cr, const LinphoneEventLog cell.imageView.image = [LinphoneUtils resizeImage:[UIImage imageNamed:@"delete_default.png"] newSize:CGSizeMake(20, 25)]; cell.textLabel.text = NSLocalizedString(@"Delete messages",nil); } - if ([ConfigManager.instance lpConfigBoolForKeyWithKey:@"ephemeral_feature" defaultValue:false]) { + if ([ConfigManager.instance lpConfigBoolForKeyWithKey:@"ephemeral_feature" defaultValue:false] && [self canAdminEphemeral:_chatRoom]) { if (indexPath.row == 2) { cell.imageView.image = [LinphoneUtils resizeImage:[UIImage imageNamed:@"ephemeral_messages_default.png"] newSize:CGSizeMake(20, 25)]; cell.textLabel.text = NSLocalizedString(@"Ephemeral messages",nil); diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index 163dabcf2..3d0ad4962 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -884,7 +884,10 @@ static RootViewManager *rootViewManagerInstance = nil; LinphoneChatRoomParams *param = linphone_core_create_default_chat_room_params(LC); linphone_chat_room_params_enable_group(param, isGroup); linphone_chat_room_params_enable_encryption(param, isEncrypted); - + linphone_chat_room_params_set_ephemeral_mode(param,[LinphoneManager.instance lpConfigBoolForKey:@"ephemeral_chat_messages_settings_per_device" withDefault:true] ? + LinphoneChatRoomEphemeralModeDeviceManaged : + LinphoneChatRoomEphemeralModeAdminManaged); + linphone_chat_room_params_set_ephemeral_lifetime(param,0); LinphoneChatRoom *room = linphone_core_create_chat_room_2(LC, param, subject ?: LINPHONE_DUMMY_SUBJECT, addresses); if (!room) {