diff --git a/Classes/ChatConversationCreateTableView.m b/Classes/ChatConversationCreateTableView.m index a2d27d327..0aadd7482 100644 --- a/Classes/ChatConversationCreateTableView.m +++ b/Classes/ChatConversationCreateTableView.m @@ -82,6 +82,41 @@ [self searchBar:_searchBar textDidChange:_searchBar.text]; self.tableView.accessibilityIdentifier = @"Suggested addresses"; + NSDictionary* userInfo; + [NSNotificationCenter.defaultCenter addObserver:self + selector: @selector(receiveTestNotification:) + name: @"LinphoneFriendPresenceUpdate" + object: userInfo]; +} + +-(void) receiveTestNotification:(NSNotification*)notification +{ + if ([notification.name isEqualToString:@"LinphoneFriendPresenceUpdate"]) + { + NSDictionary* userInfo = notification.userInfo; + NSString* friend = (NSString*)userInfo[@"friend"]; + + for (int i = 0; i < _addresses.count; i++) + { + + NSString *key = [_addresses objectAtIndex:i]; + Contact *contact = [LinphoneManager.instance.fastAddressBook.addressBookMap objectForKey:[FastAddressBook normalizeSipURI:key use_prefix:[CallManager.instance applyInternationalPrefix]]]; + if (!contact) { + contact = [_ldapAndProvisioningContactAddressBookMap objectForKey:key]; + } + + if (contact.friend != nil) { + char *curi = linphone_address_as_string_uri_only(linphone_friend_get_address(contact.friend)); + NSString *uri = [NSString stringWithUTF8String:curi]; + + if([uri isEqual:friend]){ + NSIndexPath* indexPath = [NSIndexPath indexPathForRow:i inSection:0]; + NSArray* indexArray = [NSArray arrayWithObjects:indexPath, nil]; + [self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade]; + } + } + } + } } - (void) viewWillDisappear:(BOOL)animated { diff --git a/Classes/ChatConversationInfoView.m b/Classes/ChatConversationInfoView.m index f47a227f4..277cbfe72 100644 --- a/Classes/ChatConversationInfoView.m +++ b/Classes/ChatConversationInfoView.m @@ -96,6 +96,39 @@ static UICompositeViewDescription *compositeDescription = nil; selector:@selector(onLinphoneCoreReady:) name:kLinphoneGlobalStateUpdate object:nil]; + + NSDictionary* userInfo; + [NSNotificationCenter.defaultCenter addObserver:self + selector: @selector(receiveTestNotification:) + name: @"LinphoneFriendPresenceUpdate" + object: userInfo]; +} + +-(void) receiveTestNotification:(NSNotification*)notification +{ + if ([notification.name isEqualToString:@"LinphoneFriendPresenceUpdate"]) + { + NSDictionary* userInfo = notification.userInfo; + NSString* friend = (NSString*)userInfo[@"friend"]; + + for (int i = 0; i < _contacts.count; i++) + { + + NSString *uri = _contacts[i]; + LinphoneAddress *addr = linphone_address_new(uri.UTF8String); + + if (addr != nil) { + char *curi = linphone_address_as_string_uri_only(addr); + NSString *uri = [NSString stringWithUTF8String:curi]; + + if([uri isEqual:friend]){ + NSIndexPath* indexPath = [NSIndexPath indexPathForRow:i inSection:0]; + NSArray* indexArray = [NSArray arrayWithObjects:indexPath, nil]; + [self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade]; + } + } + } + } } - (void)viewWillDisappear:(BOOL)animated { diff --git a/Classes/ChatsListTableView.m b/Classes/ChatsListTableView.m index 5d0807849..1aa26132c 100644 --- a/Classes/ChatsListTableView.m +++ b/Classes/ChatsListTableView.m @@ -67,9 +67,25 @@ { NSDictionary* userInfo = notification.userInfo; NSString* friend = (NSString*)userInfo[@"friend"]; - BOOL friendIsOnline = (BOOL)userInfo[@"isOnline"]; - //NSLog(@"Successfully received test notification! %@ %d", friend, friendIsOnline); + for (int i = 0; i < bctbx_list_size(_data); i++) + { + LinphoneChatRoom *chatRoom = (LinphoneChatRoom *)bctbx_list_nth_data(_data, i); + + bctbx_list_t *participants = linphone_chat_room_get_participants(chatRoom); + LinphoneParticipant *firstParticipant = participants ? (LinphoneParticipant *)participants->data : NULL; + + char *curi = linphone_address_as_string_uri_only(linphone_participant_get_address(firstParticipant)); + NSString *uri = [NSString stringWithUTF8String:curi]; + + LinphoneChatRoomCapabilitiesMask capabilities = linphone_chat_room_get_capabilities(chatRoom); + bool oneToOne = capabilities & LinphoneChatRoomCapabilitiesOneToOne; + if(oneToOne && [uri isEqual:friend]){ + NSIndexPath* indexPath = [NSIndexPath indexPathForRow:i inSection:0]; + NSArray* indexArray = [NSArray arrayWithObjects:indexPath, nil]; + [self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade]; + } + } } } diff --git a/Classes/ContactDetailsView.m b/Classes/ContactDetailsView.m index 0abca3125..b86abd0a6 100644 --- a/Classes/ContactDetailsView.m +++ b/Classes/ContactDetailsView.m @@ -302,6 +302,20 @@ [self updateBackOrCancelButton]; [self recomputeTableViewSize:FALSE]; + + NSDictionary* userInfo; + [NSNotificationCenter.defaultCenter addObserver:self + selector: @selector(receiveTestNotification:) + name: @"LinphoneFriendPresenceUpdate" + object: userInfo]; +} + +-(void) receiveTestNotification:(NSNotification*)notification +{ + if ([notification.name isEqualToString:@"LinphoneFriendPresenceUpdate"]) + { + [self resetData]; + } } - (void)deviceOrientationDidChange:(NSNotification*)notif { diff --git a/Classes/ContactsListTableView.m b/Classes/ContactsListTableView.m index c852e7c79..4a992685a 100644 --- a/Classes/ContactsListTableView.m +++ b/Classes/ContactsListTableView.m @@ -60,6 +60,41 @@ [view setContact:nil]; } } + NSDictionary* userInfo; + [NSNotificationCenter.defaultCenter addObserver:self + selector: @selector(receiveTestNotification:) + name: @"LinphoneFriendPresenceUpdate" + object: userInfo]; +} + +-(void) receiveTestNotification:(NSNotification*)notification +{ + if ([notification.name isEqualToString:@"LinphoneFriendPresenceUpdate"]) + { + NSDictionary* userInfo = notification.userInfo; + NSString* friend = (NSString*)userInfo[@"friend"]; + + self.tableView.indexPathsForVisibleRows; + + for (int i = 0; i < addressBookMap.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]; + + if([uri isEqual:friend]){ + NSIndexPath* indexPath = [NSIndexPath indexPathForRow:i inSection:0]; + NSArray* indexArray = [NSArray arrayWithObjects:indexPath, nil]; + [self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade]; + } + } + */ + } + } } - (id)init { diff --git a/Classes/HistoryDetailsView.m b/Classes/HistoryDetailsView.m index e2e4dd743..ef70a366e 100644 --- a/Classes/HistoryDetailsView.m +++ b/Classes/HistoryDetailsView.m @@ -93,6 +93,20 @@ static UICompositeViewDescription *compositeDescription = nil; selector: @selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil]; + + NSDictionary* userInfo; + [NSNotificationCenter.defaultCenter addObserver:self + selector: @selector(receiveTestNotification:) + name: @"LinphoneFriendPresenceUpdate" + object: userInfo]; +} + +-(void) receiveTestNotification:(NSNotification*)notification +{ + if ([notification.name isEqualToString:@"LinphoneFriendPresenceUpdate"]) + { + [self update]; + } } - (void)viewWillDisappear:(BOOL)animated { diff --git a/Classes/HistoryListTableView.m b/Classes/HistoryListTableView.m index f6b34c503..12ab5d8c4 100644 --- a/Classes/HistoryListTableView.m +++ b/Classes/HistoryListTableView.m @@ -71,6 +71,36 @@ name:kLinphoneCoreUpdate object:nil]; [self loadData]; + NSDictionary* userInfo; + [NSNotificationCenter.defaultCenter addObserver:self + selector: @selector(receiveTestNotification:) + name: @"LinphoneFriendPresenceUpdate" + object: userInfo]; +} + +-(void) receiveTestNotification:(NSNotification*)notification +{ + if ([notification.name isEqualToString:@"LinphoneFriendPresenceUpdate"]) + { + NSDictionary* userInfo = notification.userInfo; + NSString* friend = (NSString*)userInfo[@"friend"]; + + const MSList *list = linphone_core_get_call_logs(LC); + int i = 0; + while (list != NULL) { + LinphoneCallLog *log = (LinphoneCallLog *)list->data; + const char *curi = linphone_address_as_string_uri_only(linphone_call_log_get_remote_address(log)); + NSString *uri = [NSString stringWithUTF8String:curi]; + + if([uri isEqual:friend]){ + NSIndexPath* indexPath = [NSIndexPath indexPathForRow:i inSection:0]; + NSArray* indexArray = [NSArray arrayWithObjects:indexPath, nil]; + [self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade]; + } + i = i + 1; + list = list->next; + } + } } - (void)viewWillDisappear:(BOOL)animated { diff --git a/Classes/Swift/Voip/Widgets/Avatar.swift b/Classes/Swift/Voip/Widgets/Avatar.swift index af23e991d..8f0e436e1 100644 --- a/Classes/Swift/Voip/Widgets/Avatar.swift +++ b/Classes/Swift/Voip/Widgets/Avatar.swift @@ -28,6 +28,9 @@ class Avatar : UIView { static let groupAvatar = UIImage(named:"voip_multiple_contacts_avatar") static let singleAvatar = UIImage(named:"avatar") + var friend: [Friend] = [] + var friendDelegate: [FriendDelegate] = [] + required init?(coder: NSCoder) { initialsLabel = StyledLabel(VoipTheme.call_generated_avatar_large) super.init(coder: coder) @@ -86,12 +89,33 @@ class Avatar : UIView { layer.cornerRadius = self.frame.width / 2.0 } + func addDelegate(contactAddress: Contact){ + var delegatePresence = false + + friend.forEach { friendForEach in + if friendForEach.address?.asStringUriOnly() == Friend.getSwiftObject(cObject: (contactAddress.friend)!).address?.asStringUriOnly() { + delegatePresence = true + } + } + if delegatePresence == false { + friend.append(Friend.getSwiftObject(cObject: (contactAddress.friend)!)) + let newFriendDelegate = FriendDelegateStub( + onPresenceReceived: { (linphoneFriend: Friend) -> Void in + let presenceModel = linphoneFriend.getPresenceModelForUriOrTel(uriOrTel: (linphoneFriend.address?.asStringUriOnly())!) + NotificationCenter.default.post(name: Notification.Name("LinphoneFriendPresenceUpdate"), object: nil, userInfo: ["friend": linphoneFriend.address?.asStringUriOnly() ?? "", "isOnline": presenceModel!.isOnline]) + } + ) + friendDelegate.append(newFriendDelegate) + friend.last?.addDelegate(delegate: friendDelegate.last!) + } + } } @objc class AvatarBridge : NSObject { // Ugly work around to tap into the swift Avatars, until rest of the app is reworked in Swift. static var shared : Avatar? = nil static let size = 50.0 + @objc static func prepareIt() { if (shared != nil) { shared?.removeFromSuperview() @@ -116,34 +140,12 @@ class Avatar : UIView { if contactAddress != nil { iconPresenceView = updatePresenceImage(contact: contactAddress!) + avatarWithPresence.addSubview(avatarImageWihtoutPresence) + avatarWithPresence.addSubview(iconPresenceView) + iconPresenceView.frame = CGRect(x: 35, y: 35, width: 16, height: 16) - - - let friend = Friend.getSwiftObject(cObject: (contactAddress?.friend)!) - - let friendDelegate = FriendDelegateStub( - onPresenceReceived: { (linphoneFriend: Friend) -> Void in - let presenceModel = linphoneFriend.getPresenceModelForUriOrTel(uriOrTel: (linphoneFriend.address?.asStringUriOnly())!) - print("Successfully received test notification linphoneFriend \(linphoneFriend.address?.displayName)") - print("Successfully received test notification friend \(friend.address?.displayName)") - print("Successfully received test notification consolidatedPresence \(presenceModel!.consolidatedPresence)") - print("Successfully received test notification consolidatedPresence \(friend.consolidatedPresence)") - print("Successfully received test notification isOnline \(presenceModel!.isOnline)") - print("Successfully received test notification friend \(friend.isPresenceReceived)") - NotificationCenter.default.post(name: Notification.Name("LinphoneFriendPresenceUpdate"), object: nil, userInfo: ["friend": linphoneFriend.address?.asStringUriOnly(), "isOnline": presenceModel!.isOnline]) - } - ) - - friend.addDelegate(delegate: friendDelegate) - - - + shared?.addDelegate(contactAddress: contactAddress!) } - - avatarWithPresence.addSubview(avatarImageWihtoutPresence) - avatarWithPresence.addSubview(iconPresenceView) - iconPresenceView.frame = CGRect(x: 35, y: 35, width: 16, height: 16) - return avatarWithPresence.toImage() } @@ -162,34 +164,12 @@ class Avatar : UIView { 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) - - let friend = Friend.getSwiftObject(cObject: contact.friend) - - let friendDelegate = FriendDelegateStub( - onPresenceReceived: { (linphoneFriend: Friend) -> Void in - let presenceModel = linphoneFriend.getPresenceModelForUriOrTel(uriOrTel: (linphoneFriend.address?.asStringUriOnly())!) - print("Successfully received test notification linphoneFriend displayName \(linphoneFriend.address?.displayName)") - print("Successfully received test notification friend displayName \(friend.address?.displayName)") - print("Successfully received test notification presenceModel consolidatedPresence \(presenceModel!.consolidatedPresence)") - print("Successfully received test notification friend consolidatedPresence \(friend.consolidatedPresence)") - print("Successfully received test notification presenceModel isOnline \(presenceModel!.isOnline)") - print("Successfully received test notification friend isPresenceReceived \(friend.isPresenceReceived)") - NotificationCenter.default.post(name: Notification.Name("LinphoneFriendPresenceUpdate"), object: nil, userInfo: ["friend": linphoneFriend.address?.asStringUriOnly(), "isOnline": presenceModel!.isOnline]) - } - ) - - friend.addDelegate(delegate: friendDelegate) - - - - - - avatarWithPresence.addSubview(avatarImageWihtoutPresence) - avatarWithPresence.addSubview(iconPresenceView) - iconPresenceView.frame = CGRect(x: 35, y: 35, width: 16, height: 16) - return avatarWithPresence.toImage() }