This commit is contained in:
fmodf 2024-07-10 16:13:47 +02:00
parent eb06abaebf
commit e2363f9f9f
18 changed files with 81 additions and 31 deletions

View file

@ -11,4 +11,5 @@ enum AppAction: Codable {
case chatsAction(_ action: ChatsAction)
case conversationAction(_ action: ConversationAction)
case messagesAction(_ action: MessagesAction)
case sharingAction(_ action: SharingAction)
}

View file

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

View file

@ -0,0 +1,7 @@
enum SharingAction: Codable {
case showSharing(Bool)
// case sendAttachment([ShareItem])
// case sendAttachmentDone
// case sendAttachmentError(reason: String)
}

View file

@ -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<AppAction, Never> {
switch action {
default:
return Empty().eraseToAnyPublisher()
}
}
}

View file

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

View file

@ -17,9 +17,6 @@ extension ConversationState {
state.replyText = text.makeReply
}
case .showAttachmentPicker(let flag):
state.attachmentPickerVisible = flag
default:
break
}

View file

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

View file

@ -0,0 +1,5 @@
import Foundation
final class GalleryService {
var dumb = false
}

View file

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

View file

@ -0,0 +1,10 @@
struct SharingState: Stateable {
var sharingShown: Bool
}
// MARK: Init
extension SharingState {
init() {
sharingShown = false
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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