Merge remote-tracking branch 'refs/remotes/origin/fix/beta_fixes'

#Conflicts:
#	Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift
This commit is contained in:
benoit.martins 2025-02-06 19:47:24 +01:00
commit db24bd842f
6 changed files with 117 additions and 44 deletions

View file

@ -150,14 +150,23 @@ final class ContactsManager: ObservableObject {
linphoneFriend.addAddress(address: address!)
linphoneFriend.done()
let addressTmp = linphoneFriend.address?.clone()?.asStringUriOnly() ?? ""
addedAvatarListModel.append(
ContactAvatarModel(
friend: linphoneFriend,
name: linphoneFriend.name ?? "",
address: linphoneFriend.address?.clone()?.asStringUriOnly() ?? "",
address: addressTmp,
withPresence: true
)
)
DispatchQueue.main.async {
NotificationCenter.default.post(
name: NSNotification.Name("ContactAdded"),
object: nil,
userInfo: ["address": addressTmp]
)
}
}
}
@ -342,25 +351,21 @@ final class ContactsManager: ObservableObject {
}
func getFriendWithAddress(address: Address?) -> Friend? {
if address != nil {
let clonedAddress = address!.clone()
clonedAddress!.clean()
let sipUri = clonedAddress!.asStringUriOnly()
if self.friendList != nil && !self.friendList!.friends.isEmpty {
var friend: Friend?
friend = self.friendList!.friends.first(where: {$0.addresses.contains(where: {$0.asStringUriOnly() == sipUri})})
if friend == nil && self.linphoneFriendList != nil && !self.linphoneFriendList!.friends.isEmpty {
friend = self.linphoneFriendList!.friends.first(where: {$0.addresses.contains(where: {$0.asStringUriOnly() == sipUri})})
}
return friend
} else {
return nil
}
} else {
print("getFriendWithAddress")
guard let address = address, let clonedAddress = address.clone() else {
return nil
}
clonedAddress.clean()
let sipUri = clonedAddress.asStringUriOnly()
var friend: Friend?
if let friendList = self.friendList {
friend = friendList.friends.first(where: { $0.addresses.contains(where: { $0.asStringUriOnly() == sipUri }) })
}
if friend == nil, let linphoneFriendList = self.linphoneFriendList {
friend = linphoneFriendList.friends.first(where: { $0.addresses.contains(where: { $0.asStringUriOnly() == sipUri }) })
}
return friend
}
func getFriendWithAddressInCoreQueue(address: Address?, completion: @escaping (Friend?) -> Void) {

View file

@ -163,17 +163,18 @@ struct ContactInnerFragment: View {
Image("phone")
.renderingMode(.template)
.resizable()
.foregroundStyle(Color.grayMain2c600)
.foregroundStyle(contactAvatarModel.address.isEmpty ? Color.grayMain2c400 : Color.grayMain2c600)
.frame(width: 25, height: 25)
}
.padding(16)
.background(Color.grayMain2c200)
.background(contactAvatarModel.address.isEmpty ? Color.grayMain2c100 : Color.grayMain2c200)
.cornerRadius(40)
Text("contact_call_action")
.default_text_style(styleSize: 14)
}
})
.disabled(contactAvatarModel.address.isEmpty)
Spacer()
@ -195,17 +196,18 @@ struct ContactInnerFragment: View {
Image("chat-teardrop-text")
.renderingMode(.template)
.resizable()
.foregroundStyle(Color.grayMain2c600)
.foregroundStyle(contactAvatarModel.address.isEmpty ? Color.grayMain2c400 : Color.grayMain2c600)
.frame(width: 25, height: 25)
}
.padding(16)
.background(Color.grayMain2c200)
.background(contactAvatarModel.address.isEmpty ? Color.grayMain2c100 : Color.grayMain2c200)
.cornerRadius(40)
Text("contact_message_action")
.default_text_style(styleSize: 14)
}
})
.disabled(contactAvatarModel.address.isEmpty)
Spacer()
@ -227,17 +229,18 @@ struct ContactInnerFragment: View {
Image("video-camera")
.renderingMode(.template)
.resizable()
.foregroundStyle(Color.grayMain2c600)
.foregroundStyle(contactAvatarModel.address.isEmpty ? Color.grayMain2c400 : Color.grayMain2c600)
.frame(width: 25, height: 25)
}
.padding(16)
.background(Color.grayMain2c200)
.background(contactAvatarModel.address.isEmpty ? Color.grayMain2c100 : Color.grayMain2c200)
.cornerRadius(40)
Text("contact_video_call_action")
.default_text_style(styleSize: 14)
}
})
.disabled(contactAvatarModel.address.isEmpty)
Spacer()
}

View file

@ -22,6 +22,7 @@ import linphonesw
import Combine
class ContactAvatarModel: ObservableObject, Identifiable {
let id = UUID()
let friend: Friend?
@ -46,24 +47,23 @@ class ContactAvatarModel: ObservableObject, Identifiable {
self.name = name
self.address = address
var addressesTmp: [String] = []
if friend != nil {
friend!.addresses.forEach { address in
if let friend = friend {
friend.addresses.forEach { address in
addressesTmp.append(address.asStringUriOnly())
}
}
self.addresses = addressesTmp
self.nativeUri = friend?.nativeUri ?? ""
self.withPresence = withPresence
if friend != nil &&
withPresence == true {
if let friend = friend, withPresence == true {
self.lastPresenceInfo = ""
self.presenceStatus = friend!.consolidatedPresence
self.presenceStatus = friend.consolidatedPresence
if friend!.consolidatedPresence == .Online || friend!.consolidatedPresence == .Busy {
if friend!.consolidatedPresence == .Online || friend!.presenceModel!.latestActivityTimestamp != -1 {
self.lastPresenceInfo = (friend!.consolidatedPresence == .Online) ?
"Online" : getCallTime(startDate: friend!.presenceModel!.latestActivityTimestamp)
if friend.consolidatedPresence == .Online || friend.consolidatedPresence == .Busy {
if friend.consolidatedPresence == .Online || friend.presenceModel?.latestActivityTimestamp != -1 {
self.lastPresenceInfo = (friend.consolidatedPresence == .Online) ?
"Online" : getCallTime(startDate: friend.presenceModel!.latestActivityTimestamp)
} else {
self.lastPresenceInfo = "Away"
}

View file

@ -86,6 +86,9 @@ struct ContentView: View {
var body: some View {
let pub = NotificationCenter.default
.publisher(for: NSNotification.Name("ContactLoaded"))
let pub2 = NotificationCenter.default
.publisher(for: NSNotification.Name("ContactAdded"))
.compactMap { $0.userInfo?["address"] as? String }
let imageChanged = NotificationCenter.default
.publisher(for: NSNotification.Name("ImageChanged"))
GeometryReader { geometry in
@ -110,7 +113,7 @@ struct ContentView: View {
Spacer()
if callViewModel.callsCounter == 1 {
Text(String(localized: "\(callViewModel.isPaused || telecomManager.isPausedByRemote ? "call_state_paused" : "call_state_connected")"))
Text(callViewModel.isPaused || telecomManager.isPausedByRemote ? String(localized: "call_state_paused") : String(localized: "call_state_connected"))
.default_text_style_white(styleSize: 16)
.padding(.trailing, 10)
}
@ -1358,6 +1361,9 @@ struct ContentView: View {
conversationsListViewModel.updateChatRoomsList()
historyListViewModel.refreshHistoryAvatarModel()
}
.onReceive(pub2) { address in
conversationsListViewModel.updateChatRoom(address: address)
}
}
.overlay {
if isMenuOpen {

View file

@ -123,6 +123,62 @@ class ConversationsListViewModel: ObservableObject {
}
}
func updateChatRoom(address: String) {
CoreContext.shared.doOnCoreQueue { _ in
if let contactAvatarModel = self.contactsManager.avatarListModel.first(where: {$0.addresses.contains(address)}) {
self.conversationsListTmp.forEach { conversationModel in
if conversationModel.participantsAddress.contains(contactAvatarModel.address) {
if conversationModel.isGroup && conversationModel.participantsAddress.count > 1 {
let lastMessage = conversationModel.chatRoom.lastMessageInHistory
if lastMessage != nil && lastMessage!.fromAddress != nil && lastMessage!.fromAddress!.asStringUriOnly().contains(contactAvatarModel.address) {
var fromAddressFriend = lastMessage!.fromAddress != nil
? self.contactsManager.getFriendWithAddress(address: lastMessage!.fromAddress)?.name ?? nil
: nil
if !lastMessage!.isOutgoing && lastMessage!.chatRoom != nil && !lastMessage!.chatRoom!.hasCapability(mask: ChatRoom.Capabilities.OneToOne.rawValue) {
if fromAddressFriend == nil {
if lastMessage!.fromAddress!.displayName != nil {
fromAddressFriend = lastMessage!.fromAddress!.displayName! + ": "
} else if lastMessage!.fromAddress!.username != nil {
fromAddressFriend = lastMessage!.fromAddress!.username! + ": "
} else {
fromAddressFriend = String(lastMessage!.fromAddress!.asStringUriOnly().dropFirst(4)) + ": "
}
} else {
fromAddressFriend! += ": "
}
} else {
fromAddressFriend = nil
}
let lastMessageTextTmp = (fromAddressFriend ?? "")
+ (lastMessage!.contents.first(where: {$0.isText == true})?.utf8Text ?? (lastMessage!.contents.first(where: {$0.isFile == true || $0.isFileTransfer == true})?.name ?? ""))
let index = self.conversationsList.firstIndex(where: { $0.chatRoom === conversationModel.chatRoom })
DispatchQueue.main.async {
conversationModel.lastMessageText = lastMessageTextTmp
if index != nil {
self.conversationsList[index!].lastMessageText = lastMessageTextTmp
}
}
}
} else if !conversationModel.isGroup && conversationModel.participantsAddress.first != nil && conversationModel.participantsAddress.first!.contains(contactAvatarModel.address) {
let index = self.conversationsList.firstIndex(where: { $0.chatRoom === conversationModel.chatRoom })
DispatchQueue.main.async {
conversationModel.avatarModel = contactAvatarModel
conversationModel.subject = contactAvatarModel.name
if index != nil {
self.conversationsList[index!].avatarModel = contactAvatarModel
}
}
}
}
}
}
}
}
func addConversationDelegate() {
coreContext.doOnCoreQueue { core in
self.coreConversationDelegate = CoreDelegateStub(onMessagesReceived: { (_: Core, chatRoom: ChatRoom, _: [ChatMessage]) in

View file

@ -112,24 +112,27 @@ class HistoryModel: ObservableObject {
func refreshAvatarModel() {
coreContext.doOnCoreQueue { _ in
let addressFriendTmp = ContactsManager.shared.getFriendWithAddress(
address: self.callLog.dir == .Outgoing ? self.callLog.toAddress! : self.callLog.fromAddress!
)
if addressFriendTmp != nil {
guard let address = (self.callLog.dir == .Outgoing ? self.callLog.toAddress : self.callLog.fromAddress) else {
DispatchQueue.main.async {
self.avatarModel = ContactAvatarModel(friend: nil, name: self.addressName, address: self.address, withPresence: false)
}
return
}
let addressFriendTmp = ContactsManager.shared.getFriendWithAddress(address: address)
if let addressFriendTmp = addressFriendTmp {
self.addressFriend = addressFriendTmp
let addressNameTmp = self.addressName
let avatarModelTmp = addressFriendTmp != nil
? ContactsManager.shared.avatarListModel.first(where: {
$0.friend!.name == addressFriendTmp!.name
&& $0.friend!.address!.asStringUriOnly() == addressFriendTmp!.address!.asStringUriOnly()
let avatarModelTmp = ContactsManager.shared.avatarListModel.first(where: {
guard let friend = $0.friend else { return false }
return friend.name == addressFriendTmp.name && friend.address?.asStringUriOnly() == addressFriendTmp.address?.asStringUriOnly()
}) ?? ContactAvatarModel(friend: nil, name: self.addressName, address: self.address, withPresence: false)
: ContactAvatarModel(friend: nil, name: self.addressName, address: self.address, withPresence: false)
DispatchQueue.main.async {
self.addressFriend = addressFriendTmp
self.addressName = addressFriendTmp!.name ?? addressNameTmp
self.addressName = addressFriendTmp.name ?? addressNameTmp
self.avatarModel = avatarModelTmp
}
} else {