wip
This commit is contained in:
parent
5df60bd867
commit
2b3e50eb77
|
@ -1,4 +1,5 @@
|
||||||
enum ConversationAction: Codable {
|
enum ConversationAction: Codable {
|
||||||
case makeConversationActive(chat: Chat)
|
case makeConversationActive(chat: Chat)
|
||||||
case messageForCurrentConversationReceived(Message)
|
case messageForCurrentConversationReceived(Message)
|
||||||
|
case sendMessage(from: String, to: String, body: String)
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,14 @@ final class XMPPMiddleware {
|
||||||
}
|
}
|
||||||
.eraseToAnyPublisher()
|
.eraseToAnyPublisher()
|
||||||
|
|
||||||
|
case .conversationAction(.sendMessage(let from, let to, let body)):
|
||||||
|
return Future<AppAction, Never> { [weak self] promise in
|
||||||
|
// TODO: handle errors
|
||||||
|
self?.service.sendMessage(from: from, to: to, body: body)
|
||||||
|
promise(.success(.empty))
|
||||||
|
}
|
||||||
|
.eraseToAnyPublisher()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return Empty().eraseToAnyPublisher()
|
return Empty().eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// TODO: implement complex merging list of messages
|
||||||
extension ConversationState {
|
extension ConversationState {
|
||||||
static func reducer(state: inout ConversationState, action: ConversationAction) {
|
static func reducer(state: inout ConversationState, action: ConversationAction) {
|
||||||
switch action {
|
switch action {
|
||||||
|
|
|
@ -103,4 +103,17 @@ final class XMPPService: ObservableObject {
|
||||||
func getClient(for jid: String) -> XMPPClient? {
|
func getClient(for jid: String) -> XMPPClient? {
|
||||||
clients.first { $0.connectionConfiguration.userJid.stringValue == jid }
|
clients.first { $0.connectionConfiguration.userJid.stringValue == jid }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: add handler
|
||||||
|
func sendMessage(from: String, to: String, body: String) {
|
||||||
|
guard let client = getClient(for: from) else { return }
|
||||||
|
let message = Martin.Message()
|
||||||
|
// message.from = client.connectionConfiguration.userJid
|
||||||
|
message.to = JID(to)
|
||||||
|
message.body = body
|
||||||
|
|
||||||
|
client.writer.write(message) { res in
|
||||||
|
print(res)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,13 @@ struct ConversationScreenTextInput: View {
|
||||||
.padding(.trailing, 8)
|
.padding(.trailing, 8)
|
||||||
.tappablePadding(.symmetric(8)) {
|
.tappablePadding(.symmetric(8)) {
|
||||||
if !messageStr.isEmpty {
|
if !messageStr.isEmpty {
|
||||||
|
guard let acc = store.state.conversationsState.currentChat?.account else { return }
|
||||||
|
guard let contact = store.state.conversationsState.currentChat?.participant else { return }
|
||||||
|
store.dispatch(.conversationAction(.sendMessage(
|
||||||
|
from: acc,
|
||||||
|
to: contact,
|
||||||
|
body: messageStr
|
||||||
|
)))
|
||||||
messageStr = ""
|
messageStr = ""
|
||||||
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
|
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue