diff --git a/Classes/ChatConversationCreateTableView.m b/Classes/ChatConversationCreateTableView.m index 0aadd7482..a5a73481c 100644 --- a/Classes/ChatConversationCreateTableView.m +++ b/Classes/ChatConversationCreateTableView.m @@ -151,7 +151,7 @@ const LinphoneFriend* friend = linphone_search_result_get_friend(result); const char *phoneNumber = linphone_search_result_get_phone_number(result); - if ([LinphoneManager.instance lpConfigBoolForKey:@"force_lime_chat_rooms"] && ![self isSecureChatable:friend]) { + if (([LinphoneManager.instance lpConfigBoolForKey:@"force_lime_chat_rooms"] && ![self isSecureChatable:friend]) || [LinphoneManager.instance lpConfigBoolForKey:@"disable_chat_feature"]) { continue; } diff --git a/Classes/ChatConversationCreateView.m b/Classes/ChatConversationCreateView.m index 9f5f69006..e480632ea 100644 --- a/Classes/ChatConversationCreateView.m +++ b/Classes/ChatConversationCreateView.m @@ -105,7 +105,7 @@ static UICompositeViewDescription *compositeDescription = nil; } - if ([LinphoneManager.instance lpConfigBoolForKey:@"force_lime_chat_rooms"]) { + if ([LinphoneManager.instance lpConfigBoolForKey:@"force_lime_chat_rooms"] || [LinphoneManager.instance lpConfigBoolForKey:@"disable_chat_feature"]) { _chiffreOptionView.hidden = true; _isEncrypted = true; _tableController.isEncrypted = true; @@ -159,7 +159,7 @@ static UICompositeViewDescription *compositeDescription = nil; frame.origin.x = self.view.frame.size.width * 0.192; } _chiffreOptionView.frame = frame; - _isEncrypted = [LinphoneManager.instance lpConfigBoolForKey:@"force_lime_chat_rooms"]; // false by default + _isEncrypted = [LinphoneManager.instance lpConfigBoolForKey:@"force_lime_chat_rooms"] || [LinphoneManager.instance lpConfigBoolForKey:@"disable_chat_feature"]; // false by default CGRect buttonFrame = _chiffreButton.frame; if (!_isEncrypted) { diff --git a/Classes/HistoryDetailsView.m b/Classes/HistoryDetailsView.m index ef70a366e..1ac93dad2 100644 --- a/Classes/HistoryDetailsView.m +++ b/Classes/HistoryDetailsView.m @@ -69,7 +69,7 @@ static UICompositeViewDescription *compositeDescription = nil; } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { - _chatButton.hidden = [LinphoneManager.instance lpConfigBoolForKey:@"force_lime_chat_rooms"]; + _chatButton.hidden = [LinphoneManager.instance lpConfigBoolForKey:@"force_lime_chat_rooms"] || [LinphoneManager.instance lpConfigBoolForKey:@"disable_chat_feature"]; [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; [self update]; } @@ -178,7 +178,7 @@ static UICompositeViewDescription *compositeDescription = nil; } - (void)shouldHideEncryptedChatView:(BOOL)hasLime { - _encryptedChatView.hidden = !hasLime; + _encryptedChatView.hidden = !hasLime || [LinphoneManager.instance lpConfigBoolForKey:@"disable_chat_feature"]; CGRect newFrame = _optionsView.frame; if (!hasLime) { newFrame.origin.x = _encryptedChatView.frame.size.width * 2/3; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index fd5f9d5bc..1b593a920 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -240,7 +240,7 @@ struct codec_name_pref_table codec_pref_table[] = {{"speex", 8000, "speex_8k_pre NSString *path = [[NSBundle mainBundle] pathForResource:@"msg" ofType:@"wav"]; self.messagePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:path] error:nil]; - _sounds.vibrate = kSystemSoundID_Vibrate; + //_sounds.vibrate = kSystemSoundID_Vibrate; _logs = [[NSMutableArray alloc] init]; _pushDict = [[NSMutableDictionary alloc] init]; @@ -254,6 +254,11 @@ struct codec_name_pref_table codec_pref_table[] = {{"speex", 8000, "speex_8k_pre [self renameDefaultSettings]; [self copyDefaultSettings]; [self overrideDefaultSettings]; + + if (![self lpConfigBoolForKey:@"disable_chat_feature" withDefault:FALSE]) { + _sounds.vibrate = kSystemSoundID_Vibrate; + } + if (![self lpConfigBoolForKey:@"migration_images_done" withDefault:FALSE]) { [self migrationAllImages]; } diff --git a/Classes/LinphoneUI/TabBarView.m b/Classes/LinphoneUI/TabBarView.m index 76ae20cc0..2b3880d7e 100644 --- a/Classes/LinphoneUI/TabBarView.m +++ b/Classes/LinphoneUI/TabBarView.m @@ -76,16 +76,20 @@ - (void)update:(BOOL)appear { [self updateSelectedButton:[PhoneMainView.instance currentView]]; [self updateMissedCall:linphone_core_get_missed_calls_count(LC) appear:appear]; - [self updateUnreadMessage:appear]; + if (![LinphoneManager.instance lpConfigBoolForKey:@"disable_chat_feature"]) { + [self updateUnreadMessage:appear]; + } } - (void)updateUnreadMessage:(BOOL)appear { int unreadMessage = [LinphoneManager unreadMessageCount]; - if (unreadMessage > 0) { - _chatNotificationLabel.text = [NSString stringWithFormat:@"%i", unreadMessage]; - [_chatNotificationView startAnimating:appear]; - } else { - [_chatNotificationView stopAnimating:appear]; + if (![LinphoneManager.instance lpConfigBoolForKey:@"disable_chat_feature"]) { + if (unreadMessage > 0) { + _chatNotificationLabel.text = [NSString stringWithFormat:@"%i", unreadMessage]; + [_chatNotificationView startAnimating:appear]; + } else { + [_chatNotificationView stopAnimating:appear]; + } } } @@ -110,6 +114,24 @@ [view equal:ChatConversationInfoView.compositeViewDescription] || [view equal:ChatConversationImdnView.compositeViewDescription] || [view equal:ChatConversationView.compositeViewDescription]; + if ([LinphoneManager.instance lpConfigBoolForKey:@"disable_chat_feature"] && [self viewIsCurrentlyPortrait]) { + CGFloat itemWidth = [UIScreen mainScreen].bounds.size.width/3; + [_chatButton setEnabled:false]; + [_chatButton setHidden:true]; + [_chatNotificationView setHidden:true]; + _historyButton.frame = CGRectMake(0, 0, itemWidth, 66); + _contactsButton.frame = CGRectMake(itemWidth, 0, itemWidth, 66); + _dialerButton.frame = CGRectMake(itemWidth*2, 0, itemWidth, 66); + _selectedButtonImage.frame = CGRectMake(_selectedButtonImage.frame.origin.x, _selectedButtonImage.frame.origin.y, itemWidth, 3); + } else if ([LinphoneManager.instance lpConfigBoolForKey:@"disable_chat_feature"] && ![self viewIsCurrentlyPortrait]) { + [_chatButton setEnabled:false]; + [_chatButton setHidden:true]; + [_chatNotificationView setHidden:true]; + _historyButton.frame = CGRectMake(0, 20, 90, 90); + _contactsButton.frame = CGRectMake(0, 120, 90, 90); + _dialerButton.frame = CGRectMake(0, 220, 90, 90); + _selectedButtonImage.frame = CGRectMake(_selectedButtonImage.frame.origin.x, _selectedButtonImage.frame.origin.y, 3, 90); + } CGRect selectedNewFrame = _selectedButtonImage.frame; if ([self viewIsCurrentlyPortrait]) { selectedNewFrame.origin.x = diff --git a/Classes/LinphoneUI/UIContactDetailsCell.m b/Classes/LinphoneUI/UIContactDetailsCell.m index b1b5bc697..2b52ca496 100644 --- a/Classes/LinphoneUI/UIContactDetailsCell.m +++ b/Classes/LinphoneUI/UIContactDetailsCell.m @@ -77,7 +77,7 @@ [FastAddressBook isSipURIValid:_addressLabel.text])); self.inviteButton.hidden = !ENABLE_SMS_INVITE || [[contactDetailsView.contact sipAddresses] count] > 0 || !self.linphoneImage.hidden; [self shouldHideEncryptedChatView:account && linphone_account_params_get_conference_factory_uri(linphone_account_get_params(account)) && model && linphone_presence_model_has_capability(model, LinphoneFriendCapabilityLimeX3dh)]; - _chatButton.hidden = [LinphoneManager.instance lpConfigBoolForKey:@"force_lime_chat_rooms"]; + _chatButton.hidden = [LinphoneManager.instance lpConfigBoolForKey:@"force_lime_chat_rooms"] || [LinphoneManager.instance lpConfigBoolForKey:@"disable_chat_feature"]; } if (addr) { @@ -86,7 +86,7 @@ } - (void)shouldHideEncryptedChatView:(BOOL)hasLime { - _encryptedChatView.hidden = !hasLime; + _encryptedChatView.hidden = !hasLime || [LinphoneManager.instance lpConfigBoolForKey:@"disable_chat_feature"]; CGRect newFrame = _optionsView.frame; if (!hasLime) { newFrame.origin.x = _addressLabel.frame.origin.x + _callButton.frame.size.width * 2/3; diff --git a/Classes/SettingsView.m b/Classes/SettingsView.m index 5b28009aa..8b92e1b28 100644 --- a/Classes/SettingsView.m +++ b/Classes/SettingsView.m @@ -669,6 +669,10 @@ void update_hash_cbs(LinphoneAccountCreator *creator, LinphoneAccountCreatorStat if (!linphone_core_ldap_available(LC)) { [hiddenKeys addObject:@"contacts_menu"]; } + + if ([LinphoneManager.instance lpConfigBoolForKey:@"disable_chat_feature"]){ + [hiddenKeys addObject:@"message_menu"]; + } #ifndef DEBUG [hiddenKeys addObject:@"debug_actions_group"]; [hiddenKeys addObject:@"release_button"]; diff --git a/Classes/Swift/Extensions/IOS/UIDeviceExtensions.swift b/Classes/Swift/Extensions/IOS/UIDeviceExtensions.swift index 32b415dbe..ba7a5245a 100644 --- a/Classes/Swift/Extensions/IOS/UIDeviceExtensions.swift +++ b/Classes/Swift/Extensions/IOS/UIDeviceExtensions.swift @@ -22,13 +22,14 @@ import Foundation import UIKit import AVFoundation +import linphonesw extension UIDevice { static func ipad() -> Bool { return UIDevice.current.userInterfaceIdiom == .pad } static func vibrate() { - if (!ipad()) { + if (!ipad() || Core.get().config?.getBool(section: "app", key: "disable_chat_feature", defaultValue: false) == false) { AudioServicesPlaySystemSound(kSystemSoundID_Vibrate) } } diff --git a/Resources/linphonerc b/Resources/linphonerc index 8df2b1501..3270c2301 100644 --- a/Resources/linphonerc +++ b/Resources/linphonerc @@ -19,6 +19,8 @@ lime_migration_done=0 use_rls_presence=1 use_callkit=1 unexpected_pushkit=0 +force_lime_chat_rooms=0 +disable_chat_feature=0 [in_app_purchase] #set to 1 if in-app purchases are to be shown in the application diff --git a/Resources/linphonerc-factory b/Resources/linphonerc-factory index c0793518a..dcf48706c 100644 --- a/Resources/linphonerc-factory +++ b/Resources/linphonerc-factory @@ -28,6 +28,7 @@ use_callkit=1 accept_early_media=0 force_lime_chat_rooms=0 +disable_chat_feature=0 enable_native_address_book=1 hide_link_phone_number=0 diff --git a/msgNotificationService/NotificationService.swift b/msgNotificationService/NotificationService.swift index 4c4f19492..fb4923441 100644 --- a/msgNotificationService/NotificationService.swift +++ b/msgNotificationService/NotificationService.swift @@ -52,94 +52,97 @@ class NotificationService: UNNotificationServiceExtension { } override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { - self.contentHandler = contentHandler - bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) - NSLog("[msgNotificationService] start msgNotificationService extension") - - if (VFSUtil.vfsEnabled(groupName: APP_GROUP_ID) && !VFSUtil.activateVFS()) { - VFSUtil.log("[VFS] Error unable to activate.", .error) - } - - if let bestAttemptContent = bestAttemptContent { - createCore() - NotificationService.log.message(message: "received push payload : \(bestAttemptContent.userInfo.debugDescription)") + self.contentHandler = contentHandler + bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) + NSLog("[msgNotificationService] start msgNotificationService extension") + if (VFSUtil.vfsEnabled(groupName: APP_GROUP_ID) && !VFSUtil.activateVFS()) { + VFSUtil.log("[VFS] Error unable to activate.", .error) + } - let defaults = UserDefaults.init(suiteName: APP_GROUP_ID) - if let chatroomsPushStatus = defaults?.dictionary(forKey: "chatroomsPushStatus") { - let aps = bestAttemptContent.userInfo["aps"] as? NSDictionary - let alert = aps?["alert"] as? NSDictionary - let fromAddresses = alert?["loc-args"] as? [String] + if let bestAttemptContent = bestAttemptContent { + createCore() - if let from = fromAddresses?.first { - if ((chatroomsPushStatus[from] as? String) == "disabled") { - NotificationService.log.message(message: "message comes from a muted chatroom, ignore it") - contentHandler(UNNotificationContent()) - } - } - } - - if let chatRoomInviteAddr = bestAttemptContent.userInfo["chat-room-addr"] as? String, !chatRoomInviteAddr.isEmpty { - NotificationService.log.message(message: "fetch chat room for invite, addr: \(chatRoomInviteAddr)") - let chatRoom = lc!.getNewChatRoomFromConfAddr(chatRoomAddr: chatRoomInviteAddr) + if (!(lc!.config?.getBool(section: "app", key: "disable_chat_feature", defaultValue: true))!){ + NotificationService.log.message(message: "received push payload : \(bestAttemptContent.userInfo.debugDescription)") - if let chatRoom = chatRoom { - stopCore() - NotificationService.log.message(message: "chat room invite received") - bestAttemptContent.title = NSLocalizedString("GC_MSG", comment: "") - if (chatRoom.hasCapability(mask:ChatRoomCapabilities.OneToOne.rawValue)) { - if (chatRoom.peerAddress?.displayName.isEmpty != true) { - bestAttemptContent.body = chatRoom.peerAddress!.displayName - } else { - bestAttemptContent.body = chatRoom.peerAddress!.username + + let defaults = UserDefaults.init(suiteName: APP_GROUP_ID) + if let chatroomsPushStatus = defaults?.dictionary(forKey: "chatroomsPushStatus") { + let aps = bestAttemptContent.userInfo["aps"] as? NSDictionary + let alert = aps?["alert"] as? NSDictionary + let fromAddresses = alert?["loc-args"] as? [String] + + if let from = fromAddresses?.first { + if ((chatroomsPushStatus[from] as? String) == "disabled") { + NotificationService.log.message(message: "message comes from a muted chatroom, ignore it") + contentHandler(UNNotificationContent()) + } } - } else { - bestAttemptContent.body = chatRoom.subject } + + if let chatRoomInviteAddr = bestAttemptContent.userInfo["chat-room-addr"] as? String, !chatRoomInviteAddr.isEmpty { + NotificationService.log.message(message: "fetch chat room for invite, addr: \(chatRoomInviteAddr)") + let chatRoom = lc!.getNewChatRoomFromConfAddr(chatRoomAddr: chatRoomInviteAddr) - bestAttemptContent.sound = UNNotificationSound(named: UNNotificationSoundName("msg.caf")) // TODO : temporary fix, to be removed after flexisip release - contentHandler(bestAttemptContent) - return - } - } else if let callId = bestAttemptContent.userInfo["call-id"] as? String { - NotificationService.log.message(message: "fetch msg for callid ["+callId+"]") - let message = lc!.getNewMessageFromCallid(callId: callId) - - if let message = message { - let msgData = parseMessage(message: message) - - // Extension only upates app's badge when main shared core is Off = extension's core is On. - // Otherwise, the app will update the badge. - if lc?.globalState == GlobalState.On, let badge = updateBadge() as NSNumber? { - bestAttemptContent.badge = badge - } - - stopCore() - - bestAttemptContent.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "msg.caf")) - bestAttemptContent.title = NSLocalizedString("Message received", comment: "") - if let subtitle = msgData?.subtitle { - bestAttemptContent.subtitle = subtitle - } - if let body = msgData?.body { - bestAttemptContent.body = body - } - - bestAttemptContent.categoryIdentifier = "msg_cat" - - bestAttemptContent.userInfo.updateValue(msgData?.callId as Any, forKey: "CallId") - bestAttemptContent.userInfo.updateValue(msgData?.from as Any, forKey: "from") - bestAttemptContent.userInfo.updateValue(msgData?.peerAddr as Any, forKey: "peer_addr") - bestAttemptContent.userInfo.updateValue(msgData?.localAddr as Any, forKey: "local_addr") - - contentHandler(bestAttemptContent) - return - } else { - NotificationService.log.message(message: "Message not found for callid ["+callId+"]") + if let chatRoom = chatRoom { + stopCore() + NotificationService.log.message(message: "chat room invite received") + bestAttemptContent.title = NSLocalizedString("GC_MSG", comment: "") + if (chatRoom.hasCapability(mask:ChatRoomCapabilities.OneToOne.rawValue)) { + if (chatRoom.peerAddress?.displayName.isEmpty != true) { + bestAttemptContent.body = chatRoom.peerAddress!.displayName + } else { + bestAttemptContent.body = chatRoom.peerAddress!.username + } + } else { + bestAttemptContent.body = chatRoom.subject + } + + bestAttemptContent.sound = UNNotificationSound(named: UNNotificationSoundName("msg.caf")) // TODO : temporary fix, to be removed after flexisip release + contentHandler(bestAttemptContent) + return + } + } else if let callId = bestAttemptContent.userInfo["call-id"] as? String { + NotificationService.log.message(message: "fetch msg for callid ["+callId+"]") + let message = lc!.getNewMessageFromCallid(callId: callId) + + if let message = message { + let msgData = parseMessage(message: message) + + // Extension only upates app's badge when main shared core is Off = extension's core is On. + // Otherwise, the app will update the badge. + if lc?.globalState == GlobalState.On, let badge = updateBadge() as NSNumber? { + bestAttemptContent.badge = badge + } + + stopCore() + + bestAttemptContent.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "msg.caf")) + bestAttemptContent.title = NSLocalizedString("Message received", comment: "") + if let subtitle = msgData?.subtitle { + bestAttemptContent.subtitle = subtitle + } + if let body = msgData?.body { + bestAttemptContent.body = body + } + + bestAttemptContent.categoryIdentifier = "msg_cat" + + bestAttemptContent.userInfo.updateValue(msgData?.callId as Any, forKey: "CallId") + bestAttemptContent.userInfo.updateValue(msgData?.from as Any, forKey: "from") + bestAttemptContent.userInfo.updateValue(msgData?.peerAddr as Any, forKey: "peer_addr") + bestAttemptContent.userInfo.updateValue(msgData?.localAddr as Any, forKey: "local_addr") + + contentHandler(bestAttemptContent) + return + } else { + NotificationService.log.message(message: "Message not found for callid ["+callId+"]") + } + } } + serviceExtensionTimeWillExpire() } - serviceExtensionTimeWillExpire() - } } override func serviceExtensionTimeWillExpire() {