mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-29 17:29:20 +00:00
Fix crash when sending a message and crash in conversation list
This commit is contained in:
parent
e870b74758
commit
885c14ef9c
2 changed files with 119 additions and 117 deletions
|
|
@ -32,129 +32,131 @@ struct ConversationsListFragment: View {
|
|||
VStack {
|
||||
List {
|
||||
ForEach(0..<conversationsListViewModel.conversationsList.count, id: \.self) { index in
|
||||
HStack {
|
||||
Avatar(contactAvatarModel: conversationsListViewModel.conversationsList[index].avatarModel, avatarSize: 50)
|
||||
|
||||
VStack(spacing: 0) {
|
||||
Spacer()
|
||||
if index < conversationsListViewModel.conversationsList.count {
|
||||
HStack {
|
||||
Avatar(contactAvatarModel: conversationsListViewModel.conversationsList[index].avatarModel, avatarSize: 50)
|
||||
|
||||
Text(conversationsListViewModel.conversationsList[index].subject)
|
||||
.foregroundStyle(Color.grayMain2c800)
|
||||
.if(conversationsListViewModel.conversationsList[index].unreadMessagesCount > 0) { view in
|
||||
view.default_text_style_700(styleSize: 14)
|
||||
}
|
||||
.default_text_style(styleSize: 14)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(1)
|
||||
|
||||
Text(conversationsListViewModel.conversationsList[index].lastMessageText)
|
||||
.foregroundStyle(Color.grayMain2c400)
|
||||
.if(conversationsListViewModel.conversationsList[index].unreadMessagesCount > 0) { view in
|
||||
view.default_text_style_700(styleSize: 14)
|
||||
}
|
||||
.default_text_style(styleSize: 14)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(1)
|
||||
|
||||
Spacer()
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
VStack(alignment: .trailing, spacing: 0) {
|
||||
Spacer()
|
||||
|
||||
HStack {
|
||||
if !conversationsListViewModel.conversationsList[index].encryptionEnabled {
|
||||
Image("warning-circle")
|
||||
.renderingMode(.template)
|
||||
.resizable()
|
||||
.foregroundStyle(Color.redDanger500)
|
||||
.frame(width: 18, height: 18, alignment: .trailing)
|
||||
}
|
||||
VStack(spacing: 0) {
|
||||
Spacer()
|
||||
|
||||
Text(conversationsListViewModel.getCallTime(startDate: conversationsListViewModel.conversationsList[index].lastUpdateTime))
|
||||
.foregroundStyle(Color.grayMain2c400)
|
||||
.default_text_style(styleSize: 14)
|
||||
.lineLimit(1)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
HStack {
|
||||
if conversationsListViewModel.conversationsList[index].isMuted == false
|
||||
&& !(!conversationsListViewModel.conversationsList[index].lastMessageText.isEmpty
|
||||
&& conversationsListViewModel.conversationsList[index].lastMessageIsOutgoing == true)
|
||||
&& conversationsListViewModel.conversationsList[index].unreadMessagesCount == 0 {
|
||||
Text("")
|
||||
.frame(width: 18, height: 18, alignment: .trailing)
|
||||
}
|
||||
|
||||
if conversationsListViewModel.conversationsList[index].isMuted {
|
||||
Image("bell-slash")
|
||||
.renderingMode(.template)
|
||||
.resizable()
|
||||
.foregroundStyle(Color.orangeMain500)
|
||||
.frame(width: 18, height: 18, alignment: .trailing)
|
||||
}
|
||||
|
||||
if !conversationsListViewModel.conversationsList[index].lastMessageText.isEmpty
|
||||
&& conversationsListViewModel.conversationsList[index].lastMessageIsOutgoing == true {
|
||||
let imageName = LinphoneUtils.getChatIconState(chatState: conversationsListViewModel.conversationsList[index].lastMessageState)
|
||||
Image(imageName)
|
||||
.renderingMode(.template)
|
||||
.resizable()
|
||||
.foregroundStyle(Color.orangeMain500)
|
||||
.frame(width: 18, height: 18, alignment: .trailing)
|
||||
}
|
||||
|
||||
if conversationsListViewModel.conversationsList[index].unreadMessagesCount > 0 {
|
||||
HStack {
|
||||
Text(
|
||||
conversationsListViewModel.conversationsList[index].unreadMessagesCount < 99
|
||||
? String(conversationsListViewModel.conversationsList[index].unreadMessagesCount)
|
||||
: "99+"
|
||||
)
|
||||
.foregroundStyle(.white)
|
||||
.default_text_style(styleSize: 10)
|
||||
.lineLimit(1)
|
||||
Text(conversationsListViewModel.conversationsList[index].subject)
|
||||
.foregroundStyle(Color.grayMain2c800)
|
||||
.if(conversationsListViewModel.conversationsList[index].unreadMessagesCount > 0) { view in
|
||||
view.default_text_style_700(styleSize: 14)
|
||||
}
|
||||
.frame(width: 18, height: 18)
|
||||
.background(Color.redDanger500)
|
||||
.cornerRadius(50)
|
||||
}
|
||||
.default_text_style(styleSize: 14)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(1)
|
||||
|
||||
Text(conversationsListViewModel.conversationsList[index].lastMessageText)
|
||||
.foregroundStyle(Color.grayMain2c400)
|
||||
.if(conversationsListViewModel.conversationsList[index].unreadMessagesCount > 0) { view in
|
||||
view.default_text_style_700(styleSize: 14)
|
||||
}
|
||||
.default_text_style(styleSize: 14)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(1)
|
||||
|
||||
Spacer()
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.padding(.trailing, 10)
|
||||
}
|
||||
.frame(height: 50)
|
||||
.buttonStyle(.borderless)
|
||||
.listRowInsets(EdgeInsets(top: 6, leading: 20, bottom: 6, trailing: 20))
|
||||
.listRowSeparator(.hidden)
|
||||
.background(.white)
|
||||
.onTapGesture {
|
||||
if index < conversationsListViewModel.conversationsList.count {
|
||||
if conversationViewModel.displayedConversation != nil {
|
||||
conversationViewModel.displayedConversation = nil
|
||||
conversationViewModel.selectedMessage = nil
|
||||
conversationViewModel.resetMessage()
|
||||
conversationViewModel.changeDisplayedChatRoom(conversationModel: conversationsListViewModel.conversationsList[index])
|
||||
|
||||
VStack(alignment: .trailing, spacing: 0) {
|
||||
Spacer()
|
||||
|
||||
conversationViewModel.getMessages()
|
||||
} else {
|
||||
conversationViewModel.selectedMessage = nil
|
||||
withAnimation {
|
||||
HStack {
|
||||
if !conversationsListViewModel.conversationsList[index].encryptionEnabled {
|
||||
Image("warning-circle")
|
||||
.renderingMode(.template)
|
||||
.resizable()
|
||||
.foregroundStyle(Color.redDanger500)
|
||||
.frame(width: 18, height: 18, alignment: .trailing)
|
||||
}
|
||||
|
||||
Text(conversationsListViewModel.getCallTime(startDate: conversationsListViewModel.conversationsList[index].lastUpdateTime))
|
||||
.foregroundStyle(Color.grayMain2c400)
|
||||
.default_text_style(styleSize: 14)
|
||||
.lineLimit(1)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
HStack {
|
||||
if conversationsListViewModel.conversationsList[index].isMuted == false
|
||||
&& !(!conversationsListViewModel.conversationsList[index].lastMessageText.isEmpty
|
||||
&& conversationsListViewModel.conversationsList[index].lastMessageIsOutgoing == true)
|
||||
&& conversationsListViewModel.conversationsList[index].unreadMessagesCount == 0 {
|
||||
Text("")
|
||||
.frame(width: 18, height: 18, alignment: .trailing)
|
||||
}
|
||||
|
||||
if conversationsListViewModel.conversationsList[index].isMuted {
|
||||
Image("bell-slash")
|
||||
.renderingMode(.template)
|
||||
.resizable()
|
||||
.foregroundStyle(Color.orangeMain500)
|
||||
.frame(width: 18, height: 18, alignment: .trailing)
|
||||
}
|
||||
|
||||
if !conversationsListViewModel.conversationsList[index].lastMessageText.isEmpty
|
||||
&& conversationsListViewModel.conversationsList[index].lastMessageIsOutgoing == true {
|
||||
let imageName = LinphoneUtils.getChatIconState(chatState: conversationsListViewModel.conversationsList[index].lastMessageState)
|
||||
Image(imageName)
|
||||
.renderingMode(.template)
|
||||
.resizable()
|
||||
.foregroundStyle(Color.orangeMain500)
|
||||
.frame(width: 18, height: 18, alignment: .trailing)
|
||||
}
|
||||
|
||||
if conversationsListViewModel.conversationsList[index].unreadMessagesCount > 0 {
|
||||
HStack {
|
||||
Text(
|
||||
conversationsListViewModel.conversationsList[index].unreadMessagesCount < 99
|
||||
? String(conversationsListViewModel.conversationsList[index].unreadMessagesCount)
|
||||
: "99+"
|
||||
)
|
||||
.foregroundStyle(.white)
|
||||
.default_text_style(styleSize: 10)
|
||||
.lineLimit(1)
|
||||
}
|
||||
.frame(width: 18, height: 18)
|
||||
.background(Color.redDanger500)
|
||||
.cornerRadius(50)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.padding(.trailing, 10)
|
||||
}
|
||||
.frame(height: 50)
|
||||
.buttonStyle(.borderless)
|
||||
.listRowInsets(EdgeInsets(top: 6, leading: 20, bottom: 6, trailing: 20))
|
||||
.listRowSeparator(.hidden)
|
||||
.background(.white)
|
||||
.onTapGesture {
|
||||
if index < conversationsListViewModel.conversationsList.count {
|
||||
if conversationViewModel.displayedConversation != nil {
|
||||
conversationViewModel.displayedConversation = nil
|
||||
conversationViewModel.selectedMessage = nil
|
||||
conversationViewModel.resetMessage()
|
||||
conversationViewModel.changeDisplayedChatRoom(conversationModel: conversationsListViewModel.conversationsList[index])
|
||||
|
||||
conversationViewModel.getMessages()
|
||||
} else {
|
||||
conversationViewModel.selectedMessage = nil
|
||||
withAnimation {
|
||||
conversationViewModel.changeDisplayedChatRoom(conversationModel: conversationsListViewModel.conversationsList[index])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.onLongPressGesture(minimumDuration: 0.2) {
|
||||
if index < conversationsListViewModel.conversationsList.count {
|
||||
conversationsListViewModel.selectedConversation = conversationsListViewModel.conversationsList[index]
|
||||
showingSheet.toggle()
|
||||
.onLongPressGesture(minimumDuration: 0.2) {
|
||||
if index < conversationsListViewModel.conversationsList.count {
|
||||
conversationsListViewModel.selectedConversation = conversationsListViewModel.conversationsList[index]
|
||||
showingSheet.toggle()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ class ConversationViewModel: ObservableObject {
|
|||
case .Displayed:
|
||||
statusTmp = .read
|
||||
default:
|
||||
statusTmp = nil
|
||||
statusTmp = .sending
|
||||
}
|
||||
|
||||
let indexMessage = self.conversationMessagesSection[0].rows.firstIndex(where: {$0.id == message.messageId})
|
||||
|
|
@ -295,7 +295,7 @@ class ConversationViewModel: ObservableObject {
|
|||
case .Displayed:
|
||||
statusTmp = .read
|
||||
default:
|
||||
statusTmp = nil
|
||||
statusTmp = .sending
|
||||
}
|
||||
|
||||
var reactionsTmp: [String] = []
|
||||
|
|
@ -478,7 +478,7 @@ class ConversationViewModel: ObservableObject {
|
|||
case .Displayed:
|
||||
statusTmp = .read
|
||||
default:
|
||||
statusTmp = nil
|
||||
statusTmp = .sending
|
||||
}
|
||||
|
||||
var reactionsTmp: [String] = []
|
||||
|
|
@ -674,7 +674,7 @@ class ConversationViewModel: ObservableObject {
|
|||
case .Displayed:
|
||||
statusTmp = .read
|
||||
default:
|
||||
statusTmp = nil
|
||||
statusTmp = .sending
|
||||
}
|
||||
|
||||
var reactionsTmp: [String] = []
|
||||
|
|
@ -912,7 +912,7 @@ class ConversationViewModel: ObservableObject {
|
|||
case .Displayed:
|
||||
statusTmp = .read
|
||||
default:
|
||||
statusTmp = nil
|
||||
statusTmp = .sending
|
||||
}
|
||||
|
||||
var reactionsTmp: [String] = []
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue