diff --git a/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift b/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift index d6a32fbac..81769ade8 100644 --- a/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift +++ b/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift @@ -148,7 +148,8 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour let isDisplayingBottomOfTable = collectionView.contentOffset.y <= 20 if ChatConversationTableViewModel.sharedModel.getNBMessages() < 4 { - collectionView.reloadData() + collectionView.reloadData() + ChatConversationViewSwift.markAsRead(ChatConversationViewModel.sharedModel.chatRoom?.getCobject) } else if isDisplayingBottomOfTable { self.collectionView.scrollToItem(at: IndexPath(item: 1, section: 0), at: .top, animated: false) collectionView.reloadData() diff --git a/Classes/Swift/Chat/Views/ChatConversationViewSwift.swift b/Classes/Swift/Chat/Views/ChatConversationViewSwift.swift index 13c2c8bc3..1a9ea4acf 100644 --- a/Classes/Swift/Chat/Views/ChatConversationViewSwift.swift +++ b/Classes/Swift/Chat/Views/ChatConversationViewSwift.swift @@ -47,6 +47,9 @@ class ChatConversationViewSwift: BackActionsNavigationView, PHPickerViewControll let loadingView = UIView() let loading = RotatingSpinner(color: VoipTheme.primary_color) let loadingText = StyledLabel(VoipTheme.chat_conversation_operation_in_progress_wait) + + var friend: Friend? = nil + var friendDelegate: FriendDelegate? = nil var collectionViewMedia: UICollectionView = { let top_bar_height = 66.0 @@ -532,13 +535,13 @@ class ChatConversationViewSwift: BackActionsNavigationView, PHPickerViewControll let participantFriend = participants?.first?.address?.contact()?.friend - let friend = Friend.getSwiftObject(cObject: participantFriend!) + friend = Friend.getSwiftObject(cObject: participantFriend!) var presenceModel : PresenceModel? var hasPresence : Bool? = false - if friend.address?.asStringUriOnly() != nil { - presenceModel = friend.getPresenceModelForUriOrTel(uriOrTel: (friend.address?.asStringUriOnly())!) + if friend?.address?.asStringUriOnly() != nil { + presenceModel = friend!.getPresenceModelForUriOrTel(uriOrTel: (friend?.address?.asStringUriOnly())!) hasPresence = presenceModel != nil && presenceModel!.basicStatus == PresenceBasicStatus.Open } @@ -569,6 +572,14 @@ class ChatConversationViewSwift: BackActionsNavigationView, PHPickerViewControll participantsGroupLabel.text = VoipTexts.chat_room_presence_last_seen_online + dateString; } } + + friendDelegate = FriendDelegateStub( + onPresenceReceived: { (linphoneFriend: Friend) -> Void in + self.friend?.removeDelegate(delegate: self.friendDelegate!) + self.updateParticipantLabel() + } + ) + friend?.addDelegate(delegate: friendDelegate!) titleParticipants.isHidden = false }else{ diff --git a/Classes/Swift/Voip/Widgets/Avatar.swift b/Classes/Swift/Voip/Widgets/Avatar.swift index dd059ae6f..15aa24285 100644 --- a/Classes/Swift/Voip/Widgets/Avatar.swift +++ b/Classes/Swift/Voip/Widgets/Avatar.swift @@ -150,10 +150,20 @@ class Avatar : UIView { friend.append(Friend.getSwiftObject(cObject: (contactAddress.friend)!)) let newFriendDelegate = FriendDelegateStub( onPresenceReceived: { (linphoneFriend: Friend) -> Void in - print("onPresenceReceivedonPresenceReceived") if (linphoneFriend.address?.asStringUriOnly()) != nil { let presenceModel = linphoneFriend.getPresenceModelForUriOrTel(uriOrTel: (linphoneFriend.address?.asStringUriOnly())!) NotificationCenter.default.post(name: Notification.Name("LinphoneFriendPresenceUpdate"), object: nil, userInfo: ["friend": linphoneFriend.address?.asStringUriOnly() ?? "", "isOnline": presenceModel!.consolidatedPresence.rawValue == LinphoneConsolidatedPresenceOnline.rawValue]) + + var i = 0 + self.friend.forEach { friendForEach in + if friendForEach.address?.asStringUriOnly() == linphoneFriend.address?.asStringUriOnly() { + self.friend[i].removeDelegate(delegate: self.friendDelegate[i]) + self.friendDelegate.remove(at: i) + self.friend.remove(at: i) + } + i += 1; + } + } } )