Bug fixes for the public beta

This commit is contained in:
Benoit Martins 2025-02-06 17:52:34 +01:00
parent ad54e09253
commit be53335b67
7 changed files with 117 additions and 60 deletions

View file

@ -150,14 +150,23 @@ final class ContactsManager: ObservableObject {
linphoneFriend.addAddress(address: address!) linphoneFriend.addAddress(address: address!)
linphoneFriend.done() linphoneFriend.done()
let addressTmp = linphoneFriend.address?.clone()?.asStringUriOnly() ?? ""
addedAvatarListModel.append( addedAvatarListModel.append(
ContactAvatarModel( ContactAvatarModel(
friend: linphoneFriend, friend: linphoneFriend,
name: linphoneFriend.name ?? "", name: linphoneFriend.name ?? "",
address: linphoneFriend.address?.clone()?.asStringUriOnly() ?? "", address: addressTmp,
withPresence: true 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? { func getFriendWithAddress(address: Address?) -> Friend? {
if address != nil { print("getFriendWithAddress")
let clonedAddress = address!.clone() guard let address = address, let clonedAddress = address.clone() else {
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 {
return nil 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) { func getFriendWithAddressInCoreQueue(address: Address?, completion: @escaping (Friend?) -> Void) {

View file

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

View file

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

View file

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

View file

@ -85,8 +85,6 @@ struct ConversationRow: View {
@Binding var text: String @Binding var text: String
var body: some View { var body: some View {
let pub = NotificationCenter.default
.publisher(for: NSNotification.Name("ChatRoomsComputed"))
HStack { HStack {
Avatar(contactAvatarModel: conversation.avatarModel, avatarSize: 50) Avatar(contactAvatarModel: conversation.avatarModel, avatarSize: 50)
@ -189,15 +187,6 @@ struct ConversationRow: View {
.listRowInsets(EdgeInsets(top: 6, leading: 20, bottom: 6, trailing: 20)) .listRowInsets(EdgeInsets(top: 6, leading: 20, bottom: 6, trailing: 20))
.listRowSeparator(.hidden) .listRowSeparator(.hidden)
.background(.white) .background(.white)
.onReceive(pub) { _ in
/*
if navigationManager.peerAddr != nil
&& conversation.remoteSipUri.contains(navigationManager.peerAddr!) {
conversationViewModel.getChatRoomWithStringAddress(conversationsList: conversationsListViewModel.conversationsList, stringAddr: navigationManager.peerAddr!)
navigationManager.peerAddr = nil
}
*/
}
.onTapGesture { .onTapGesture {
conversationViewModel.changeDisplayedChatRoom(conversationModel: conversation) conversationViewModel.changeDisplayedChatRoom(conversationModel: conversation)
} }

View file

@ -61,11 +61,6 @@ class ConversationsListViewModel: ObservableObject {
} }
} }
DispatchQueue.main.async {
//self.conversationsList = self.conversationsListTmp
NotificationCenter.default.post(name: NSNotification.Name("ChatRoomsComputed"), object: nil)
}
self.updateUnreadMessagesCount() self.updateUnreadMessagesCount()
} }
} }
@ -128,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() { func addConversationDelegate() {
coreContext.doOnCoreQueue { core in coreContext.doOnCoreQueue { core in
self.coreConversationDelegate = CoreDelegateStub(onMessagesReceived: { (_: Core, chatRoom: ChatRoom, _: [ChatMessage]) in self.coreConversationDelegate = CoreDelegateStub(onMessagesReceived: { (_: Core, chatRoom: ChatRoom, _: [ChatMessage]) in

View file

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