Displaying presence in BackActionNavigationView

This commit is contained in:
benoit.martins 2023-04-24 14:27:44 +02:00 committed by QuentinArguillere
parent b045117ed7
commit cb9707a231
4 changed files with 71 additions and 17 deletions

View file

@ -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(){

View file

@ -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()

View file

@ -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

View file

@ -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)