forked from mirrors/linphone-iphone
Run getFriendWithAddress in the core queue if necessary
This commit is contained in:
parent
c69ca4c971
commit
1e16dbaa61
10 changed files with 254 additions and 270 deletions
|
|
@ -301,28 +301,31 @@ final class ContactsManager: ObservableObject {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func getFriendWithAddress(address: Address?, completion: @escaping (Friend?) -> Void) {
|
||||
self.coreContext.doOnCoreQueue { core in
|
||||
if address != nil {
|
||||
let clonedAddress = address!.clone()
|
||||
clonedAddress!.clean()
|
||||
let sipUri = clonedAddress!.asStringUriOnly()
|
||||
|
||||
if self.friendList != nil {
|
||||
var friend: Friend?
|
||||
friend = self.friendList!.friends.first(where: {$0.addresses.contains(where: {$0.asStringUriOnly() == sipUri})})
|
||||
if friend == nil {
|
||||
friend = self.linphoneFriendList!.friends.first(where: {$0.addresses.contains(where: {$0.asStringUriOnly() == sipUri})})
|
||||
}
|
||||
|
||||
completion(friend)
|
||||
} else {
|
||||
completion(nil)
|
||||
func getFriendWithAddress(address: Address?) -> Friend? {
|
||||
if address != nil {
|
||||
let clonedAddress = address!.clone()
|
||||
clonedAddress!.clean()
|
||||
let sipUri = clonedAddress!.asStringUriOnly()
|
||||
|
||||
if self.friendList != nil {
|
||||
var friend: Friend?
|
||||
friend = self.friendList!.friends.first(where: {$0.addresses.contains(where: {$0.asStringUriOnly() == sipUri})})
|
||||
if friend == nil {
|
||||
friend = self.linphoneFriendList!.friends.first(where: {$0.addresses.contains(where: {$0.asStringUriOnly() == sipUri})})
|
||||
}
|
||||
|
||||
return friend
|
||||
} else {
|
||||
completion(nil)
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func getFriendWithAddressInCoreQueue(address: Address?, completion: @escaping (Friend?) -> Void) {
|
||||
self.coreContext.doOnCoreQueue { core in
|
||||
completion(self.getFriendWithAddress(address: address))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,6 +66,8 @@ final class CoreContext: ObservableObject {
|
|||
coreQueue.async {
|
||||
if self.mCore.globalState != .Off {
|
||||
lambda(self.mCore)
|
||||
} else {
|
||||
Log.warn("Doesn't run the asynchronous function because the core is off")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -344,16 +344,14 @@ class TelecomManager: ObservableObject {
|
|||
func incomingDisplayName(call: Call, completion: @escaping (String) -> Void) {
|
||||
CoreContext.shared.doOnCoreQueue { core in
|
||||
if call.remoteAddress != nil {
|
||||
ContactsManager.shared.getFriendWithAddress(address: call.remoteAddress!) { friendResult in
|
||||
let friend = friendResult
|
||||
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
|
||||
completion(friend!.address!.displayName!)
|
||||
} else {
|
||||
if call.remoteAddress!.displayName != nil {
|
||||
completion(call.remoteAddress!.displayName!)
|
||||
} else if call.remoteAddress!.username != nil {
|
||||
completion(call.remoteAddress!.username!)
|
||||
}
|
||||
let friend = ContactsManager.shared.getFriendWithAddress(address: call.remoteAddress!)
|
||||
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
|
||||
completion(friend!.address!.displayName!)
|
||||
} else {
|
||||
if call.remoteAddress!.displayName != nil {
|
||||
completion(call.remoteAddress!.displayName!)
|
||||
} else if call.remoteAddress!.username != nil {
|
||||
completion(call.remoteAddress!.username!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -469,16 +467,14 @@ class TelecomManager: ObservableObject {
|
|||
if isRecordingByRemoteTmp && ToastViewModel.shared.toastMessage.isEmpty {
|
||||
|
||||
var displayName = ""
|
||||
ContactsManager.shared.getFriendWithAddress(address: call.remoteAddress!) { friendResult in
|
||||
let friend = friendResult
|
||||
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
|
||||
displayName = friend!.address!.displayName!
|
||||
} else {
|
||||
if call.remoteAddress!.displayName != nil {
|
||||
displayName = call.remoteAddress!.displayName!
|
||||
} else if call.remoteAddress!.username != nil {
|
||||
displayName = call.remoteAddress!.username!
|
||||
}
|
||||
let friend = ContactsManager.shared.getFriendWithAddress(address: call.remoteAddress!)
|
||||
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
|
||||
displayName = friend!.address!.displayName!
|
||||
} else {
|
||||
if call.remoteAddress!.displayName != nil {
|
||||
displayName = call.remoteAddress!.displayName!
|
||||
} else if call.remoteAddress!.username != nil {
|
||||
displayName = call.remoteAddress!.username!
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class ParticipantModel: ObservableObject {
|
|||
self.isAdmin = isAdmin
|
||||
self.isSpeaking = isSpeaking
|
||||
|
||||
ContactsManager.shared.getFriendWithAddress(address: self.address) { friendResult in
|
||||
ContactsManager.shared.getFriendWithAddressInCoreQueue(address: self.address) { friendResult in
|
||||
if let addressFriend = friendResult {
|
||||
self.name = addressFriend.name!
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -138,21 +138,19 @@ class CallViewModel: ObservableObject {
|
|||
if self.currentCall?.conference != nil {
|
||||
displayNameTmp = self.currentCall?.conference?.subject ?? ""
|
||||
} else if self.currentCall?.remoteAddress != nil {
|
||||
ContactsManager.shared.getFriendWithAddress(address: self.currentCall!.remoteAddress) { friendResult in
|
||||
let friend = friendResult
|
||||
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
|
||||
displayNameTmp = friend!.address!.displayName!
|
||||
} else {
|
||||
if self.currentCall!.remoteAddress!.displayName != nil {
|
||||
displayNameTmp = self.currentCall!.remoteAddress!.displayName!
|
||||
} else if self.currentCall!.remoteAddress!.username != nil {
|
||||
displayNameTmp = self.currentCall!.remoteAddress!.username!
|
||||
}
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
self.displayName = displayNameTmp
|
||||
let friend = ContactsManager.shared.getFriendWithAddress(address: self.currentCall!.remoteAddress)
|
||||
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
|
||||
displayNameTmp = friend!.address!.displayName!
|
||||
} else {
|
||||
if self.currentCall!.remoteAddress!.displayName != nil {
|
||||
displayNameTmp = self.currentCall!.remoteAddress!.displayName!
|
||||
} else if self.currentCall!.remoteAddress!.username != nil {
|
||||
displayNameTmp = self.currentCall!.remoteAddress!.username!
|
||||
}
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
self.displayName = displayNameTmp
|
||||
}
|
||||
|
||||
ContactAvatarModel.getAvatarModelFromAddress(address: self.currentCall!.remoteAddress!) { avatarResult in
|
||||
DispatchQueue.main.async {
|
||||
|
|
@ -291,16 +289,14 @@ class CallViewModel: ObservableObject {
|
|||
|
||||
var activeSpeakerNameTmp = ""
|
||||
if activeSpeakerParticipantTmp != nil {
|
||||
ContactsManager.shared.getFriendWithAddress(address: activeSpeakerParticipantTmp?.address) { friendResult in
|
||||
let friend = friendResult
|
||||
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
|
||||
activeSpeakerNameTmp = friend!.address!.displayName!
|
||||
} else {
|
||||
if activeSpeakerParticipantTmp!.address.displayName != nil {
|
||||
activeSpeakerNameTmp = activeSpeakerParticipantTmp!.address.displayName!
|
||||
} else if activeSpeakerParticipantTmp!.address.username != nil {
|
||||
activeSpeakerNameTmp = activeSpeakerParticipantTmp!.address.username!
|
||||
}
|
||||
let friend = ContactsManager.shared.getFriendWithAddress(address: activeSpeakerParticipantTmp?.address)
|
||||
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
|
||||
activeSpeakerNameTmp = friend!.address!.displayName!
|
||||
} else {
|
||||
if activeSpeakerParticipantTmp!.address.displayName != nil {
|
||||
activeSpeakerNameTmp = activeSpeakerParticipantTmp!.address.displayName!
|
||||
} else if activeSpeakerParticipantTmp!.address.username != nil {
|
||||
activeSpeakerNameTmp = activeSpeakerParticipantTmp!.address.username!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -367,48 +363,46 @@ class CallViewModel: ObservableObject {
|
|||
isMuted: cbValue.participantDevice.isMuted
|
||||
)
|
||||
|
||||
ContactsManager.shared.getFriendWithAddress(address: activeSpeakerParticipantTmp.address) { friendResult in
|
||||
var activeSpeakerNameTmp = ""
|
||||
let friend = friendResult
|
||||
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
|
||||
activeSpeakerNameTmp = friend!.address!.displayName!
|
||||
} else {
|
||||
if activeSpeakerParticipantTmp.address.displayName != nil {
|
||||
activeSpeakerNameTmp = activeSpeakerParticipantTmp.address.displayName!
|
||||
} else if activeSpeakerParticipantTmp.address.username != nil {
|
||||
activeSpeakerNameTmp = activeSpeakerParticipantTmp.address.username!
|
||||
}
|
||||
var activeSpeakerNameTmp = ""
|
||||
let friend = ContactsManager.shared.getFriendWithAddress(address: activeSpeakerParticipantTmp.address)
|
||||
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
|
||||
activeSpeakerNameTmp = friend!.address!.displayName!
|
||||
} else {
|
||||
if activeSpeakerParticipantTmp.address.displayName != nil {
|
||||
activeSpeakerNameTmp = activeSpeakerParticipantTmp.address.displayName!
|
||||
} else if activeSpeakerParticipantTmp.address.username != nil {
|
||||
activeSpeakerNameTmp = activeSpeakerParticipantTmp.address.username!
|
||||
}
|
||||
}
|
||||
|
||||
var participantListTmp: [ParticipantModel] = []
|
||||
if (activeSpeakerParticipantBis != nil && !activeSpeakerParticipantBis!.address.equal(address2: activeSpeakerParticipantTmp.address))
|
||||
|| ( activeSpeakerParticipantBis == nil) {
|
||||
|
||||
var participantListTmp: [ParticipantModel] = []
|
||||
if (activeSpeakerParticipantBis != nil && !activeSpeakerParticipantBis!.address.equal(address2: activeSpeakerParticipantTmp.address))
|
||||
|| ( activeSpeakerParticipantBis == nil) {
|
||||
|
||||
cbValue.conference.participantDeviceList.forEach({ participantDevice in
|
||||
if participantDevice.address != nil && !cbValue.conference.isMe(uri: participantDevice.address!.clone()!) {
|
||||
if !cbValue.conference.isMe(uri: participantDevice.address!.clone()!) {
|
||||
let isAdmin = cbValue.conference.participantList.first(where: {$0.address!.equal(address2: participantDevice.address!.clone()!)})?.isAdmin
|
||||
participantListTmp.append(
|
||||
ParticipantModel(
|
||||
address: participantDevice.address!,
|
||||
isJoining: participantDevice.state == .Joining || participantDevice.state == .Alerting,
|
||||
onPause: participantDevice.state == .OnHold,
|
||||
isMuted: participantDevice.isMuted,
|
||||
isAdmin: isAdmin ?? false
|
||||
)
|
||||
cbValue.conference.participantDeviceList.forEach({ participantDevice in
|
||||
if participantDevice.address != nil && !cbValue.conference.isMe(uri: participantDevice.address!.clone()!) {
|
||||
if !cbValue.conference.isMe(uri: participantDevice.address!.clone()!) {
|
||||
let isAdmin = cbValue.conference.participantList.first(where: {$0.address!.equal(address2: participantDevice.address!.clone()!)})?.isAdmin
|
||||
participantListTmp.append(
|
||||
ParticipantModel(
|
||||
address: participantDevice.address!,
|
||||
isJoining: participantDevice.state == .Joining || participantDevice.state == .Alerting,
|
||||
onPause: participantDevice.state == .OnHold,
|
||||
isMuted: participantDevice.isMuted,
|
||||
isAdmin: isAdmin ?? false
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.activeSpeakerParticipant = activeSpeakerParticipantTmp
|
||||
self.activeSpeakerName = activeSpeakerNameTmp
|
||||
if (activeSpeakerParticipantBis != nil && !activeSpeakerParticipantBis!.address.equal(address2: activeSpeakerParticipantTmp.address))
|
||||
|| ( activeSpeakerParticipantBis == nil) {
|
||||
self.participantList = participantListTmp
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.activeSpeakerParticipant = activeSpeakerParticipantTmp
|
||||
self.activeSpeakerName = activeSpeakerNameTmp
|
||||
if (activeSpeakerParticipantBis != nil && !activeSpeakerParticipantBis!.address.equal(address2: activeSpeakerParticipantTmp.address))
|
||||
|| ( activeSpeakerParticipantBis == nil) {
|
||||
self.participantList = participantListTmp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -464,21 +458,19 @@ class CallViewModel: ObservableObject {
|
|||
}
|
||||
|
||||
if activeSpeakerParticipantTmp != nil {
|
||||
ContactsManager.shared.getFriendWithAddress(address: activeSpeakerParticipantTmp?.address) { friendResult in
|
||||
let friend = friendResult
|
||||
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
|
||||
activeSpeakerNameTmp = friend!.address!.displayName!
|
||||
} else {
|
||||
if activeSpeakerParticipantTmp!.address.displayName != nil {
|
||||
activeSpeakerNameTmp = activeSpeakerParticipantTmp!.address.displayName!
|
||||
} else if activeSpeakerParticipantTmp!.address.username != nil {
|
||||
activeSpeakerNameTmp = activeSpeakerParticipantTmp!.address.username!
|
||||
}
|
||||
let friend = ContactsManager.shared.getFriendWithAddress(address: activeSpeakerParticipantTmp?.address)
|
||||
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
|
||||
activeSpeakerNameTmp = friend!.address!.displayName!
|
||||
} else {
|
||||
if activeSpeakerParticipantTmp!.address.displayName != nil {
|
||||
activeSpeakerNameTmp = activeSpeakerParticipantTmp!.address.displayName!
|
||||
} else if activeSpeakerParticipantTmp!.address.username != nil {
|
||||
activeSpeakerNameTmp = activeSpeakerParticipantTmp!.address.username!
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
if self.activeSpeakerParticipant == nil {
|
||||
self.activeSpeakerName = activeSpeakerNameTmp
|
||||
}
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
if self.activeSpeakerParticipant == nil {
|
||||
self.activeSpeakerName = activeSpeakerNameTmp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,68 +64,66 @@ class MeetingWaitingRoomViewModel: ObservableObject {
|
|||
let confNameTmp = conf?.subject ?? "Conference"
|
||||
var userNameTmp = ""
|
||||
|
||||
ContactsManager.shared.getFriendWithAddress(address: core.defaultAccount?.contactAddress) { friendResult in
|
||||
let friend = core.defaultAccount != nil && core.defaultAccount!.contactAddress != nil
|
||||
? friendResult
|
||||
: nil
|
||||
|
||||
let addressTmp = friend?.address?.asStringUriOnly() ?? ""
|
||||
|
||||
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
|
||||
userNameTmp = friend!.address!.displayName!
|
||||
} else {
|
||||
if core.defaultAccount!.contactAddress!.displayName != nil {
|
||||
userNameTmp = core.defaultAccount!.contactAddress!.displayName!
|
||||
} else if core.defaultAccount!.contactAddress!.username != nil {
|
||||
userNameTmp = core.defaultAccount!.contactAddress!.username!
|
||||
}
|
||||
let friend = core.defaultAccount != nil && core.defaultAccount!.contactAddress != nil
|
||||
? ContactsManager.shared.getFriendWithAddress(address: core.defaultAccount?.contactAddress)
|
||||
: nil
|
||||
|
||||
let addressTmp = friend?.address?.asStringUriOnly() ?? ""
|
||||
|
||||
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
|
||||
userNameTmp = friend!.address!.displayName!
|
||||
} else {
|
||||
if core.defaultAccount!.contactAddress!.displayName != nil {
|
||||
userNameTmp = core.defaultAccount!.contactAddress!.displayName!
|
||||
} else if core.defaultAccount!.contactAddress!.username != nil {
|
||||
userNameTmp = core.defaultAccount!.contactAddress!.username!
|
||||
}
|
||||
}
|
||||
|
||||
let avatarModelTmp = friend != nil
|
||||
? ContactsManager.shared.avatarListModel.first(where: {
|
||||
$0.friend!.name == friend!.name
|
||||
&& $0.friend!.address!.asStringUriOnly() == core.defaultAccount!.contactAddress!.asStringUriOnly()
|
||||
}) ?? ContactAvatarModel(friend: nil, name: userNameTmp, address: addressTmp, withPresence: false)
|
||||
: ContactAvatarModel(friend: nil, name: userNameTmp, address: addressTmp, withPresence: false)
|
||||
|
||||
if core.videoEnabled && !core.videoPreviewEnabled {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||
core.videoPreviewEnabled = true
|
||||
self.videoDisplayed = true
|
||||
}
|
||||
}
|
||||
|
||||
core.micEnabled = true
|
||||
|
||||
let micMuttedTmp = !core.micEnabled
|
||||
|
||||
let timeInterval = TimeInterval(conf!.dateTime)
|
||||
let date = Date(timeIntervalSince1970: timeInterval)
|
||||
let dateFormatter = DateFormatter()
|
||||
dateFormatter.dateStyle = .full
|
||||
dateFormatter.timeStyle = .none
|
||||
let dateTmp = dateFormatter.string(from: date)
|
||||
|
||||
let timeFormatter = DateFormatter()
|
||||
timeFormatter.dateFormat = Locale.current.identifier == "fr_FR" ? "HH:mm" : "h:mm a"
|
||||
let timeTmp = timeFormatter.string(from: date)
|
||||
|
||||
let timeBisInterval = TimeInterval(conf!.dateTime + (Int(conf!.duration) * 60))
|
||||
let timeBis = Date(timeIntervalSince1970: timeBisInterval)
|
||||
let timeBisTmp = timeFormatter.string(from: timeBis)
|
||||
|
||||
let meetingDateTmp = "\(dateTmp) | \(timeTmp) - \(timeBisTmp)"
|
||||
|
||||
DispatchQueue.main.async {
|
||||
if self.telecomManager.meetingWaitingRoomName.isEmpty || self.telecomManager.meetingWaitingRoomName != confNameTmp {
|
||||
self.telecomManager.meetingWaitingRoomName = confNameTmp
|
||||
}
|
||||
|
||||
let avatarModelTmp = friend != nil
|
||||
? ContactsManager.shared.avatarListModel.first(where: {
|
||||
$0.friend!.name == friend!.name
|
||||
&& $0.friend!.address!.asStringUriOnly() == core.defaultAccount!.contactAddress!.asStringUriOnly()
|
||||
}) ?? ContactAvatarModel(friend: nil, name: userNameTmp, address: addressTmp, withPresence: false)
|
||||
: ContactAvatarModel(friend: nil, name: userNameTmp, address: addressTmp, withPresence: false)
|
||||
|
||||
if core.videoEnabled && !core.videoPreviewEnabled {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||
core.videoPreviewEnabled = true
|
||||
self.videoDisplayed = true
|
||||
}
|
||||
}
|
||||
|
||||
core.micEnabled = true
|
||||
|
||||
let micMuttedTmp = !core.micEnabled
|
||||
|
||||
let timeInterval = TimeInterval(conf!.dateTime)
|
||||
let date = Date(timeIntervalSince1970: timeInterval)
|
||||
let dateFormatter = DateFormatter()
|
||||
dateFormatter.dateStyle = .full
|
||||
dateFormatter.timeStyle = .none
|
||||
let dateTmp = dateFormatter.string(from: date)
|
||||
|
||||
let timeFormatter = DateFormatter()
|
||||
timeFormatter.dateFormat = Locale.current.identifier == "fr_FR" ? "HH:mm" : "h:mm a"
|
||||
let timeTmp = timeFormatter.string(from: date)
|
||||
|
||||
let timeBisInterval = TimeInterval(conf!.dateTime + (Int(conf!.duration) * 60))
|
||||
let timeBis = Date(timeIntervalSince1970: timeBisInterval)
|
||||
let timeBisTmp = timeFormatter.string(from: timeBis)
|
||||
|
||||
let meetingDateTmp = "\(dateTmp) | \(timeTmp) - \(timeBisTmp)"
|
||||
|
||||
DispatchQueue.main.async {
|
||||
if self.telecomManager.meetingWaitingRoomName.isEmpty || self.telecomManager.meetingWaitingRoomName != confNameTmp {
|
||||
self.telecomManager.meetingWaitingRoomName = confNameTmp
|
||||
}
|
||||
|
||||
self.userName = userNameTmp
|
||||
self.avatarModel = avatarModelTmp
|
||||
self.micMutted = micMuttedTmp
|
||||
self.meetingDate = meetingDateTmp
|
||||
}
|
||||
self.userName = userNameTmp
|
||||
self.avatarModel = avatarModelTmp
|
||||
self.micMutted = micMuttedTmp
|
||||
self.meetingDate = meetingDateTmp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ class ContactAvatarModel: ObservableObject {
|
|||
|
||||
|
||||
static func getAvatarModelFromAddress(address: Address, completion: @escaping (ContactAvatarModel) -> Void) {
|
||||
ContactsManager.shared.getFriendWithAddress(address: address) { resultFriend in
|
||||
ContactsManager.shared.getFriendWithAddressInCoreQueue(address: address) { resultFriend in
|
||||
if let addressFriend = resultFriend {
|
||||
if addressFriend.address != nil {
|
||||
var avatarModel = ContactsManager.shared.avatarListModel.first(where: {
|
||||
|
|
|
|||
|
|
@ -141,42 +141,40 @@ class ConversationModel: ObservableObject {
|
|||
coreContext.doOnCoreQueue { _ in
|
||||
let lastMessage = self.chatRoom.lastMessageInHistory
|
||||
if lastMessage != nil {
|
||||
self.contactsManager.getFriendWithAddress(address: lastMessage!.fromAddress) { friendResult in
|
||||
var fromAddressFriend = lastMessage!.fromAddress != nil
|
||||
? friendResult?.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 = ""
|
||||
}
|
||||
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! += ": "
|
||||
fromAddressFriend = ""
|
||||
}
|
||||
|
||||
} else {
|
||||
fromAddressFriend = nil
|
||||
fromAddressFriend! += ": "
|
||||
}
|
||||
|
||||
let lastMessageTextTmp = (fromAddressFriend ?? "")
|
||||
+ (lastMessage!.contents.first(where: {$0.isText == true})?.utf8Text ?? (lastMessage!.contents.first(where: {$0.isFile == true || $0.isFileTransfer == true})?.name ?? ""))
|
||||
} 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 lastMessageIsOutgoingTmp = lastMessage?.isOutgoing ?? false
|
||||
|
||||
let lastMessageStateTmp = lastMessage?.state.rawValue ?? 0
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.lastMessageText = lastMessageTextTmp
|
||||
|
||||
let lastMessageIsOutgoingTmp = lastMessage?.isOutgoing ?? false
|
||||
self.lastMessageIsOutgoing = lastMessageIsOutgoingTmp
|
||||
|
||||
let lastMessageStateTmp = lastMessage?.state.rawValue ?? 0
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.lastMessageText = lastMessageTextTmp
|
||||
|
||||
self.lastMessageIsOutgoing = lastMessageIsOutgoingTmp
|
||||
|
||||
self.lastMessageState = lastMessageStateTmp
|
||||
}
|
||||
self.lastMessageState = lastMessageStateTmp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -184,51 +182,48 @@ class ConversationModel: ObservableObject {
|
|||
|
||||
func getChatRoomSubject() {
|
||||
coreContext.doOnCoreQueue { _ in
|
||||
self.contactsManager.getFriendWithAddress(address: self.chatRoom.participants.first?.address) { friendResult in
|
||||
let addressFriend =
|
||||
(self.chatRoom.participants.first != nil && self.chatRoom.participants.first!.address != nil)
|
||||
? friendResult
|
||||
: nil
|
||||
|
||||
if self.isGroup {
|
||||
self.subject = self.chatRoom.subject!
|
||||
} else if addressFriend != nil {
|
||||
self.subject = addressFriend!.name!
|
||||
} else {
|
||||
if self.chatRoom.participants.first != nil
|
||||
&& self.chatRoom.participants.first!.address != nil {
|
||||
|
||||
self.subject = self.chatRoom.participants.first!.address!.displayName != nil
|
||||
? self.chatRoom.participants.first!.address!.displayName!
|
||||
: self.chatRoom.participants.first!.address!.username!
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
let addressTmp = addressFriend?.address?.asStringUriOnly() ?? ""
|
||||
|
||||
let avatarModelTmp = addressFriend != nil && !self.isGroup
|
||||
? ContactsManager.shared.avatarListModel.first(where: {
|
||||
$0.friend!.name == addressFriend!.name
|
||||
&& $0.friend!.address!.asStringUriOnly() == addressFriend!.address!.asStringUriOnly()
|
||||
})
|
||||
?? ContactAvatarModel(
|
||||
friend: nil,
|
||||
name: self.subject,
|
||||
address: addressTmp,
|
||||
withPresence: false
|
||||
)
|
||||
: ContactAvatarModel(
|
||||
friend: nil,
|
||||
name: self.subject,
|
||||
address: addressTmp,
|
||||
withPresence: false
|
||||
)
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.avatarModel = avatarModelTmp
|
||||
let addressFriend = (self.chatRoom.participants.first != nil && self.chatRoom.participants.first!.address != nil)
|
||||
? self.contactsManager.getFriendWithAddress(address: self.chatRoom.participants.first?.address)
|
||||
: nil
|
||||
|
||||
if self.isGroup {
|
||||
self.subject = self.chatRoom.subject!
|
||||
} else if addressFriend != nil {
|
||||
self.subject = addressFriend!.name!
|
||||
} else {
|
||||
if self.chatRoom.participants.first != nil
|
||||
&& self.chatRoom.participants.first!.address != nil {
|
||||
|
||||
self.subject = self.chatRoom.participants.first!.address!.displayName != nil
|
||||
? self.chatRoom.participants.first!.address!.displayName!
|
||||
: self.chatRoom.participants.first!.address!.username!
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
let addressTmp = addressFriend?.address?.asStringUriOnly() ?? ""
|
||||
|
||||
let avatarModelTmp = addressFriend != nil && !self.isGroup
|
||||
? ContactsManager.shared.avatarListModel.first(where: {
|
||||
$0.friend!.name == addressFriend!.name
|
||||
&& $0.friend!.address!.asStringUriOnly() == addressFriend!.address!.asStringUriOnly()
|
||||
})
|
||||
?? ContactAvatarModel(
|
||||
friend: nil,
|
||||
name: self.subject,
|
||||
address: addressTmp,
|
||||
withPresence: false
|
||||
)
|
||||
: ContactAvatarModel(
|
||||
friend: nil,
|
||||
name: self.subject,
|
||||
address: addressTmp,
|
||||
withPresence: false
|
||||
)
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.avatarModel = avatarModelTmp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ class ConversationsListViewModel: ObservableObject {
|
|||
}
|
||||
|
||||
func getContentTextMessage(message: ChatMessage, completion: @escaping (String) -> Void) {
|
||||
contactsManager.getFriendWithAddress(address: message.fromAddress) { friendResult in
|
||||
contactsManager.getFriendWithAddressInCoreQueue(address: message.fromAddress) { friendResult in
|
||||
var fromAddressFriend = message.fromAddress != nil
|
||||
? friendResult?.name ?? nil
|
||||
: nil
|
||||
|
|
|
|||
|
|
@ -71,29 +71,27 @@ class HistoryModel: ObservableObject {
|
|||
|
||||
func refreshAvatarModel() {
|
||||
coreContext.doOnCoreQueue { _ in
|
||||
ContactsManager.shared.getFriendWithAddress(address: self.callLog.dir == .Outgoing ? self.callLog.toAddress! : self.callLog.fromAddress!) { friendResult in
|
||||
let addressFriendTmp = friendResult
|
||||
if addressFriendTmp != nil {
|
||||
let addressFriendTmp = ContactsManager.shared.getFriendWithAddress(address: self.callLog.dir == .Outgoing ? self.callLog.toAddress! : self.callLog.fromAddress!)
|
||||
if addressFriendTmp != nil {
|
||||
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()
|
||||
}) ?? 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
|
||||
|
||||
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()
|
||||
}) ?? 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.avatarModel = avatarModelTmp
|
||||
}
|
||||
} else {
|
||||
DispatchQueue.main.async {
|
||||
self.avatarModel = ContactAvatarModel(friend: nil, name: self.addressName, address: self.address, withPresence: false)
|
||||
}
|
||||
self.addressName = addressFriendTmp!.name ?? addressNameTmp
|
||||
self.avatarModel = avatarModelTmp
|
||||
}
|
||||
} else {
|
||||
DispatchQueue.main.async {
|
||||
self.avatarModel = ContactAvatarModel(friend: nil, name: self.addressName, address: self.address, withPresence: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue