mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 02:58:07 +00:00
Fix crash on first load of chatrooms
This commit is contained in:
parent
6eaaf3c9c5
commit
fdfc7b2af9
2 changed files with 17 additions and 20 deletions
|
|
@ -83,13 +83,13 @@ class ConversationModel: ObservableObject, Identifiable {
|
|||
|
||||
self.lastMessageState = 0
|
||||
|
||||
self.unreadMessagesCount = 0
|
||||
self.unreadMessagesCount = chatRoom.unreadMessagesCount
|
||||
|
||||
self.avatarModel = ContactAvatarModel(friend: nil, name: chatRoom.subject ?? "", address: chatRoom.peerAddress?.asStringUriOnly() ?? "", withPresence: false)
|
||||
|
||||
getContentTextMessage()
|
||||
getChatRoomSubject()
|
||||
getUnreadMessagesCount()
|
||||
getContentTextMessage(chatRoom: chatRoom)
|
||||
getChatRoomSubject(chatRoom: chatRoom)
|
||||
//getUnreadMessagesCount()
|
||||
}
|
||||
|
||||
func leave() {
|
||||
|
|
@ -183,8 +183,8 @@ class ConversationModel: ObservableObject, Identifiable {
|
|||
}
|
||||
}
|
||||
|
||||
func getContentTextMessage() {
|
||||
let lastMessage = self.chatRoom.lastMessageInHistory
|
||||
func getContentTextMessage(chatRoom: ChatRoom) {
|
||||
let lastMessage = chatRoom.lastMessageInHistory
|
||||
if lastMessage != nil {
|
||||
var fromAddressFriend = lastMessage!.fromAddress != nil
|
||||
? self.contactsManager.getFriendWithAddress(address: lastMessage!.fromAddress)?.name ?? nil
|
||||
|
|
@ -224,24 +224,25 @@ class ConversationModel: ObservableObject, Identifiable {
|
|||
}
|
||||
}
|
||||
|
||||
func getChatRoomSubject() {
|
||||
let addressFriend = (self.chatRoom.participants.first != nil && self.chatRoom.participants.first!.address != nil)
|
||||
? self.contactsManager.getFriendWithAddress(address: self.chatRoom.participants.first?.address)
|
||||
func getChatRoomSubject(chatRoom: ChatRoom) {
|
||||
let chatRoomParticipants = chatRoom.participants
|
||||
let addressFriend = (chatRoomParticipants.first != nil && chatRoomParticipants.first!.address != nil)
|
||||
? self.contactsManager.getFriendWithAddress(address: chatRoomParticipants.first?.address)
|
||||
: nil
|
||||
|
||||
var subjectTmp = ""
|
||||
|
||||
if self.isGroup {
|
||||
subjectTmp = self.chatRoom.subject!
|
||||
subjectTmp = chatRoom.subject!
|
||||
} else if addressFriend != nil {
|
||||
subjectTmp = addressFriend!.name!
|
||||
} else {
|
||||
if self.chatRoom.participants.first != nil
|
||||
&& self.chatRoom.participants.first!.address != nil {
|
||||
if chatRoomParticipants.first != nil
|
||||
&& chatRoomParticipants.first!.address != nil {
|
||||
|
||||
subjectTmp = self.chatRoom.participants.first!.address!.displayName != nil
|
||||
? self.chatRoom.participants.first!.address!.displayName!
|
||||
: (self.chatRoom.participants.first!.address!.username ?? String(self.chatRoom.participants.first!.address!.asStringUriOnly().dropFirst(4)))
|
||||
subjectTmp = chatRoomParticipants.first!.address!.displayName != nil
|
||||
? chatRoomParticipants.first!.address!.displayName!
|
||||
: (chatRoomParticipants.first!.address!.username ?? String(chatRoomParticipants.first!.address!.asStringUriOnly().dropFirst(4)))
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -267,7 +268,7 @@ class ConversationModel: ObservableObject, Identifiable {
|
|||
avatarModelTmp = ContactAvatarModel(
|
||||
friend: nil,
|
||||
name: subjectTmp,
|
||||
address: self.chatRoom.peerAddress?.asStringUriOnly() ?? addressTmp,
|
||||
address: chatRoom.peerAddress?.asStringUriOnly() ?? addressTmp,
|
||||
withPresence: false
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,10 +57,8 @@ class ConversationsListViewModel: ObservableObject {
|
|||
|
||||
var conversationsTmp: [ConversationModel] = []
|
||||
var count = 0
|
||||
print("ConversationModelInit 0000")
|
||||
chatRooms.forEach { chatRoom in
|
||||
if filter.isEmpty {
|
||||
print("ConversationModelInit 1111")
|
||||
let model = ConversationModel(chatRoom: chatRoom)
|
||||
conversationsTmp.append(model)
|
||||
count += 1
|
||||
|
|
@ -255,8 +253,6 @@ class ConversationsListViewModel: ObservableObject {
|
|||
let chatRoomAccount = chatRoom.account
|
||||
let defaultAccount = LinphoneUtils.getDefaultAccount()
|
||||
|
||||
print("ConversationModelInit 2222")
|
||||
//print("addChatRoomaddChatRoom \(chatRoomAccount?.contactAddress?.asStringUriOnly()) \(defaultAccount?.contactAddress?.asStringUriOnly())")
|
||||
if defaultAccount == nil || chatRoomAccount == nil { //} || chatRoomAccount != defaultAccount {
|
||||
Log.warn(
|
||||
"\(ConversationsListViewModel.TAG) Chat room with identifier \(identifier ?? "Identifier error") was created but not displaying it because it doesn't belong to currently default account"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue