This commit is contained in:
fmodf 2024-08-18 18:42:59 +02:00
parent 2890a6cd6d
commit bdcc984386
11 changed files with 29 additions and 36 deletions

View file

@ -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)
}

View file

@ -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 {

View file

@ -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 {

View file

@ -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()
}
}

View file

@ -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: {

View file

@ -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()
}
}

View file

@ -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 {

View file

@ -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] = []

View file

@ -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
}
}

View file

@ -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)
}
}

View file

@ -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