From bdcc984386158d8c0900c4cbe4bd0498588e1447 Mon Sep 17 00:00:00 2001 From: fmodf Date: Sun, 18 Aug 2024 18:42:59 +0200 Subject: [PATCH] wip --- .../AppData/Store/ClientsStore.swift | 8 ++++---- .../View/Main/ChatList/ChatsListScreen.swift | 4 ++-- .../View/Main/Contacts/ContactsScreen.swift | 4 ++-- .../ContactsPicker/ContactsPickerView.swift | 4 ++-- .../FilesPicker/FilesPickerView.swift | 5 +---- .../LocationPicker/LocationPickerView.swift | 6 ++---- .../MediaPicker/CameraCellPreview.swift | 1 - .../MediaPicker/MediaPickerView.swift | 1 - .../Conversation/ConversationMessageRow.swift | 6 +++--- .../Main/Conversation/ConversationScreen.swift | 8 ++++---- .../Conversation/ConversationTextInput.swift | 18 +++++++++--------- 11 files changed, 29 insertions(+), 36 deletions(-) diff --git a/ConversationsClassic/AppData/Store/ClientsStore.swift b/ConversationsClassic/AppData/Store/ClientsStore.swift index 3eaa3d2..ed07fcd 100644 --- a/ConversationsClassic/AppData/Store/ClientsStore.swift +++ b/ConversationsClassic/AppData/Store/ClientsStore.swift @@ -141,7 +141,7 @@ extension ClientsStore { } extension ClientsStore { - func conversationStores(for roster: Roster) async throws -> (ConversationStore, AttachmentsStore) { + func conversationStores(for roster: Roster) async throws -> (MessagesStore, AttachmentsStore) { while !ready { await Task.yield() } @@ -150,12 +150,12 @@ extension ClientsStore { throw AppError.clientNotFound } - let conversationStore = ConversationStore(roster: roster, client: client) + let conversationStore = MessagesStore(roster: roster, client: client) let attachmentsStore = AttachmentsStore(roster: roster, client: client) return (conversationStore, attachmentsStore) } - func conversationStores(for chat: Chat) async throws -> (ConversationStore, AttachmentsStore) { + func conversationStores(for chat: Chat) async throws -> (MessagesStore, AttachmentsStore) { while !ready { await Task.yield() } @@ -165,7 +165,7 @@ extension ClientsStore { } let roster = try await chat.fetchRoster() - let conversationStore = ConversationStore(roster: roster, client: client) + let conversationStore = MessagesStore(roster: roster, client: client) let attachmentsStore = AttachmentsStore(roster: roster, client: client) return (conversationStore, attachmentsStore) } diff --git a/ConversationsClassic/View/Main/ChatList/ChatsListScreen.swift b/ConversationsClassic/View/Main/ChatList/ChatsListScreen.swift index 8468603..be88ee3 100644 --- a/ConversationsClassic/View/Main/ChatList/ChatsListScreen.swift +++ b/ConversationsClassic/View/Main/ChatList/ChatsListScreen.swift @@ -60,9 +60,9 @@ private struct ChatsRow: View { } do { - let (conversation, attachments) = try await clientsStore.conversationStores(for: chat) + let (messages, attachments) = try await clientsStore.conversationStores(for: chat) router.showScreen(.push) { _ in - ConversationScreen(conversation: conversation, attachments: attachments) + ConversationScreen(messages: messages, attachments: attachments) .navigationBarHidden(true) } } catch { diff --git a/ConversationsClassic/View/Main/Contacts/ContactsScreen.swift b/ConversationsClassic/View/Main/Contacts/ContactsScreen.swift index d145036..474a800 100644 --- a/ConversationsClassic/View/Main/Contacts/ContactsScreen.swift +++ b/ConversationsClassic/View/Main/Contacts/ContactsScreen.swift @@ -158,9 +158,9 @@ private struct ContactsScreenRow: View { } do { - let (conversation, attachments) = try await clientsStore.conversationStores(for: roster) + let (messages, attachments) = try await clientsStore.conversationStores(for: roster) router.showScreen(.push) { _ in - ConversationScreen(conversation: conversation, attachments: attachments) + ConversationScreen(messages: messages, attachments: attachments) .navigationBarHidden(true) } } catch { diff --git a/ConversationsClassic/View/Main/Conversation/Attachments/ContactsPicker/ContactsPickerView.swift b/ConversationsClassic/View/Main/Conversation/Attachments/ContactsPicker/ContactsPickerView.swift index 7246a1c..ddb0fa6 100644 --- a/ConversationsClassic/View/Main/Conversation/Attachments/ContactsPicker/ContactsPickerView.swift +++ b/ConversationsClassic/View/Main/Conversation/Attachments/ContactsPicker/ContactsPickerView.swift @@ -2,7 +2,7 @@ import SwiftUI struct ContactsPickerView: View { @Environment(\.router) var router - @EnvironmentObject var conversation: ConversationStore + @EnvironmentObject var messages: MessagesStore @State private var rosters: [Roster] = [] @State private var selectedContact: Roster? @@ -42,7 +42,7 @@ struct ContactsPickerView: View { .clipped() .onTapGesture { if let selectedContact = selectedContact { - conversation.sendContact(selectedContact.contactBareJid) + messages.sendContact(selectedContact.contactBareJid) router.dismissEnvironment() } } diff --git a/ConversationsClassic/View/Main/Conversation/Attachments/FilesPicker/FilesPickerView.swift b/ConversationsClassic/View/Main/Conversation/Attachments/FilesPicker/FilesPickerView.swift index 2e734b7..01e4959 100644 --- a/ConversationsClassic/View/Main/Conversation/Attachments/FilesPicker/FilesPickerView.swift +++ b/ConversationsClassic/View/Main/Conversation/Attachments/FilesPicker/FilesPickerView.swift @@ -3,15 +3,12 @@ import UIKit struct FilesPickerView: View { @Environment(\.router) var router - @EnvironmentObject var conversation: ConversationStore @EnvironmentObject var attachments: AttachmentsStore var body: some View { DocumentPicker( completion: { dataArray, extensionsArray in - Task { - await attachments.sendDocuments(dataArray, extensionsArray) - } + attachments.sendDocuments(dataArray, extensionsArray) router.dismissEnvironment() }, cancel: { diff --git a/ConversationsClassic/View/Main/Conversation/Attachments/LocationPicker/LocationPickerView.swift b/ConversationsClassic/View/Main/Conversation/Attachments/LocationPicker/LocationPickerView.swift index 92eb472..5b90474 100644 --- a/ConversationsClassic/View/Main/Conversation/Attachments/LocationPicker/LocationPickerView.swift +++ b/ConversationsClassic/View/Main/Conversation/Attachments/LocationPicker/LocationPickerView.swift @@ -3,7 +3,7 @@ import SwiftUI struct LocationPickerView: View { @Environment(\.router) var router - @EnvironmentObject var conversation: ConversationStore + @EnvironmentObject var messages: MessagesStore @StateObject var locationManager = LocationManager() @State private var region = MKCoordinateRegion() @@ -65,9 +65,7 @@ struct LocationPickerView: View { } .clipped() .onTapGesture { - Task { - await conversation.sendLocation(region.center.latitude, region.center.longitude) - } + messages.sendLocation(region.center.latitude, region.center.longitude) router.dismissEnvironment() } } diff --git a/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/CameraCellPreview.swift b/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/CameraCellPreview.swift index f2c2191..a9a3dbe 100644 --- a/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/CameraCellPreview.swift +++ b/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/CameraCellPreview.swift @@ -3,7 +3,6 @@ import SwiftUI struct CameraCellPreview: View { @Environment(\.router) var router - @EnvironmentObject var conversation: ConversationStore @EnvironmentObject var attachments: AttachmentsStore var body: some View { diff --git a/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/MediaPickerView.swift b/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/MediaPickerView.swift index cba4b34..24458e1 100644 --- a/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/MediaPickerView.swift +++ b/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/MediaPickerView.swift @@ -5,7 +5,6 @@ import SwiftUI struct MediaPickerView: View { @Environment(\.router) var router - @EnvironmentObject var conversation: ConversationStore @EnvironmentObject var attachments: AttachmentsStore @State private var selectedItems: [String] = [] diff --git a/ConversationsClassic/View/Main/Conversation/ConversationMessageRow.swift b/ConversationsClassic/View/Main/Conversation/ConversationMessageRow.swift index 5047eaa..57c1586 100644 --- a/ConversationsClassic/View/Main/Conversation/ConversationMessageRow.swift +++ b/ConversationsClassic/View/Main/Conversation/ConversationMessageRow.swift @@ -2,7 +2,7 @@ import Foundation import SwiftUI struct ConversationMessageRow: View { - @EnvironmentObject var conversation: ConversationStore + @EnvironmentObject var messages: MessagesStore let message: Message @State private var offset: CGSize = .zero @@ -50,7 +50,7 @@ struct ConversationMessageRow: View { } if value.translation.width <= targetWidth { DispatchQueue.main.asyncAfter(deadline: .now() + 0.02) { - conversation.replyText = message.body ?? "" + messages.replyText = message.body ?? "" } } } @@ -63,7 +63,7 @@ struct ConversationMessageRow: View { } private func isOutgoing() -> Bool { - message.from == conversation.roster.bareJid + message.from == messages.roster.bareJid } } diff --git a/ConversationsClassic/View/Main/Conversation/ConversationScreen.swift b/ConversationsClassic/View/Main/Conversation/ConversationScreen.swift index 401843d..29d4403 100644 --- a/ConversationsClassic/View/Main/Conversation/ConversationScreen.swift +++ b/ConversationsClassic/View/Main/Conversation/ConversationScreen.swift @@ -5,7 +5,7 @@ import SwiftUI struct ConversationScreen: View { @Environment(\.router) var router - @StateObject var conversation: ConversationStore + @StateObject var messages: MessagesStore @StateObject var attachments: AttachmentsStore @State private var autoScroll = true @@ -31,7 +31,7 @@ struct ConversationScreen: View { ) // Msg list - let messages = conversation.messages + let messages = messages.messages if !messages.isEmpty { ScrollViewReader { proxy in List { @@ -98,11 +98,11 @@ struct ConversationScreen: View { } } } - .environmentObject(conversation) + .environmentObject(messages) .environmentObject(attachments) .safeAreaInset(edge: .bottom, spacing: 0) { ConversationTextInput(autoScroll: $autoScroll) - .environmentObject(conversation) + .environmentObject(messages) .environmentObject(attachments) } } diff --git a/ConversationsClassic/View/Main/Conversation/ConversationTextInput.swift b/ConversationsClassic/View/Main/Conversation/ConversationTextInput.swift index de63dbb..e8691f8 100644 --- a/ConversationsClassic/View/Main/Conversation/ConversationTextInput.swift +++ b/ConversationsClassic/View/Main/Conversation/ConversationTextInput.swift @@ -3,7 +3,7 @@ import UIKit struct ConversationTextInput: View { @Environment(\.router) var router - @EnvironmentObject var conversation: ConversationStore + @EnvironmentObject var messages: MessagesStore @EnvironmentObject var attachments: AttachmentsStore @State private var messageStr = "" @@ -16,10 +16,10 @@ struct ConversationTextInput: View { .foregroundColor(.Material.Shape.separator) .frame(height: 0.5) .padding(.bottom, 8) - if !conversation.replyText.isEmpty { + if !messages.replyText.isEmpty { VStack(spacing: 0) { HStack(alignment: .top) { - Text(conversation.replyText) + Text(messages.replyText) .font(.body3) .foregroundColor(Color.Material.Text.main) .multilineTextAlignment(.leading) @@ -31,7 +31,7 @@ struct ConversationTextInput: View { .foregroundColor(.Material.Elements.active) .padding(.leading, 8) .tappablePadding(.symmetric(8)) { - conversation.replyText = "" + messages.replyText = "" } .padding(8) } @@ -53,7 +53,7 @@ struct ConversationTextInput: View { .tappablePadding(.symmetric(8)) { router.showScreen(.fullScreenCover) { _ in AttachmentPickerScreen() - .environmentObject(conversation) + .environmentObject(messages) .environmentObject(attachments) } } @@ -74,7 +74,7 @@ struct ConversationTextInput: View { .padding(.trailing, 8) .tappablePadding(.symmetric(8)) { if !messageStr.isEmpty { - conversation.sendMessage(composedMessage) + messages.sendMessage(composedMessage) messageStr = "" autoScroll = true } @@ -83,7 +83,7 @@ struct ConversationTextInput: View { } .padding(.bottom, 8) .background(Color.Material.Background.dark) - .onChange(of: conversation.replyText) { new in + .onChange(of: messages.replyText) { new in if !new.isEmpty { isFocused = true } @@ -92,8 +92,8 @@ struct ConversationTextInput: View { private var composedMessage: String { var result = "" - if !conversation.replyText.isEmpty { - result += conversation.replyText + "\n\n" + if !messages.replyText.isEmpty { + result += messages.replyText + "\n\n" } result += messageStr return result