mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 02:58:07 +00:00
Fix contacts list
This commit is contained in:
parent
c54fda28f3
commit
106e628e41
5 changed files with 71 additions and 23 deletions
|
|
@ -36,9 +36,11 @@ final class ContactsManager: ObservableObject {
|
||||||
|
|
||||||
private let nativeAddressBookFriendList = "Native address-book"
|
private let nativeAddressBookFriendList = "Native address-book"
|
||||||
let linphoneAddressBookFriendList = "Linphone address-book"
|
let linphoneAddressBookFriendList = "Linphone address-book"
|
||||||
|
let tempRemoteAddressBookFriendList = "TempRemoteDirectoryContacts address-book"
|
||||||
|
|
||||||
var friendList: FriendList?
|
var friendList: FriendList?
|
||||||
var linphoneFriendList: FriendList?
|
var linphoneFriendList: FriendList?
|
||||||
|
var tempRemoteFriendList: FriendList?
|
||||||
|
|
||||||
@Published var lastSearch: [SearchResult] = []
|
@Published var lastSearch: [SearchResult] = []
|
||||||
@Published var lastSearchSuggestions: [SearchResult] = []
|
@Published var lastSearchSuggestions: [SearchResult] = []
|
||||||
|
|
@ -96,6 +98,21 @@ final class ContactsManager: ObservableObject {
|
||||||
core.addFriendList(list: linphoneFriendList)
|
core.addFriendList(list: linphoneFriendList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
self.tempRemoteFriendList = try core.getFriendListByName(name: self.tempRemoteAddressBookFriendList) ?? core.createFriendList()
|
||||||
|
} catch let error {
|
||||||
|
print("\(#function) - Failed to enumerate contacts: \(error)")
|
||||||
|
}
|
||||||
|
|
||||||
|
if let tempRemoteFriendList = self.tempRemoteFriendList {
|
||||||
|
if tempRemoteFriendList.displayName == nil || tempRemoteFriendList.displayName!.isEmpty {
|
||||||
|
print("\(#function) - Friend list \(self.tempRemoteAddressBookFriendList) didn't exist yet, let's create it")
|
||||||
|
tempRemoteFriendList.databaseStorageEnabled = true
|
||||||
|
tempRemoteFriendList.displayName = self.tempRemoteAddressBookFriendList
|
||||||
|
core.addFriendList(list: tempRemoteFriendList)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let store = CNContactStore()
|
let store = CNContactStore()
|
||||||
|
|
@ -142,7 +159,7 @@ final class ContactsManager: ObservableObject {
|
||||||
image: image,
|
image: image,
|
||||||
name: contact.givenName + contact.familyName,
|
name: contact.givenName + contact.familyName,
|
||||||
prefix: "",
|
prefix: "",
|
||||||
contact: newContact, linphoneFriend: false, existingFriend: nil) {
|
contact: newContact, linphoneFriend: self.nativeAddressBookFriendList, existingFriend: nil) {
|
||||||
dispatchGroup.leave()
|
dispatchGroup.leave()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -152,7 +169,7 @@ final class ContactsManager: ObservableObject {
|
||||||
image: image,
|
image: image,
|
||||||
name: contact.givenName + contact.familyName,
|
name: contact.givenName + contact.familyName,
|
||||||
prefix: "-default",
|
prefix: "-default",
|
||||||
contact: newContact, linphoneFriend: false, existingFriend: nil) {
|
contact: newContact, linphoneFriend: self.nativeAddressBookFriendList, existingFriend: nil) {
|
||||||
dispatchGroup.leave()
|
dispatchGroup.leave()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -237,7 +254,7 @@ final class ContactsManager: ObservableObject {
|
||||||
return IBImgViewUserProfile
|
return IBImgViewUserProfile
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveImage(image: UIImage, name: String, prefix: String, contact: Contact, linphoneFriend: Bool, existingFriend: Friend?, completion: @escaping () -> Void) {
|
func saveImage(image: UIImage, name: String, prefix: String, contact: Contact, linphoneFriend: String, existingFriend: Friend?, completion: @escaping () -> Void) {
|
||||||
guard let data = image.jpegData(compressionQuality: 1) ?? image.pngData() else {
|
guard let data = image.jpegData(compressionQuality: 1) ?? image.pngData() else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -245,8 +262,10 @@ final class ContactsManager: ObservableObject {
|
||||||
awaitDataWrite(data: data, name: name, prefix: prefix) { _, result in
|
awaitDataWrite(data: data, name: name, prefix: prefix) { _, result in
|
||||||
self.saveFriend(result: result, contact: contact, existingFriend: existingFriend) { resultFriend in
|
self.saveFriend(result: result, contact: contact, existingFriend: existingFriend) { resultFriend in
|
||||||
if resultFriend != nil {
|
if resultFriend != nil {
|
||||||
if linphoneFriend && existingFriend == nil {
|
if linphoneFriend != self.nativeAddressBookFriendList && existingFriend == nil {
|
||||||
if let linphoneFL = self.linphoneFriendList {
|
if let linphoneFL = self.linphoneFriendList, linphoneFriend == linphoneFL.displayName {
|
||||||
|
_ = linphoneFL.addFriend(linphoneFriend: resultFriend!)
|
||||||
|
} else if let linphoneFL = self.tempRemoteFriendList {
|
||||||
_ = linphoneFL.addFriend(linphoneFriend: resultFriend!)
|
_ = linphoneFL.addFriend(linphoneFriend: resultFriend!)
|
||||||
}
|
}
|
||||||
} else if existingFriend == nil {
|
} else if existingFriend == nil {
|
||||||
|
|
@ -378,12 +397,17 @@ final class ContactsManager: ObservableObject {
|
||||||
let sipUri = clonedAddress.asStringUriOnly()
|
let sipUri = clonedAddress.asStringUriOnly()
|
||||||
|
|
||||||
var friend: Friend?
|
var friend: Friend?
|
||||||
|
|
||||||
if let friendList = self.friendList {
|
if let friendList = self.friendList {
|
||||||
friend = friendList.friends.first(where: { $0.addresses.contains(where: { $0.asStringUriOnly() == sipUri }) })
|
friend = friendList.friends.first(where: { $0.addresses.contains(where: { $0.asStringUriOnly() == sipUri }) })
|
||||||
}
|
}
|
||||||
if friend == nil, let linphoneFriendList = self.linphoneFriendList {
|
if friend == nil, let linphoneFriendList = self.linphoneFriendList {
|
||||||
friend = linphoneFriendList.friends.first(where: { $0.addresses.contains(where: { $0.asStringUriOnly() == sipUri }) })
|
friend = linphoneFriendList.friends.first(where: { $0.addresses.contains(where: { $0.asStringUriOnly() == sipUri }) })
|
||||||
}
|
}
|
||||||
|
if friend == nil, let tempRemoteFriendList = self.tempRemoteFriendList {
|
||||||
|
friend = tempRemoteFriendList.friends.first(where: { $0.addresses.contains(where: { $0.asStringUriOnly() == sipUri }) })
|
||||||
|
}
|
||||||
|
|
||||||
return friend
|
return friend
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -414,7 +438,18 @@ final class ContactsManager: ObservableObject {
|
||||||
onSyncStatusChanged: { (friendList: FriendList, status: FriendList.SyncStatus?, message: String?) in
|
onSyncStatusChanged: { (friendList: FriendList, status: FriendList.SyncStatus?, message: String?) in
|
||||||
Log.info("\(ContactsManager.TAG) FriendListDelegateStub onSyncStatusChanged")
|
Log.info("\(ContactsManager.TAG) FriendListDelegateStub onSyncStatusChanged")
|
||||||
if status == .Successful {
|
if status == .Successful {
|
||||||
|
if friendList.displayName != self.nativeAddressBookFriendList && friendList.displayName != self.linphoneAddressBookFriendList {
|
||||||
|
if let tempRemoteFriendList = self.tempRemoteFriendList {
|
||||||
|
tempRemoteFriendList.friends.forEach { friend in
|
||||||
|
_ = tempRemoteFriendList.removeFriend(linphoneFriend: friend)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let dispatchGroup = DispatchGroup()
|
||||||
|
|
||||||
friendList.friends.forEach { friend in
|
friendList.friends.forEach { friend in
|
||||||
|
dispatchGroup.enter()
|
||||||
let addressTmp = friend.address?.clone()?.asStringUriOnly() ?? ""
|
let addressTmp = friend.address?.clone()?.asStringUriOnly() ?? ""
|
||||||
|
|
||||||
let newContact = Contact(
|
let newContact = Contact(
|
||||||
|
|
@ -434,14 +469,19 @@ final class ContactsManager: ObservableObject {
|
||||||
image: image,
|
image: image,
|
||||||
name: friend.name ?? addressTmp,
|
name: friend.name ?? addressTmp,
|
||||||
prefix: "-default",
|
prefix: "-default",
|
||||||
contact: newContact, linphoneFriend: false, existingFriend: friend) {
|
contact: newContact, linphoneFriend: friendList.displayName ?? "No Display Name", existingFriend: nil) {
|
||||||
|
dispatchGroup.leave()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dispatchGroup.notify(queue: .main) {
|
||||||
MagicSearchSingleton.shared.searchForContacts()
|
MagicSearchSingleton.shared.searchForContacts()
|
||||||
|
if let linphoneFL = self.tempRemoteFriendList {
|
||||||
|
linphoneFL.updateSubscriptions()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onPresenceReceived: { (friendList: FriendList, friends: [Friend?]) in
|
onPresenceReceived: { (friendList: FriendList, friends: [Friend?]) in
|
||||||
Log.info("\(ContactsManager.TAG) FriendListDelegateStub onPresenceReceived \(friends.count)")
|
Log.info("\(ContactsManager.TAG) FriendListDelegateStub onPresenceReceived \(friends.count)")
|
||||||
|
|
|
||||||
|
|
@ -554,7 +554,7 @@ struct EditContactFragment: View {
|
||||||
name: editContactViewModel.firstName
|
name: editContactViewModel.firstName
|
||||||
+ editContactViewModel.lastName,
|
+ editContactViewModel.lastName,
|
||||||
prefix: ((selectedImage == nil) ? "-default" : ""),
|
prefix: ((selectedImage == nil) ? "-default" : ""),
|
||||||
contact: newContact, linphoneFriend: true, existingFriend: editContactViewModel.selectedEditFriend?.friend) {
|
contact: newContact, linphoneFriend: "Linphone address-book", existingFriend: editContactViewModel.selectedEditFriend?.friend) {
|
||||||
if let selectedFriendTmp = editContactViewModel.selectedEditFriend?.friend {
|
if let selectedFriendTmp = editContactViewModel.selectedEditFriend?.friend {
|
||||||
let addressTmp = selectedFriendTmp.address?.clone()?.asStringUriOnly() ?? ""
|
let addressTmp = selectedFriendTmp.address?.clone()?.asStringUriOnly() ?? ""
|
||||||
SharedMainViewModel.shared.displayedFriend?.resetContactAvatarModel(
|
SharedMainViewModel.shared.displayedFriend?.resetContactAvatarModel(
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ class ContactAvatarModel: ObservableObject, Identifiable {
|
||||||
var presenceStatusTmp: ConsolidatedPresence = .Offline
|
var presenceStatusTmp: ConsolidatedPresence = .Offline
|
||||||
|
|
||||||
if let friend = friend, withPresence == true {
|
if let friend = friend, withPresence == true {
|
||||||
|
|
||||||
lastPresenceInfoTmp = ""
|
lastPresenceInfoTmp = ""
|
||||||
|
|
||||||
presenceStatusTmp = friend.consolidatedPresence
|
presenceStatusTmp = friend.consolidatedPresence
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ struct EditContactView: UIViewControllerRepresentable {
|
||||||
name: cnc.givenName + cnc.familyName,
|
name: cnc.givenName + cnc.familyName,
|
||||||
prefix: ((imageThumbnail == nil) ? "-default" : ""),
|
prefix: ((imageThumbnail == nil) ? "-default" : ""),
|
||||||
contact: newContact,
|
contact: newContact,
|
||||||
linphoneFriend: false,
|
linphoneFriend: "Native address-book",
|
||||||
existingFriend: ContactsManager.shared.getFriendWithContact(contact: newContact)) {
|
existingFriend: ContactsManager.shared.getFriendWithContact(contact: newContact)) {
|
||||||
MagicSearchSingleton.shared.searchForContacts()
|
MagicSearchSingleton.shared.searchForContacts()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,10 @@ final class MagicSearchSingleton: ObservableObject {
|
||||||
|
|
||||||
private var contactLoadedDebounceWorkItem: DispatchWorkItem?
|
private var contactLoadedDebounceWorkItem: DispatchWorkItem?
|
||||||
|
|
||||||
|
let nativeAddressBookFriendList = "Native address-book"
|
||||||
|
let linphoneAddressBookFriendList = "Linphone address-book"
|
||||||
|
let tempRemoteAddressBookFriendList = "TempRemoteDirectoryContacts address-book"
|
||||||
|
|
||||||
func destroyMagicSearch() {
|
func destroyMagicSearch() {
|
||||||
magicSearch = nil
|
magicSearch = nil
|
||||||
}
|
}
|
||||||
|
|
@ -67,7 +71,7 @@ final class MagicSearchSingleton: ObservableObject {
|
||||||
var lastSearchSuggestions: [SearchResult] = []
|
var lastSearchSuggestions: [SearchResult] = []
|
||||||
|
|
||||||
magicSearch.lastSearch.forEach { searchResult in
|
magicSearch.lastSearch.forEach { searchResult in
|
||||||
if searchResult.friend != nil {
|
if searchResult.friend != nil && (searchResult.friend?.friendList?.displayName == self.nativeAddressBookFriendList || searchResult.friend?.friendList?.displayName == self.linphoneAddressBookFriendList || searchResult.friend?.friendList?.displayName == self.tempRemoteAddressBookFriendList) {
|
||||||
if let address = searchResult.address,
|
if let address = searchResult.address,
|
||||||
!lastSearchFriend.contains(where: { $0.address?.weakEqual(address2: address) ?? false }) {
|
!lastSearchFriend.contains(where: { $0.address?.weakEqual(address2: address) ?? false }) {
|
||||||
lastSearchFriend.append(searchResult)
|
lastSearchFriend.append(searchResult)
|
||||||
|
|
@ -99,6 +103,8 @@ final class MagicSearchSingleton: ObservableObject {
|
||||||
var addedAvatarListModel: [ContactAvatarModel] = []
|
var addedAvatarListModel: [ContactAvatarModel] = []
|
||||||
sortedLastSearch.forEach { searchResult in
|
sortedLastSearch.forEach { searchResult in
|
||||||
if searchResult.friend != nil {
|
if searchResult.friend != nil {
|
||||||
|
if (searchResult.friend?.friendList?.displayName == self.nativeAddressBookFriendList || searchResult.friend?.friendList?.displayName == self.linphoneAddressBookFriendList || searchResult.friend?.friendList?.displayName == self.tempRemoteAddressBookFriendList) {
|
||||||
|
|
||||||
addedAvatarListModel.append(
|
addedAvatarListModel.append(
|
||||||
ContactAvatarModel(
|
ContactAvatarModel(
|
||||||
friend: searchResult.friend!,
|
friend: searchResult.friend!,
|
||||||
|
|
@ -109,6 +115,7 @@ final class MagicSearchSingleton: ObservableObject {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.contactsManager.avatarListModel.forEach { contactAvatarModel in
|
self.contactsManager.avatarListModel.forEach { contactAvatarModel in
|
||||||
contactAvatarModel.removeFriendDelegate()
|
contactAvatarModel.removeFriendDelegate()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue