From e2363f9f9f0d2469bd5a0f39f90b83da714d2998 Mon Sep 17 00:00:00 2001 From: fmodf Date: Wed, 10 Jul 2024 16:13:47 +0200 Subject: [PATCH] wip --- .../AppCore/Actions/AppActions.swift | 1 + .../AppCore/Actions/ConversationActions.swift | 5 ----- .../AppCore/Actions/SharingActions.swift | 7 +++++++ .../AppCore/Middlewares/SharingMiddleware.swift | 15 +++++++++++++++ .../AppCore/Reducers/AppReducer.swift | 3 +++ .../AppCore/Reducers/ConversationReducer.swift | 3 --- .../AppCore/Reducers/SharingReducer.swift | 11 +++++++++++ .../AppCore/Services/GalleryService.swift | 5 +++++ .../{XMPP => Services}/XMPPService.swift | 0 .../AppCore/State/AppState.swift | 2 ++ .../AppCore/State/SharingState.swift | 10 ++++++++++ .../ConversationsClassicApp.swift | 3 ++- .../AttachmentContactsPickerView.swift | 17 +++++++++-------- .../Attachments/AttachmentFilesPickerView.swift | 7 ++++--- .../Screens/Attachments/AttachmentHeader.swift | 2 +- .../AttachmentLocationPickerView.swift | 17 +++++++++-------- .../Media/AttachmentMediaPickerView.swift | 2 +- .../Conversation/ConversationTextInput.swift | 2 +- 18 files changed, 81 insertions(+), 31 deletions(-) create mode 100644 ConversationsClassic/AppCore/Actions/SharingActions.swift create mode 100644 ConversationsClassic/AppCore/Middlewares/SharingMiddleware.swift create mode 100644 ConversationsClassic/AppCore/Reducers/SharingReducer.swift create mode 100644 ConversationsClassic/AppCore/Services/GalleryService.swift rename ConversationsClassic/AppCore/{XMPP => Services}/XMPPService.swift (100%) create mode 100644 ConversationsClassic/AppCore/State/SharingState.swift diff --git a/ConversationsClassic/AppCore/Actions/AppActions.swift b/ConversationsClassic/AppCore/Actions/AppActions.swift index 4011895..2ef748d 100644 --- a/ConversationsClassic/AppCore/Actions/AppActions.swift +++ b/ConversationsClassic/AppCore/Actions/AppActions.swift @@ -11,4 +11,5 @@ enum AppAction: Codable { case chatsAction(_ action: ChatsAction) case conversationAction(_ action: ConversationAction) case messagesAction(_ action: MessagesAction) + case sharingAction(_ action: SharingAction) } diff --git a/ConversationsClassic/AppCore/Actions/ConversationActions.swift b/ConversationsClassic/AppCore/Actions/ConversationActions.swift index 9def345..9294677 100644 --- a/ConversationsClassic/AppCore/Actions/ConversationActions.swift +++ b/ConversationsClassic/AppCore/Actions/ConversationActions.swift @@ -5,9 +5,4 @@ enum ConversationAction: Codable { case sendMessage(from: String, to: String, body: String) case setReplyText(String) - - case showAttachmentPicker(Bool) - case sendAttachment([ShareItem]) - case sendAttachmentDone - case sendAttachmentError(reason: String) } diff --git a/ConversationsClassic/AppCore/Actions/SharingActions.swift b/ConversationsClassic/AppCore/Actions/SharingActions.swift new file mode 100644 index 0000000..55e7166 --- /dev/null +++ b/ConversationsClassic/AppCore/Actions/SharingActions.swift @@ -0,0 +1,7 @@ +enum SharingAction: Codable { + case showSharing(Bool) + + // case sendAttachment([ShareItem]) + // case sendAttachmentDone + // case sendAttachmentError(reason: String) +} diff --git a/ConversationsClassic/AppCore/Middlewares/SharingMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/SharingMiddleware.swift new file mode 100644 index 0000000..78b9eb0 --- /dev/null +++ b/ConversationsClassic/AppCore/Middlewares/SharingMiddleware.swift @@ -0,0 +1,15 @@ +import Combine +import Foundation +import Martin + +final class SharingMiddleware { + static let shared = SharingMiddleware() + private let gallery = GalleryService() + + func middleware(state _: AppState, action: AppAction) -> AnyPublisher { + switch action { + default: + return Empty().eraseToAnyPublisher() + } + } +} diff --git a/ConversationsClassic/AppCore/Reducers/AppReducer.swift b/ConversationsClassic/AppCore/Reducers/AppReducer.swift index 3ad19d1..53af1cb 100644 --- a/ConversationsClassic/AppCore/Reducers/AppReducer.swift +++ b/ConversationsClassic/AppCore/Reducers/AppReducer.swift @@ -30,6 +30,9 @@ extension AppState { case .messagesAction: break // messages actions are processed by MessagesMiddleware, and other components + + case .sharingAction(let action): + SharingState.reducer(state: &state.sharingState, action: action) } } } diff --git a/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift b/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift index a4d980a..cc76c62 100644 --- a/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift +++ b/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift @@ -17,9 +17,6 @@ extension ConversationState { state.replyText = text.makeReply } - case .showAttachmentPicker(let flag): - state.attachmentPickerVisible = flag - default: break } diff --git a/ConversationsClassic/AppCore/Reducers/SharingReducer.swift b/ConversationsClassic/AppCore/Reducers/SharingReducer.swift new file mode 100644 index 0000000..94d4262 --- /dev/null +++ b/ConversationsClassic/AppCore/Reducers/SharingReducer.swift @@ -0,0 +1,11 @@ +extension SharingState { + static func reducer(state: inout SharingState, action: SharingAction) { + switch action { + case .showSharing(let shown): + state.sharingShown = shown + + default: + break + } + } +} diff --git a/ConversationsClassic/AppCore/Services/GalleryService.swift b/ConversationsClassic/AppCore/Services/GalleryService.swift new file mode 100644 index 0000000..3588fba --- /dev/null +++ b/ConversationsClassic/AppCore/Services/GalleryService.swift @@ -0,0 +1,5 @@ +import Foundation + +final class GalleryService { + var dumb = false +} diff --git a/ConversationsClassic/AppCore/XMPP/XMPPService.swift b/ConversationsClassic/AppCore/Services/XMPPService.swift similarity index 100% rename from ConversationsClassic/AppCore/XMPP/XMPPService.swift rename to ConversationsClassic/AppCore/Services/XMPPService.swift diff --git a/ConversationsClassic/AppCore/State/AppState.swift b/ConversationsClassic/AppCore/State/AppState.swift index 9db82c9..56f589f 100644 --- a/ConversationsClassic/AppCore/State/AppState.swift +++ b/ConversationsClassic/AppCore/State/AppState.swift @@ -19,6 +19,7 @@ struct AppState: Stateable { var rostersState: RostersState var chatsState: ChatsState var conversationsState: ConversationState + var sharingState: SharingState } // MARK: Init @@ -33,5 +34,6 @@ extension AppState { rostersState = RostersState() chatsState = ChatsState() conversationsState = ConversationState() + sharingState = SharingState() } } diff --git a/ConversationsClassic/AppCore/State/SharingState.swift b/ConversationsClassic/AppCore/State/SharingState.swift new file mode 100644 index 0000000..93c606e --- /dev/null +++ b/ConversationsClassic/AppCore/State/SharingState.swift @@ -0,0 +1,10 @@ +struct SharingState: Stateable { + var sharingShown: Bool +} + +// MARK: Init +extension SharingState { + init() { + sharingShown = false + } +} diff --git a/ConversationsClassic/ConversationsClassicApp.swift b/ConversationsClassic/ConversationsClassicApp.swift index 41861a3..c2d19d6 100644 --- a/ConversationsClassic/ConversationsClassicApp.swift +++ b/ConversationsClassic/ConversationsClassicApp.swift @@ -14,7 +14,8 @@ let store = AppStore( RostersMiddleware.shared.middleware, ChatsMiddleware.shared.middleware, ConversationMiddleware.shared.middleware, - MessagesMiddleware.shared.middleware + MessagesMiddleware.shared.middleware, + SharingMiddleware.shared.middleware ] ) diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentContactsPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentContactsPickerView.swift index fe2b696..6916235 100644 --- a/ConversationsClassic/View/Screens/Attachments/AttachmentContactsPickerView.swift +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentContactsPickerView.swift @@ -40,14 +40,15 @@ struct AttachmentContactsPickerView: View { .clipped() .onTapGesture { if let selectedContact = selectedContact { - store.dispatch(.conversationAction(.sendAttachment([.init( - id: UUID().uuidString, - type: .contact, - data: Data(), - thumbnail: Data(), - string: selectedContact.contactBareJid - )]))) - store.dispatch(.conversationAction(.showAttachmentPicker(false))) + // TODO: fix it + // store.dispatch(.conversationAction(.sendAttachment([.init( + // id: UUID().uuidString, + // type: .contact, + // data: Data(), + // thumbnail: Data(), + // string: selectedContact.contactBareJid + // )]))) + store.dispatch(.sharingAction(.showSharing(false))) } } } diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentFilesPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentFilesPickerView.swift index 59e7e70..8ab6d7e 100644 --- a/ConversationsClassic/View/Screens/Attachments/AttachmentFilesPickerView.swift +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentFilesPickerView.swift @@ -16,11 +16,12 @@ struct AttachmentFilesPickerView: View { string: "" ) } - store.dispatch(.conversationAction(.sendAttachment(sharedFiles))) - store.dispatch(.conversationAction(.showAttachmentPicker(false))) + // TODO: Send files + // store.dispatch(.conversationAction(.sendAttachment(sharedFiles))) + store.dispatch(.sharingAction(.showSharing(false))) }, cancel: { - store.dispatch(.conversationAction(.showAttachmentPicker(false))) + store.dispatch(.sharingAction(.showSharing(false))) } ) } diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentHeader.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentHeader.swift index 5c8aa99..f9b61e4 100644 --- a/ConversationsClassic/View/Screens/Attachments/AttachmentHeader.swift +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentHeader.swift @@ -19,7 +19,7 @@ struct AttachmentHeader: View { Image(systemName: "xmark") .foregroundColor(Color.Material.Elements.active) .tappablePadding(.symmetric(12)) { - store.dispatch(.conversationAction(.showAttachmentPicker(false))) + store.dispatch(.sharingAction(.showSharing(false))) } } .padding(.horizontal, 16) diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift index 9b20902..679e10e 100644 --- a/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift @@ -62,14 +62,15 @@ struct AttachmentLocationPickerView: View { } .clipped() .onTapGesture { - store.dispatch(.conversationAction(.sendAttachment([.init( - id: UUID().uuidString, - type: .location, - data: Data(), - thumbnail: Data(), - string: "\(region.center.latitude),\(region.center.longitude)" - )]))) - store.dispatch(.conversationAction(.showAttachmentPicker(false))) + // TODO: Send location + // store.dispatch(.conversationAction(.sendAttachment([.init( + // id: UUID().uuidString, + // type: .location, + // data: Data(), + // thumbnail: Data(), + // string: "\(region.center.latitude),\(region.center.longitude)" + // )]))) + store.dispatch(.sharingAction(.showSharing(false))) } } .onAppear { diff --git a/ConversationsClassic/View/Screens/Attachments/Media/AttachmentMediaPickerView.swift b/ConversationsClassic/View/Screens/Attachments/Media/AttachmentMediaPickerView.swift index 9a0fc0d..3993c67 100644 --- a/ConversationsClassic/View/Screens/Attachments/Media/AttachmentMediaPickerView.swift +++ b/ConversationsClassic/View/Screens/Attachments/Media/AttachmentMediaPickerView.swift @@ -131,7 +131,7 @@ struct AttachmentMediaPickerView: View { .onTapGesture { let ids = selectedMedia.map { $0.id } sendGalleryMedia(ids: ids) - store.dispatch(.conversationAction(.showAttachmentPicker(false))) + store.dispatch(.sharingAction(.showSharing(false))) } } .onAppear { diff --git a/ConversationsClassic/View/Screens/Conversation/ConversationTextInput.swift b/ConversationsClassic/View/Screens/Conversation/ConversationTextInput.swift index cd9068a..e084dbd 100644 --- a/ConversationsClassic/View/Screens/Conversation/ConversationTextInput.swift +++ b/ConversationsClassic/View/Screens/Conversation/ConversationTextInput.swift @@ -49,7 +49,7 @@ struct ConversationTextInput: View { .foregroundColor(.Material.Elements.active) .padding(.leading, 8) .tappablePadding(.symmetric(8)) { - store.dispatch(.conversationAction(.showAttachmentPicker(true))) + store.dispatch(.sharingAction(.showSharing(true))) } TextField(L10n.Chat.textfieldPrompt, text: $messageStr) .font(.body1)