mv-experiment #1

Merged
fmodf merged 88 commits from mv-experiment into develop 2024-09-03 15:13:59 +00:00
11 changed files with 29 additions and 36 deletions
Showing only changes of commit bdcc984386 - Show all commits

View file

@ -141,7 +141,7 @@ extension ClientsStore {
} }
extension ClientsStore { extension ClientsStore {
func conversationStores(for roster: Roster) async throws -> (ConversationStore, AttachmentsStore) { func conversationStores(for roster: Roster) async throws -> (MessagesStore, AttachmentsStore) {
while !ready { while !ready {
await Task.yield() await Task.yield()
} }
@ -150,12 +150,12 @@ extension ClientsStore {
throw AppError.clientNotFound throw AppError.clientNotFound
} }
let conversationStore = ConversationStore(roster: roster, client: client) let conversationStore = MessagesStore(roster: roster, client: client)
let attachmentsStore = AttachmentsStore(roster: roster, client: client) let attachmentsStore = AttachmentsStore(roster: roster, client: client)
return (conversationStore, attachmentsStore) return (conversationStore, attachmentsStore)
} }
func conversationStores(for chat: Chat) async throws -> (ConversationStore, AttachmentsStore) { func conversationStores(for chat: Chat) async throws -> (MessagesStore, AttachmentsStore) {
while !ready { while !ready {
await Task.yield() await Task.yield()
} }
@ -165,7 +165,7 @@ extension ClientsStore {
} }
let roster = try await chat.fetchRoster() 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) let attachmentsStore = AttachmentsStore(roster: roster, client: client)
return (conversationStore, attachmentsStore) return (conversationStore, attachmentsStore)
} }

View file

@ -60,9 +60,9 @@ private struct ChatsRow: View {
} }
do { do {
let (conversation, attachments) = try await clientsStore.conversationStores(for: chat) let (messages, attachments) = try await clientsStore.conversationStores(for: chat)
router.showScreen(.push) { _ in router.showScreen(.push) { _ in
ConversationScreen(conversation: conversation, attachments: attachments) ConversationScreen(messages: messages, attachments: attachments)
.navigationBarHidden(true) .navigationBarHidden(true)
} }
} catch { } catch {

View file

@ -158,9 +158,9 @@ private struct ContactsScreenRow: View {
} }
do { do {
let (conversation, attachments) = try await clientsStore.conversationStores(for: roster) let (messages, attachments) = try await clientsStore.conversationStores(for: roster)
router.showScreen(.push) { _ in router.showScreen(.push) { _ in
ConversationScreen(conversation: conversation, attachments: attachments) ConversationScreen(messages: messages, attachments: attachments)
.navigationBarHidden(true) .navigationBarHidden(true)
} }
} catch { } catch {

View file

@ -2,7 +2,7 @@ import SwiftUI
struct ContactsPickerView: View { struct ContactsPickerView: View {
@Environment(\.router) var router @Environment(\.router) var router
@EnvironmentObject var conversation: ConversationStore @EnvironmentObject var messages: MessagesStore
@State private var rosters: [Roster] = [] @State private var rosters: [Roster] = []
@State private var selectedContact: Roster? @State private var selectedContact: Roster?
@ -42,7 +42,7 @@ struct ContactsPickerView: View {
.clipped() .clipped()
.onTapGesture { .onTapGesture {
if let selectedContact = selectedContact { if let selectedContact = selectedContact {
conversation.sendContact(selectedContact.contactBareJid) messages.sendContact(selectedContact.contactBareJid)
router.dismissEnvironment() router.dismissEnvironment()
} }
} }

View file

@ -3,15 +3,12 @@ import UIKit
struct FilesPickerView: View { struct FilesPickerView: View {
@Environment(\.router) var router @Environment(\.router) var router
@EnvironmentObject var conversation: ConversationStore
@EnvironmentObject var attachments: AttachmentsStore @EnvironmentObject var attachments: AttachmentsStore
var body: some View { var body: some View {
DocumentPicker( DocumentPicker(
completion: { dataArray, extensionsArray in completion: { dataArray, extensionsArray in
Task { attachments.sendDocuments(dataArray, extensionsArray)
await attachments.sendDocuments(dataArray, extensionsArray)
}
router.dismissEnvironment() router.dismissEnvironment()
}, },
cancel: { cancel: {

View file

@ -3,7 +3,7 @@ import SwiftUI
struct LocationPickerView: View { struct LocationPickerView: View {
@Environment(\.router) var router @Environment(\.router) var router
@EnvironmentObject var conversation: ConversationStore @EnvironmentObject var messages: MessagesStore
@StateObject var locationManager = LocationManager() @StateObject var locationManager = LocationManager()
@State private var region = MKCoordinateRegion() @State private var region = MKCoordinateRegion()
@ -65,9 +65,7 @@ struct LocationPickerView: View {
} }
.clipped() .clipped()
.onTapGesture { .onTapGesture {
Task { messages.sendLocation(region.center.latitude, region.center.longitude)
await conversation.sendLocation(region.center.latitude, region.center.longitude)
}
router.dismissEnvironment() router.dismissEnvironment()
} }
} }

View file

@ -3,7 +3,6 @@ import SwiftUI
struct CameraCellPreview: View { struct CameraCellPreview: View {
@Environment(\.router) var router @Environment(\.router) var router
@EnvironmentObject var conversation: ConversationStore
@EnvironmentObject var attachments: AttachmentsStore @EnvironmentObject var attachments: AttachmentsStore
var body: some View { var body: some View {

View file

@ -5,7 +5,6 @@ import SwiftUI
struct MediaPickerView: View { struct MediaPickerView: View {
@Environment(\.router) var router @Environment(\.router) var router
@EnvironmentObject var conversation: ConversationStore
@EnvironmentObject var attachments: AttachmentsStore @EnvironmentObject var attachments: AttachmentsStore
@State private var selectedItems: [String] = [] @State private var selectedItems: [String] = []

View file

@ -2,7 +2,7 @@ import Foundation
import SwiftUI import SwiftUI
struct ConversationMessageRow: View { struct ConversationMessageRow: View {
@EnvironmentObject var conversation: ConversationStore @EnvironmentObject var messages: MessagesStore
let message: Message let message: Message
@State private var offset: CGSize = .zero @State private var offset: CGSize = .zero
@ -50,7 +50,7 @@ struct ConversationMessageRow: View {
} }
if value.translation.width <= targetWidth { if value.translation.width <= targetWidth {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.02) { 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 { 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 { struct ConversationScreen: View {
@Environment(\.router) var router @Environment(\.router) var router
@StateObject var conversation: ConversationStore @StateObject var messages: MessagesStore
@StateObject var attachments: AttachmentsStore @StateObject var attachments: AttachmentsStore
@State private var autoScroll = true @State private var autoScroll = true
@ -31,7 +31,7 @@ struct ConversationScreen: View {
) )
// Msg list // Msg list
let messages = conversation.messages let messages = messages.messages
if !messages.isEmpty { if !messages.isEmpty {
ScrollViewReader { proxy in ScrollViewReader { proxy in
List { List {
@ -98,11 +98,11 @@ struct ConversationScreen: View {
} }
} }
} }
.environmentObject(conversation) .environmentObject(messages)
.environmentObject(attachments) .environmentObject(attachments)
.safeAreaInset(edge: .bottom, spacing: 0) { .safeAreaInset(edge: .bottom, spacing: 0) {
ConversationTextInput(autoScroll: $autoScroll) ConversationTextInput(autoScroll: $autoScroll)
.environmentObject(conversation) .environmentObject(messages)
.environmentObject(attachments) .environmentObject(attachments)
} }
} }

View file

@ -3,7 +3,7 @@ import UIKit
struct ConversationTextInput: View { struct ConversationTextInput: View {
@Environment(\.router) var router @Environment(\.router) var router
@EnvironmentObject var conversation: ConversationStore @EnvironmentObject var messages: MessagesStore
@EnvironmentObject var attachments: AttachmentsStore @EnvironmentObject var attachments: AttachmentsStore
@State private var messageStr = "" @State private var messageStr = ""
@ -16,10 +16,10 @@ struct ConversationTextInput: View {
.foregroundColor(.Material.Shape.separator) .foregroundColor(.Material.Shape.separator)
.frame(height: 0.5) .frame(height: 0.5)
.padding(.bottom, 8) .padding(.bottom, 8)
if !conversation.replyText.isEmpty { if !messages.replyText.isEmpty {
VStack(spacing: 0) { VStack(spacing: 0) {
HStack(alignment: .top) { HStack(alignment: .top) {
Text(conversation.replyText) Text(messages.replyText)
.font(.body3) .font(.body3)
.foregroundColor(Color.Material.Text.main) .foregroundColor(Color.Material.Text.main)
.multilineTextAlignment(.leading) .multilineTextAlignment(.leading)
@ -31,7 +31,7 @@ struct ConversationTextInput: View {
.foregroundColor(.Material.Elements.active) .foregroundColor(.Material.Elements.active)
.padding(.leading, 8) .padding(.leading, 8)
.tappablePadding(.symmetric(8)) { .tappablePadding(.symmetric(8)) {
conversation.replyText = "" messages.replyText = ""
} }
.padding(8) .padding(8)
} }
@ -53,7 +53,7 @@ struct ConversationTextInput: View {
.tappablePadding(.symmetric(8)) { .tappablePadding(.symmetric(8)) {
router.showScreen(.fullScreenCover) { _ in router.showScreen(.fullScreenCover) { _ in
AttachmentPickerScreen() AttachmentPickerScreen()
.environmentObject(conversation) .environmentObject(messages)
.environmentObject(attachments) .environmentObject(attachments)
} }
} }
@ -74,7 +74,7 @@ struct ConversationTextInput: View {
.padding(.trailing, 8) .padding(.trailing, 8)
.tappablePadding(.symmetric(8)) { .tappablePadding(.symmetric(8)) {
if !messageStr.isEmpty { if !messageStr.isEmpty {
conversation.sendMessage(composedMessage) messages.sendMessage(composedMessage)
messageStr = "" messageStr = ""
autoScroll = true autoScroll = true
} }
@ -83,7 +83,7 @@ struct ConversationTextInput: View {
} }
.padding(.bottom, 8) .padding(.bottom, 8)
.background(Color.Material.Background.dark) .background(Color.Material.Background.dark)
.onChange(of: conversation.replyText) { new in .onChange(of: messages.replyText) { new in
if !new.isEmpty { if !new.isEmpty {
isFocused = true isFocused = true
} }
@ -92,8 +92,8 @@ struct ConversationTextInput: View {
private var composedMessage: String { private var composedMessage: String {
var result = "" var result = ""
if !conversation.replyText.isEmpty { if !messages.replyText.isEmpty {
result += conversation.replyText + "\n\n" result += messages.replyText + "\n\n"
} }
result += messageStr result += messageStr
return result return result