diff --git a/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift b/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift index c7dd24d4b..71d7d59bf 100644 --- a/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift +++ b/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift @@ -35,11 +35,11 @@ struct ChatBubbleView: View { Spacer() } - VStack { + VStack(alignment: message.isOutgoing ? .trailing : .leading) { if !message.attachments.isEmpty { if message.attachments.count == 1 { + let result = imageDimensions(url: message.attachments.first!.full.absoluteString) if message.attachments.first!.type == .image || message.attachments.first!.type == .gif { - let result = imageDimensions(url: message.attachments.first!.full.absoluteString) if message.attachments.first!.type != .gif { AsyncImage(url: message.attachments.first!.full) { image in image.resizable() @@ -96,8 +96,8 @@ struct ChatBubbleView: View { if !message.text.isEmpty { Text(message.text) - .foregroundStyle(Color.grayMain2c700) - .default_text_style(styleSize: 16) + .foregroundStyle(Color.grayMain2c700) + .default_text_style(styleSize: 16) } } .padding(.all, 15) @@ -126,17 +126,17 @@ struct ChatBubbleView: View { } enum URLType { - case name(String) // local file name of gif - case url(URL) // remote url - - var url: URL? { - switch self { - case .name(let name): - return Bundle.main.url(forResource: name, withExtension: "gif") - case .url(let remoteURL): - return remoteURL + case name(String) // local file name of gif + case url(URL) // remote url + + var url: URL? { + switch self { + case .name(let name): + return Bundle.main.url(forResource: name, withExtension: "gif") + case .url(let remoteURL): + return remoteURL + } } - } } struct GifImageView: UIViewRepresentable { diff --git a/Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift b/Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift index c95ecddde..79ac61416 100644 --- a/Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift +++ b/Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift @@ -217,23 +217,26 @@ struct ConversationFragment: View { conversationViewModel.resetMessage() } } else { - /* ScrollViewReader { proxy in List { ForEach(0.. conversationViewModel.conversationMessagesList.count { - //DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { - conversationViewModel.getOldMessages() - //} - } - } + if index < conversationViewModel.conversationMessagesSection.first!.rows.count { + ChatBubbleView(conversationViewModel: conversationViewModel, message: conversationViewModel.conversationMessagesSection.first!.rows[index], geometryProxy: geometry) + .id(conversationViewModel.conversationMessagesList[index]) + .listRowInsets(EdgeInsets(top: 2, leading: 10, bottom: 2, trailing: 10)) + .listRowSeparator(.hidden) + .scaleEffect(x: 1, y: -1, anchor: .center) + .onAppear { + if index == conversationViewModel.conversationMessagesList.count - 1 && conversationViewModel.displayedConversationHistorySize > conversationViewModel.conversationMessagesList.count { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { + conversationViewModel.getOldMessages() + } + } + } + } } } + .scaleEffect(x: 1, y: -1, anchor: .center) .listStyle(.plain) .onTapGesture { UIApplication.shared.endEditing() @@ -242,23 +245,26 @@ struct ConversationFragment: View { conversationViewModel.getMessages() } .onChange(of: conversationViewModel.conversationMessagesList) { _ in - if conversationViewModel.conversationMessagesList.count <= 30 { - proxy.scrollTo( - conversationViewModel.conversationMessagesList.last, anchor: .top - ) - } else if conversationViewModel.conversationMessagesList.count >= conversationViewModel.displayedConversationHistorySize { - proxy.scrollTo( - conversationViewModel.conversationMessagesList[conversationViewModel.displayedConversationHistorySize%30], anchor: .top - ) - } else { - proxy.scrollTo(30, anchor: .top) + /* + DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { + if conversationViewModel.conversationMessagesList.count <= 30 { + proxy.scrollTo( + conversationViewModel.conversationMessagesList.first, anchor: .top + ) + } else if conversationViewModel.conversationMessagesList.count >= conversationViewModel.displayedConversationHistorySize { + proxy.scrollTo( + conversationViewModel.conversationMessagesList[conversationViewModel.displayedConversationHistorySize%30], anchor: .top + ) + } else { + proxy.scrollTo(30, anchor: .top) + } } + */ } .onDisappear { conversationViewModel.resetMessage() } } - */ } HStack(spacing: 0) { diff --git a/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift b/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift index 059cb9d10..84eb57807 100644 --- a/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift +++ b/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift @@ -116,8 +116,10 @@ class ConversationViewModel: ObservableObject { if content.filePath == nil || content.filePath!.isEmpty { self.downloadContent(chatMessage: eventLog.chatMessage!, content: content) } else { - let attachment = Attachment(id: UUID().uuidString, url: URL(string: self.getNewFilePath(name: content.name ?? ""))!, type: (content.name?.lowercased().hasSuffix("gif"))! ? .gif : .image) - attachmentList.append(attachment) + if URL(string: self.getNewFilePath(name: content.name ?? "")) != nil { + let attachment = Attachment(id: UUID().uuidString, url: URL(string: self.getNewFilePath(name: content.name ?? ""))!, type: (content.name?.lowercased().hasSuffix("gif"))! ? .gif : .image) + attachmentList.append(attachment) + } } } }