wip
This commit is contained in:
parent
eb06abaebf
commit
e2363f9f9f
|
@ -11,4 +11,5 @@ enum AppAction: Codable {
|
||||||
case chatsAction(_ action: ChatsAction)
|
case chatsAction(_ action: ChatsAction)
|
||||||
case conversationAction(_ action: ConversationAction)
|
case conversationAction(_ action: ConversationAction)
|
||||||
case messagesAction(_ action: MessagesAction)
|
case messagesAction(_ action: MessagesAction)
|
||||||
|
case sharingAction(_ action: SharingAction)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,4 @@ enum ConversationAction: Codable {
|
||||||
|
|
||||||
case sendMessage(from: String, to: String, body: String)
|
case sendMessage(from: String, to: String, body: String)
|
||||||
case setReplyText(String)
|
case setReplyText(String)
|
||||||
|
|
||||||
case showAttachmentPicker(Bool)
|
|
||||||
case sendAttachment([ShareItem])
|
|
||||||
case sendAttachmentDone
|
|
||||||
case sendAttachmentError(reason: String)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
enum SharingAction: Codable {
|
||||||
|
case showSharing(Bool)
|
||||||
|
|
||||||
|
// case sendAttachment([ShareItem])
|
||||||
|
// case sendAttachmentDone
|
||||||
|
// case sendAttachmentError(reason: String)
|
||||||
|
}
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,6 +30,9 @@ extension AppState {
|
||||||
|
|
||||||
case .messagesAction:
|
case .messagesAction:
|
||||||
break // messages actions are processed by MessagesMiddleware, and other components
|
break // messages actions are processed by MessagesMiddleware, and other components
|
||||||
|
|
||||||
|
case .sharingAction(let action):
|
||||||
|
SharingState.reducer(state: &state.sharingState, action: action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,6 @@ extension ConversationState {
|
||||||
state.replyText = text.makeReply
|
state.replyText = text.makeReply
|
||||||
}
|
}
|
||||||
|
|
||||||
case .showAttachmentPicker(let flag):
|
|
||||||
state.attachmentPickerVisible = flag
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
11
ConversationsClassic/AppCore/Reducers/SharingReducer.swift
Normal file
11
ConversationsClassic/AppCore/Reducers/SharingReducer.swift
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
final class GalleryService {
|
||||||
|
var dumb = false
|
||||||
|
}
|
|
@ -19,6 +19,7 @@ struct AppState: Stateable {
|
||||||
var rostersState: RostersState
|
var rostersState: RostersState
|
||||||
var chatsState: ChatsState
|
var chatsState: ChatsState
|
||||||
var conversationsState: ConversationState
|
var conversationsState: ConversationState
|
||||||
|
var sharingState: SharingState
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Init
|
// MARK: Init
|
||||||
|
@ -33,5 +34,6 @@ extension AppState {
|
||||||
rostersState = RostersState()
|
rostersState = RostersState()
|
||||||
chatsState = ChatsState()
|
chatsState = ChatsState()
|
||||||
conversationsState = ConversationState()
|
conversationsState = ConversationState()
|
||||||
|
sharingState = SharingState()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
ConversationsClassic/AppCore/State/SharingState.swift
Normal file
10
ConversationsClassic/AppCore/State/SharingState.swift
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
struct SharingState: Stateable {
|
||||||
|
var sharingShown: Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Init
|
||||||
|
extension SharingState {
|
||||||
|
init() {
|
||||||
|
sharingShown = false
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,7 +14,8 @@ let store = AppStore(
|
||||||
RostersMiddleware.shared.middleware,
|
RostersMiddleware.shared.middleware,
|
||||||
ChatsMiddleware.shared.middleware,
|
ChatsMiddleware.shared.middleware,
|
||||||
ConversationMiddleware.shared.middleware,
|
ConversationMiddleware.shared.middleware,
|
||||||
MessagesMiddleware.shared.middleware
|
MessagesMiddleware.shared.middleware,
|
||||||
|
SharingMiddleware.shared.middleware
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -40,14 +40,15 @@ struct AttachmentContactsPickerView: View {
|
||||||
.clipped()
|
.clipped()
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
if let selectedContact = selectedContact {
|
if let selectedContact = selectedContact {
|
||||||
store.dispatch(.conversationAction(.sendAttachment([.init(
|
// TODO: fix it
|
||||||
id: UUID().uuidString,
|
// store.dispatch(.conversationAction(.sendAttachment([.init(
|
||||||
type: .contact,
|
// id: UUID().uuidString,
|
||||||
data: Data(),
|
// type: .contact,
|
||||||
thumbnail: Data(),
|
// data: Data(),
|
||||||
string: selectedContact.contactBareJid
|
// thumbnail: Data(),
|
||||||
)])))
|
// string: selectedContact.contactBareJid
|
||||||
store.dispatch(.conversationAction(.showAttachmentPicker(false)))
|
// )])))
|
||||||
|
store.dispatch(.sharingAction(.showSharing(false)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,12 @@ struct AttachmentFilesPickerView: View {
|
||||||
string: ""
|
string: ""
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
store.dispatch(.conversationAction(.sendAttachment(sharedFiles)))
|
// TODO: Send files
|
||||||
store.dispatch(.conversationAction(.showAttachmentPicker(false)))
|
// store.dispatch(.conversationAction(.sendAttachment(sharedFiles)))
|
||||||
|
store.dispatch(.sharingAction(.showSharing(false)))
|
||||||
},
|
},
|
||||||
cancel: {
|
cancel: {
|
||||||
store.dispatch(.conversationAction(.showAttachmentPicker(false)))
|
store.dispatch(.sharingAction(.showSharing(false)))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ struct AttachmentHeader: View {
|
||||||
Image(systemName: "xmark")
|
Image(systemName: "xmark")
|
||||||
.foregroundColor(Color.Material.Elements.active)
|
.foregroundColor(Color.Material.Elements.active)
|
||||||
.tappablePadding(.symmetric(12)) {
|
.tappablePadding(.symmetric(12)) {
|
||||||
store.dispatch(.conversationAction(.showAttachmentPicker(false)))
|
store.dispatch(.sharingAction(.showSharing(false)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(.horizontal, 16)
|
.padding(.horizontal, 16)
|
||||||
|
|
|
@ -62,14 +62,15 @@ struct AttachmentLocationPickerView: View {
|
||||||
}
|
}
|
||||||
.clipped()
|
.clipped()
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
store.dispatch(.conversationAction(.sendAttachment([.init(
|
// TODO: Send location
|
||||||
id: UUID().uuidString,
|
// store.dispatch(.conversationAction(.sendAttachment([.init(
|
||||||
type: .location,
|
// id: UUID().uuidString,
|
||||||
data: Data(),
|
// type: .location,
|
||||||
thumbnail: Data(),
|
// data: Data(),
|
||||||
string: "\(region.center.latitude),\(region.center.longitude)"
|
// thumbnail: Data(),
|
||||||
)])))
|
// string: "\(region.center.latitude),\(region.center.longitude)"
|
||||||
store.dispatch(.conversationAction(.showAttachmentPicker(false)))
|
// )])))
|
||||||
|
store.dispatch(.sharingAction(.showSharing(false)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
|
|
|
@ -131,7 +131,7 @@ struct AttachmentMediaPickerView: View {
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
let ids = selectedMedia.map { $0.id }
|
let ids = selectedMedia.map { $0.id }
|
||||||
sendGalleryMedia(ids: ids)
|
sendGalleryMedia(ids: ids)
|
||||||
store.dispatch(.conversationAction(.showAttachmentPicker(false)))
|
store.dispatch(.sharingAction(.showSharing(false)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
|
|
|
@ -49,7 +49,7 @@ struct ConversationTextInput: View {
|
||||||
.foregroundColor(.Material.Elements.active)
|
.foregroundColor(.Material.Elements.active)
|
||||||
.padding(.leading, 8)
|
.padding(.leading, 8)
|
||||||
.tappablePadding(.symmetric(8)) {
|
.tappablePadding(.symmetric(8)) {
|
||||||
store.dispatch(.conversationAction(.showAttachmentPicker(true)))
|
store.dispatch(.sharingAction(.showSharing(true)))
|
||||||
}
|
}
|
||||||
TextField(L10n.Chat.textfieldPrompt, text: $messageStr)
|
TextField(L10n.Chat.textfieldPrompt, text: $messageStr)
|
||||||
.font(.body1)
|
.font(.body1)
|
||||||
|
|
Loading…
Reference in a new issue