From 919cca172605b8ca4b0b8717ed7786e30a9386ef Mon Sep 17 00:00:00 2001 From: "benoit.martins" Date: Wed, 19 Apr 2023 00:07:11 +0200 Subject: [PATCH] Fix phone (no sip) presence Add pushpresence setting --- Classes/ContactsListTableView.m | 41 +++++++++++------- Classes/LinphoneAppDelegate.m | 12 +++-- Classes/LinphoneCoreSettingsStore.m | 4 ++ Classes/Swift/Voip/Widgets/Avatar.swift | 9 ++-- Settings/InAppSettings.bundle/Account.plist | 10 +++++ .../en.lproj/Account.strings | Bin 1278 -> 1348 bytes .../fr.lproj/Account.strings | Bin 1414 -> 1496 bytes 7 files changed, 51 insertions(+), 25 deletions(-) diff --git a/Classes/ContactsListTableView.m b/Classes/ContactsListTableView.m index 4a992685a..f2f773a3a 100644 --- a/Classes/ContactsListTableView.m +++ b/Classes/ContactsListTableView.m @@ -74,25 +74,34 @@ NSDictionary* userInfo = notification.userInfo; NSString* friend = (NSString*)userInfo[@"friend"]; - self.tableView.indexPathsForVisibleRows; + NSArray *indexPathsVisible = self.tableView.indexPathsForVisibleRows; - for (int i = 0; i < addressBookMap.count; i++) + for (int i = 0; i < indexPathsVisible.count; i++) { - /* - NSMutableArray *subAr = [addressBookMap objectForKey:[addressBookMap keyAtIndex:2]]; - Contact *contact = subAr[1]; - - if (contact.friend != nil) { - char *curi = linphone_address_as_string_uri_only(linphone_friend_get_address(contact.friend)); - NSString *uri = [NSString stringWithUTF8String:curi]; + NSMutableArray *subAr = [addressBookMap objectForKey:[addressBookMap keyAtIndex:indexPathsVisible[i].section]]; + Contact *contact = subAr[indexPathsVisible[i].row]; - if([uri isEqual:friend]){ - NSIndexPath* indexPath = [NSIndexPath indexPathForRow:i inSection:0]; - NSArray* indexArray = [NSArray arrayWithObjects:indexPath, nil]; - [self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade]; - } - } - */ + if (contact.sipAddresses.count > 0){ + for (NSString *sip in contact.sipAddresses) { + NSString *uri = [@"sip:" stringByAppendingString:sip]; + + if([uri isEqual:friend]){ + NSIndexPath* indexPath = indexPathsVisible[i]; + NSArray* indexArray = [NSArray arrayWithObjects:indexPath, nil]; + [self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade]; + } + } + }else if (contact.phones.count > 0){ + for (NSString *phone in contact.phones) { + NSString *uri = phone; + + if([uri isEqual:friend]){ + NSIndexPath* indexPath = indexPathsVisible[i]; + NSArray* indexArray = [NSArray arrayWithObjects:indexPath, nil]; + [self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade]; + } + } + } } } } diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 8e256d7ed..64d42d13c 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -75,8 +75,12 @@ // To avoid crash [PhoneMainView.instance changeCurrentView:DialerView.compositeViewDescription]; } - - linphone_core_set_consolidated_presence(LC, LinphoneConsolidatedPresenceBusy); + + [LinphoneManager.instance lpConfigSetBool:FALSE forKey:@"account_push_presence_preference"]; + + if([LinphoneManager.instance lpConfigBoolForKey:@"account_push_presence_preference"]){ + linphone_core_set_consolidated_presence(LC, LinphoneConsolidatedPresenceBusy); + } [CallManager.instance stopLinphoneCore]; } @@ -89,7 +93,9 @@ [LinphoneManager.instance startLinphoneCore]; [LinphoneManager.instance.fastAddressBook reloadFriends]; - linphone_core_set_consolidated_presence(LC, LinphoneConsolidatedPresenceOnline); + if([LinphoneManager.instance lpConfigBoolForKey:@"account_push_presence_preference"]){ + linphone_core_set_consolidated_presence(LC, LinphoneConsolidatedPresenceOnline); + } [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneMessageReceived object:nil]; diff --git a/Classes/LinphoneCoreSettingsStore.m b/Classes/LinphoneCoreSettingsStore.m index 3cd4a2f2c..690115aa7 100644 --- a/Classes/LinphoneCoreSettingsStore.m +++ b/Classes/LinphoneCoreSettingsStore.m @@ -155,6 +155,7 @@ // default values { [self setBool:NO forKey:@"account_pushnotification_preference"]; + [self setBool:YES forKey:@"account_push_presence_preference"]; [self setObject:@"" forKey:@"account_mandatory_username_preference"]; [self setObject:@"" forKey:@"account_mandatory_domain_preference"]; [self setCString:"" forKey:@"account_display_name_preference"]; @@ -184,6 +185,9 @@ { BOOL pushEnabled = linphone_account_params_get_push_notification_allowed(accountParams); [self setBool:pushEnabled forKey:@"account_pushnotification_preference"]; + + BOOL pushPresenceEnabled = [LinphoneManager.instance lpConfigBoolForKey:@"account_push_presence_preference"]; + [self setBool:pushPresenceEnabled forKey:@"account_push_presence_preference"]; const LinphoneAddress *identity_addr = linphone_account_params_get_identity_address(accountParams); const char *server_addr = linphone_account_params_get_server_addr(accountParams); diff --git a/Classes/Swift/Voip/Widgets/Avatar.swift b/Classes/Swift/Voip/Widgets/Avatar.swift index 8f0e436e1..07be0823e 100644 --- a/Classes/Swift/Voip/Widgets/Avatar.swift +++ b/Classes/Swift/Voip/Widgets/Avatar.swift @@ -137,7 +137,7 @@ class Avatar : UIView { let avatarImageWihtoutPresence = UIImageView(image: shared?.toImage()) let contactAddress = Address.getSwiftObject(cObject: address).contact() var iconPresenceView = UIImageView() - if contactAddress != nil { + if (contactAddress != nil) { iconPresenceView = updatePresenceImage(contact: contactAddress!) avatarWithPresence.addSubview(avatarImageWihtoutPresence) @@ -145,6 +145,8 @@ class Avatar : UIView { iconPresenceView.frame = CGRect(x: 35, y: 35, width: 16, height: 16) shared?.addDelegate(contactAddress: contactAddress!) + }else{ + avatarWithPresence.addSubview(avatarImageWihtoutPresence) } return avatarWithPresence.toImage() } @@ -162,13 +164,8 @@ class Avatar : UIView { let avatarWithPresence = UIView(frame: CGRect(x: 0, y: 0, width: size, height: size)) let avatarImageWihtoutPresence = UIImageView(image: shared?.toImage()) - let iconPresenceView = updatePresenceImage(contact: contact) avatarWithPresence.addSubview(avatarImageWihtoutPresence) - avatarWithPresence.addSubview(iconPresenceView) - iconPresenceView.frame = CGRect(x: 35, y: 35, width: 16, height: 16) - - shared?.addDelegate(contactAddress: contact) return avatarWithPresence.toImage() } diff --git a/Settings/InAppSettings.bundle/Account.plist b/Settings/InAppSettings.bundle/Account.plist index 67dc9e37b..528c6c96c 100644 --- a/Settings/InAppSettings.bundle/Account.plist +++ b/Settings/InAppSettings.bundle/Account.plist @@ -44,6 +44,16 @@ DefaultValue + + Title + Push Presence + Key + account_push_presence_preference + Type + PSToggleSwitchSpecifier + DefaultValue + + AutocapitalizationType None diff --git a/Settings/InAppSettings.bundle/en.lproj/Account.strings b/Settings/InAppSettings.bundle/en.lproj/Account.strings index 7b676a04f0b6f80967c4de60032acd329658e2af..0bfbac13800bbff2937bf7f816443b3d168d5345 100644 GIT binary patch delta 76 zcmeyzd4y|&1*3HULn%WsLk5EaLjXe&Ln@G+%8@#A#$(I?A^rrq diff --git a/Settings/InAppSettings.bundle/fr.lproj/Account.strings b/Settings/InAppSettings.bundle/fr.lproj/Account.strings index 84d1583abc0dfc351a3b909ce44ebeb91e4196d3..383b2164e7ef1b4d31a31376e467d4d312cfa9a8 100644 GIT binary patch delta 86 zcmZqUzQMi0hS4*Cp_HMRA%j7IA%LNXAr;6@WyoVl29ioZF