mv-experiment #1
|
@ -4,21 +4,21 @@ import Photos
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
final class FileStore: ObservableObject {
|
final class AttachmentsStore: ObservableObject {
|
||||||
@Published var cameraAccessGranted = false
|
@Published var cameraAccessGranted = false
|
||||||
@Published var galleryAccessGranted = false
|
@Published var galleryAccessGranted = false
|
||||||
@Published var galleryItems: [GalleryItem] = []
|
@Published var galleryItems: [GalleryItem] = []
|
||||||
|
|
||||||
private let client: Client
|
// private let client: Client
|
||||||
private let roster: Roster
|
// private let roster: Roster
|
||||||
|
//
|
||||||
init(roster: Roster, client: Client) {
|
// init(roster: Roster, client: Client) {
|
||||||
self.client = client
|
// self.client = client
|
||||||
self.roster = roster
|
// self.roster = roster
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
extension FileStore {
|
extension AttachmentsStore {
|
||||||
func checkCameraAuthorization() async {
|
func checkCameraAuthorization() async {
|
||||||
let status = AVCaptureDevice.authorizationStatus(for: .video)
|
let status = AVCaptureDevice.authorizationStatus(for: .video)
|
||||||
var isAuthorized = status == .authorized
|
var isAuthorized = status == .authorized
|
|
@ -141,7 +141,7 @@ extension ClientsStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ClientsStore {
|
extension ClientsStore {
|
||||||
func getStores(for roster: Roster) async throws -> (ConversationStore, FileStore) {
|
func conversation(for roster: Roster) async throws -> ConversationStore {
|
||||||
while !ready {
|
while !ready {
|
||||||
await Task.yield()
|
await Task.yield()
|
||||||
}
|
}
|
||||||
|
@ -150,13 +150,10 @@ extension ClientsStore {
|
||||||
throw ClientStoreError.clientNotFound
|
throw ClientStoreError.clientNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
let conversation = ConversationStore(roster: roster, client: client)
|
return ConversationStore(roster: roster, client: client)
|
||||||
let fileStore = FileStore(roster: roster, client: client)
|
|
||||||
|
|
||||||
return (conversation, fileStore)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStores(for chat: Chat) async throws -> (ConversationStore, FileStore) {
|
func conversation(for chat: Chat) async throws -> ConversationStore {
|
||||||
while !ready {
|
while !ready {
|
||||||
await Task.yield()
|
await Task.yield()
|
||||||
}
|
}
|
||||||
|
@ -166,9 +163,6 @@ extension ClientsStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
let roster = try await chat.fetchRoster()
|
let roster = try await chat.fetchRoster()
|
||||||
let conversation = ConversationStore(roster: roster, client: client)
|
return ConversationStore(roster: roster, client: client)
|
||||||
let fileStore = FileStore(roster: roster, client: client)
|
|
||||||
|
|
||||||
return (conversation, fileStore)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,21 @@ extension ConversationStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension ConversationStore {
|
||||||
|
var attachmentsStore: AttachmentsStore {
|
||||||
|
AttachmentsStore()
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendMedia(_ items: [GalleryItem]) async {
|
||||||
|
print("media!", items)
|
||||||
|
// guard !ids.isEmpty else { return }
|
||||||
|
// let items = galleryItems.filter { ids.contains($0.id) }
|
||||||
|
// for item in items {
|
||||||
|
// await client.uploadMedia(item.url)
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private extension ConversationStore {
|
private extension ConversationStore {
|
||||||
func subscribe() {
|
func subscribe() {
|
||||||
messagesCancellable = ValueObservation.tracking(Message
|
messagesCancellable = ValueObservation.tracking(Message
|
||||||
|
|
|
@ -60,9 +60,9 @@ private struct ChatsRow: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let (conversation, fileStore) = try await clientsStore.getStores(for: chat)
|
let conversation = try await clientsStore.conversation(for: chat)
|
||||||
router.showScreen(.push) { _ in
|
router.showScreen(.push) { _ in
|
||||||
ConversationScreen(conversation: conversation, fileStore: fileStore)
|
ConversationScreen(conversation: conversation)
|
||||||
.navigationBarHidden(true)
|
.navigationBarHidden(true)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|
|
@ -158,9 +158,9 @@ private struct ContactsScreenRow: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let (conversation, fileStore) = try await clientsStore.getStores(for: roster)
|
let conversation = try await clientsStore.conversation(for: roster)
|
||||||
router.showScreen(.push) { _ in
|
router.showScreen(.push) { _ in
|
||||||
ConversationScreen(conversation: conversation, fileStore: fileStore)
|
ConversationScreen(conversation: conversation)
|
||||||
.navigationBarHidden(true)
|
.navigationBarHidden(true)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|
|
@ -9,6 +9,7 @@ enum AttachmentTab: Int, CaseIterable {
|
||||||
|
|
||||||
struct AttachmentPickerScreen: View {
|
struct AttachmentPickerScreen: View {
|
||||||
@Environment(\.router) var router
|
@Environment(\.router) var router
|
||||||
|
@StateObject var attachmentsStore: AttachmentsStore
|
||||||
|
|
||||||
@State private var selectedTab: AttachmentTab = .media
|
@State private var selectedTab: AttachmentTab = .media
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ struct AttachmentPickerScreen: View {
|
||||||
switch selectedTab {
|
switch selectedTab {
|
||||||
case .media:
|
case .media:
|
||||||
MediaPickerView()
|
MediaPickerView()
|
||||||
|
.environmentObject(attachmentsStore)
|
||||||
|
|
||||||
case .files:
|
case .files:
|
||||||
Color.blue
|
Color.blue
|
||||||
|
|
|
@ -3,7 +3,7 @@ import SwiftUI
|
||||||
|
|
||||||
struct CameraCellPreview: View {
|
struct CameraCellPreview: View {
|
||||||
@Environment(\.router) var router
|
@Environment(\.router) var router
|
||||||
@EnvironmentObject var store: FileStore
|
@EnvironmentObject var store: AttachmentsStore
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Group {
|
Group {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct GalleryView: View {
|
struct GalleryView: View {
|
||||||
@EnvironmentObject var store: FileStore
|
@EnvironmentObject var store: AttachmentsStore
|
||||||
@Binding var selectedItems: [String]
|
@Binding var selectedItems: [String]
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
|
|
@ -4,6 +4,10 @@ import Photos
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct MediaPickerView: View {
|
struct MediaPickerView: View {
|
||||||
|
@Environment(\.router) var router
|
||||||
|
@EnvironmentObject var conversation: ConversationStore
|
||||||
|
@EnvironmentObject var store: AttachmentsStore
|
||||||
|
|
||||||
@State private var selectedItems: [String] = []
|
@State private var selectedItems: [String] = []
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
@ -40,8 +44,11 @@ struct MediaPickerView: View {
|
||||||
}
|
}
|
||||||
.clipped()
|
.clipped()
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
// store.dispatch(.sharingAction(.shareMedia(ids: selectedItems)))
|
Task {
|
||||||
// store.dispatch(.sharingAction(.showSharing(false)))
|
let items = store.galleryItems.filter { selectedItems.contains($0.id) }
|
||||||
|
await conversation.sendMedia(items)
|
||||||
|
}
|
||||||
|
router.dismissEnvironment()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import SwiftUI
|
||||||
struct ConversationScreen: View {
|
struct ConversationScreen: View {
|
||||||
@Environment(\.router) var router
|
@Environment(\.router) var router
|
||||||
@StateObject var conversation: ConversationStore
|
@StateObject var conversation: ConversationStore
|
||||||
@StateObject var fileStore: FileStore
|
|
||||||
|
|
||||||
@State private var autoScroll = true
|
@State private var autoScroll = true
|
||||||
@State private var firstIsVisible = true
|
@State private var firstIsVisible = true
|
||||||
|
@ -102,7 +101,6 @@ struct ConversationScreen: View {
|
||||||
.safeAreaInset(edge: .bottom, spacing: 0) {
|
.safeAreaInset(edge: .bottom, spacing: 0) {
|
||||||
ConversationTextInput(autoScroll: $autoScroll)
|
ConversationTextInput(autoScroll: $autoScroll)
|
||||||
.environmentObject(conversation)
|
.environmentObject(conversation)
|
||||||
.environmentObject(fileStore)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import UIKit
|
||||||
struct ConversationTextInput: View {
|
struct ConversationTextInput: View {
|
||||||
@Environment(\.router) var router
|
@Environment(\.router) var router
|
||||||
@EnvironmentObject var conversation: ConversationStore
|
@EnvironmentObject var conversation: ConversationStore
|
||||||
@EnvironmentObject var fileStore: FileStore
|
|
||||||
|
|
||||||
@State private var messageStr = ""
|
@State private var messageStr = ""
|
||||||
@FocusState private var isFocused: Bool
|
@FocusState private var isFocused: Bool
|
||||||
|
@ -52,9 +51,8 @@ struct ConversationTextInput: View {
|
||||||
.padding(.leading, 8)
|
.padding(.leading, 8)
|
||||||
.tappablePadding(.symmetric(8)) {
|
.tappablePadding(.symmetric(8)) {
|
||||||
router.showScreen(.fullScreenCover) { _ in
|
router.showScreen(.fullScreenCover) { _ in
|
||||||
AttachmentPickerScreen()
|
AttachmentPickerScreen(attachmentsStore: conversation.attachmentsStore)
|
||||||
.environmentObject(conversation)
|
.environmentObject(conversation)
|
||||||
.environmentObject(fileStore)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TextField("", text: $messageStr, prompt: Text(L10n.Chat.textfieldPrompt).foregroundColor(.Material.Shape.separator))
|
TextField("", text: $messageStr, prompt: Text(L10n.Chat.textfieldPrompt).foregroundColor(.Material.Shape.separator))
|
||||||
|
|
Loading…
Reference in a new issue