From cb9707a2312ed3e371590a0b164ef458ce614563 Mon Sep 17 00:00:00 2001 From: "benoit.martins" Date: Mon, 24 Apr 2023 14:27:44 +0200 Subject: [PATCH] Displaying presence in BackActionNavigationView --- .../Views/ChatConversationViewSwift.swift | 70 ++++++++++++++++--- .../Util/BackActionsNavigationView.swift | 4 +- Classes/Swift/Voip/Theme/VoipTexts.swift | 6 ++ Classes/Swift/Voip/Widgets/Avatar.swift | 8 ++- 4 files changed, 71 insertions(+), 17 deletions(-) diff --git a/Classes/Swift/Chat/Views/ChatConversationViewSwift.swift b/Classes/Swift/Chat/Views/ChatConversationViewSwift.swift index 6fb3a39d4..13c2c8bc3 100644 --- a/Classes/Swift/Chat/Views/ChatConversationViewSwift.swift +++ b/Classes/Swift/Chat/Views/ChatConversationViewSwift.swift @@ -490,15 +490,12 @@ class ChatConversationViewSwift: BackActionsNavigationView, PHPickerViewControll let addr = (firstParticipant != nil) ? linphone_participant_get_address(firstParticipant?.getCobject) : linphone_chat_room_get_peer_address(cChatRoom); ChatConversationViewModel.sharedModel.address = FastAddressBook.displayName(for: addr) ?? "unknow" changeIcon = false - titleParticipants.isHidden = true + updateParticipantLabel() } else { ChatConversationViewModel.sharedModel.address = ChatConversationViewModel.sharedModel.chatRoom?.subject changeIcon = true - - titleParticipants.isHidden = false - - updateParticipantLabel() + updateParticipantLabel() } @@ -521,12 +518,63 @@ class ChatConversationViewSwift: BackActionsNavigationView, PHPickerViewControll func updateParticipantLabel(){ let participants = ChatConversationViewModel.sharedModel.chatRoom?.participants participantsGroupLabel.text = "" - participants?.forEach{ participant in - if participantsGroupLabel.text != "" { - participantsGroupLabel.text = participantsGroupLabel.text! + ", " - } - participantsGroupLabel.text = participantsGroupLabel.text! + FastAddressBook.displayName(for: linphone_participant_get_address(participant.getCobject)) - } + if participants!.count > 1 { + participants?.forEach{ participant in + if participantsGroupLabel.text != "" { + participantsGroupLabel.text = participantsGroupLabel.text! + ", " + } + participantsGroupLabel.text = participantsGroupLabel.text! + FastAddressBook.displayName(for: linphone_participant_get_address(participant.getCobject)) + } + titleParticipants.isHidden = false + }else if participants?.first?.address?.contact() != nil { + let participantAddress = participants?.first?.address + participantsGroupLabel.text = participantAddress?.asStringUriOnly() + + + let participantFriend = participants?.first?.address?.contact()?.friend + let friend = Friend.getSwiftObject(cObject: participantFriend!) + + var presenceModel : PresenceModel? + var hasPresence : Bool? = false + + if friend.address?.asStringUriOnly() != nil { + presenceModel = friend.getPresenceModelForUriOrTel(uriOrTel: (friend.address?.asStringUriOnly())!) + hasPresence = presenceModel != nil && presenceModel!.basicStatus == PresenceBasicStatus.Open + } + + if (hasPresence! && presenceModel?.consolidatedPresence == ConsolidatedPresence.Online) { + participantsGroupLabel.text = VoipTexts.chat_room_presence_online; + } else if (hasPresence! && presenceModel?.consolidatedPresence == ConsolidatedPresence.Busy){ + + let timeInterval = TimeInterval(presenceModel!.latestActivityTimestamp) + let myNSDate = Date(timeIntervalSince1970: timeInterval) + + + if timeInterval == -1 { + participantsGroupLabel.text = VoipTexts.chat_room_presence_away; + } else if Calendar.current.isDateInToday(myNSDate) { + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "HH:mm" + let dateString = dateFormatter.string(from: myNSDate) + participantsGroupLabel.text = VoipTexts.chat_room_presence_last_seen_online_today + dateString; + } else if Calendar.current.isDateInYesterday(myNSDate) { + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "HH:mm" + let dateString = dateFormatter.string(from: myNSDate) + participantsGroupLabel.text = VoipTexts.chat_room_presence_last_seen_online_yesterday + dateString; + } else { + let dateFormatter = DateFormatter() + dateFormatter.dateStyle = .short + let dateString = dateFormatter.string(from: myNSDate) + participantsGroupLabel.text = VoipTexts.chat_room_presence_last_seen_online + dateString; + } + } + + titleParticipants.isHidden = false + }else{ + titleParticipants.isHidden = true + } + } func updateParticipantLabel(){ diff --git a/Classes/Swift/Util/BackActionsNavigationView.swift b/Classes/Swift/Util/BackActionsNavigationView.swift index c195fbe84..c2443cb91 100644 --- a/Classes/Swift/Util/BackActionsNavigationView.swift +++ b/Classes/Swift/Util/BackActionsNavigationView.swift @@ -141,7 +141,7 @@ class BackActionsNavigationView: UIViewController { titleLabel.toRightOf(backButton, withLeftMargin: 10).matchParentHeight().done() titleLabel.toLeftOf(action1Button, withRightMargin: 20).done() titleLabel.text = title - + topBar.addSubview(titleParticipants) titleParticipants.toRightOf(backButton, withLeftMargin: 10).matchParentHeight().done() titleParticipants.backgroundColor = VoipTheme.voipToolbarBackgroundColor.get() @@ -154,8 +154,6 @@ class BackActionsNavigationView: UIViewController { titleParticipants.addSubview(participantsGroupLabel) participantsGroupLabel.alignParentBottom(withMargin: 10).matchParentSideBorders().done() participantsGroupLabel.text = participants - - titleParticipants.isHidden = true super.viewDidLoad() diff --git a/Classes/Swift/Voip/Theme/VoipTexts.swift b/Classes/Swift/Voip/Theme/VoipTexts.swift index a3cce72bc..5319f8a02 100644 --- a/Classes/Swift/Voip/Theme/VoipTexts.swift +++ b/Classes/Swift/Voip/Theme/VoipTexts.swift @@ -207,6 +207,12 @@ import UIKit @objc static let bubble_chat_event_message_attack_detected_for = NSLocalizedString("Man-in-the-middle attack detected for %@",comment:"").replacingOccurrences(of: "%@", with: "") @objc static let bubble_chat_download_file = NSLocalizedString("Download",comment:"") + + @objc static let chat_room_presence_online = NSLocalizedString("Online",comment:"") + @objc static let chat_room_presence_last_seen_online_today = NSLocalizedString("Online today at ",comment:"") + @objc static let chat_room_presence_last_seen_online_yesterday = NSLocalizedString("Online yesterday at ",comment:"") + @objc static let chat_room_presence_last_seen_online = NSLocalizedString("Online on ",comment:"") + @objc static let chat_room_presence_away = NSLocalizedString("Away",comment:"") // FROM ANDROID END diff --git a/Classes/Swift/Voip/Widgets/Avatar.swift b/Classes/Swift/Voip/Widgets/Avatar.swift index d74f20ba5..dd059ae6f 100644 --- a/Classes/Swift/Voip/Widgets/Avatar.swift +++ b/Classes/Swift/Voip/Widgets/Avatar.swift @@ -150,9 +150,11 @@ class Avatar : UIView { 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!.consolidatedPresence.rawValue == LinphoneConsolidatedPresenceOnline.rawValue]) + 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]) + } } ) friendDelegate.append(newFriendDelegate)