wip
This commit is contained in:
parent
fc88c50ae8
commit
e23a312538
|
@ -1,7 +1,3 @@
|
||||||
enum ConversationAction: Codable {
|
enum ConversationAction: Codable {
|
||||||
case makeConversationActive(chat: Chat, roster: Roster?)
|
case makeConversationActive(chat: Chat, roster: Roster?)
|
||||||
case messageForCurrentConversationReceived(Message)
|
|
||||||
case sendMessage(from: String, to: String, body: String)
|
|
||||||
|
|
||||||
case messagesUpdated(messages: [Message])
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,7 @@ extension Database {
|
||||||
table.column("thread", .text)
|
table.column("thread", .text)
|
||||||
table.column("oobUrl", .text)
|
table.column("oobUrl", .text)
|
||||||
table.column("date", .datetime).notNull()
|
table.column("date", .datetime).notNull()
|
||||||
|
table.column("pending", .boolean).notNull()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,24 +16,24 @@ final class ConversationMiddleware {
|
||||||
case .conversationAction(.makeConversationActive):
|
case .conversationAction(.makeConversationActive):
|
||||||
return Just(AppAction.changeFlow(.conversation)).eraseToAnyPublisher()
|
return Just(AppAction.changeFlow(.conversation)).eraseToAnyPublisher()
|
||||||
|
|
||||||
case .xmppAction(.xmppMessageReceived(let message)):
|
// case .xmppAction(.xmppMessageReceived(let message)):
|
||||||
return Future<AppAction, Never> { promise in
|
// return Future<AppAction, Never> { promise in
|
||||||
let currentChat = state.conversationsState.currentChat
|
// let currentChat = state.conversationsState.currentChat
|
||||||
if message.from == currentChat?.participant, message.to == currentChat?.account, message.contentType != .typing {
|
// if message.from == currentChat?.participant, message.to == currentChat?.account, message.contentType != .typing {
|
||||||
promise(.success(.conversationAction(.messageForCurrentConversationReceived(message))))
|
// promise(.success(.conversationAction(.messageForCurrentConversationReceived(message))))
|
||||||
} else {
|
// } else {
|
||||||
promise(.success(.empty))
|
// promise(.success(.empty))
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
.eraseToAnyPublisher()
|
// .eraseToAnyPublisher()
|
||||||
|
//
|
||||||
case .conversationAction(.messageForCurrentConversationReceived(let message)):
|
// case .conversationAction(.messageForCurrentConversationReceived(let message)):
|
||||||
return Future<AppAction, Never> { promise in
|
// return Future<AppAction, Never> { promise in
|
||||||
var currentMessages = state.conversationsState.currentMessages
|
// var currentMessages = state.conversationsState.currentMessages
|
||||||
currentMessages.append(message)
|
// currentMessages.append(message)
|
||||||
promise(.success(.conversationAction(.messagesUpdated(messages: currentMessages))))
|
// promise(.success(.conversationAction(.messagesUpdated(messages: currentMessages))))
|
||||||
}
|
// }
|
||||||
.eraseToAnyPublisher()
|
// .eraseToAnyPublisher()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return Empty().eraseToAnyPublisher()
|
return Empty().eraseToAnyPublisher()
|
||||||
|
|
|
@ -86,13 +86,13 @@ final class XMPPMiddleware {
|
||||||
}
|
}
|
||||||
.eraseToAnyPublisher()
|
.eraseToAnyPublisher()
|
||||||
|
|
||||||
case .conversationAction(.sendMessage(let from, let to, let body)):
|
// case .conversationAction(.sendMessage(let from, let to, let body)):
|
||||||
return Future<AppAction, Never> { [weak self] promise in
|
// return Future<AppAction, Never> { [weak self] promise in
|
||||||
// TODO: handle errors
|
// // TODO: handle errors
|
||||||
self?.service.sendMessage(from: from, to: to, body: body)
|
// self?.service.sendMessage(from: from, to: to, body: body)
|
||||||
promise(.success(.empty))
|
// promise(.success(.empty))
|
||||||
}
|
// }
|
||||||
.eraseToAnyPublisher()
|
// .eraseToAnyPublisher()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return Empty().eraseToAnyPublisher()
|
return Empty().eraseToAnyPublisher()
|
||||||
|
|
|
@ -28,6 +28,7 @@ struct Message: Stateable, Identifiable, DatabaseValueConvertible {
|
||||||
let oobUrl: String?
|
let oobUrl: String?
|
||||||
|
|
||||||
let date: Date
|
let date: Date
|
||||||
|
let pending: Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Message {
|
extension Message {
|
||||||
|
@ -72,7 +73,8 @@ extension Message {
|
||||||
subject: martinMessage.subject,
|
subject: martinMessage.subject,
|
||||||
thread: martinMessage.thread,
|
thread: martinMessage.thread,
|
||||||
oobUrl: martinMessage.oob,
|
oobUrl: martinMessage.oob,
|
||||||
date: Date()
|
date: Date(),
|
||||||
|
pending: false
|
||||||
)
|
)
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,6 @@ extension ConversationState {
|
||||||
state.currentChat = chat
|
state.currentChat = chat
|
||||||
state.currentRoster = roster
|
state.currentRoster = roster
|
||||||
|
|
||||||
case .messagesUpdated(let messages):
|
|
||||||
state.currentMessages = messages
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,14 @@ struct ConversationScreen: View {
|
||||||
}
|
}
|
||||||
.listStyle(.plain)
|
.listStyle(.plain)
|
||||||
.background(Color.Main.backgroundLight)
|
.background(Color.Main.backgroundLight)
|
||||||
|
.scrollDismissesKeyboard(.immediately)
|
||||||
} else {
|
} else {
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.onTapGesture {
|
||||||
|
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.safeAreaInset(edge: .bottom, spacing: 0) {
|
.safeAreaInset(edge: .bottom, spacing: 0) {
|
||||||
ConversationScreenTextInput()
|
ConversationScreenTextInput()
|
||||||
|
@ -66,13 +70,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 acc = store.state.conversationsState.currentChat?.account else { return }
|
||||||
guard let contact = store.state.conversationsState.currentChat?.participant else { return }
|
// guard let contact = store.state.conversationsState.currentChat?.participant else { return }
|
||||||
store.dispatch(.conversationAction(.sendMessage(
|
// store.dispatch(.conversationAction(.sendMessage(
|
||||||
from: acc,
|
// from: acc,
|
||||||
to: contact,
|
// to: contact,
|
||||||
body: messageStr
|
// 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)
|
||||||
}
|
}
|
||||||
|
@ -217,18 +221,18 @@ struct MessageTime: View {
|
||||||
contentType: .text,
|
contentType: .text,
|
||||||
from: contact,
|
from: contact,
|
||||||
to: acc,
|
to: acc,
|
||||||
|
|
||||||
body: "this is for test sdgdsfg dsfg dsfgdg dsfgdfgsdgsdfgdfg sdfgdsfgdfsg dsfgdsfgsdfg dsfgdfgsdg fgf fgfg sdfsdf sdfsdf sdf sdfsdf sdf sdfsdf sdfsdfsdf sdfsdf ",
|
body: "this is for test sdgdsfg dsfg dsfgdg dsfgdfgsdgsdfgdfg sdfgdsfgdfsg dsfgdsfgsdfg dsfgdfgsdg fgf fgfg sdfsdf sdfsdf sdf sdfsdf sdf sdfsdf sdfsdfsdf sdfsdf ",
|
||||||
subject: nil,
|
subject: nil,
|
||||||
thread: nil,
|
thread: nil,
|
||||||
oobUrl: nil,
|
oobUrl: nil,
|
||||||
date: Date()
|
date: Date(),
|
||||||
|
pending: false
|
||||||
),
|
),
|
||||||
Message(id: "2", type: .chat, contentType: .text, from: contact, to: acc, body: "this is for testsdfsdf sdfsdf sdfs sdf sdffsdf sdf sdf sdf sdf sdf sdff sdfffwwe ", subject: nil, thread: nil, oobUrl: nil, date: Date()),
|
Message(id: "2", type: .chat, contentType: .text, from: contact, to: acc, body: "this is for testsdfsdf sdfsdf sdfs sdf sdffsdf sdf sdf sdf sdf sdf sdff sdfffwwe ", subject: nil, thread: nil, oobUrl: nil, date: Date(), pending: false),
|
||||||
Message(id: "3", type: .chat, contentType: .text, from: contact, to: acc, body: "this is for test", subject: nil, thread: nil, oobUrl: nil, date: Date()),
|
Message(id: "3", type: .chat, contentType: .text, from: contact, to: acc, body: "this is for test", subject: nil, thread: nil, oobUrl: nil, date: Date(), pending: false),
|
||||||
Message(id: "4", type: .chat, contentType: .text, from: acc, to: contact, body: "this is for test sdfkjwek jwkjfh jwerf jdfhskjdhf jsdhfjhwefh sjdhfh fsdjhfh sd ", subject: nil, thread: nil, oobUrl: nil, date: Date()),
|
Message(id: "4", type: .chat, contentType: .text, from: acc, to: contact, body: "this is for test sdfkjwek jwkjfh jwerf jdfhskjdhf jsdhfjhwefh sjdhfh fsdjhfh sd ", subject: nil, thread: nil, oobUrl: nil, date: Date(), pending: false),
|
||||||
Message(id: "5", type: .chat, contentType: .text, from: contact, to: acc, body: "this is for test sdfjkkeke kekkddjw;; w;edkdjfj l kjwekrjfk wef", subject: nil, thread: nil, oobUrl: nil, date: Date()),
|
Message(id: "5", type: .chat, contentType: .text, from: contact, to: acc, body: "this is for test sdfjkkeke kekkddjw;; w;edkdjfj l kjwekrjfk wef", subject: nil, thread: nil, oobUrl: nil, date: Date(), pending: false),
|
||||||
Message(id: "6", type: .chat, contentType: .text, from: acc, to: contact, body: "this is for testsdf dsdkkekkddn wejkjfj ", subject: nil, thread: nil, oobUrl: nil, date: Date()),
|
Message(id: "6", type: .chat, contentType: .text, from: acc, to: contact, body: "this is for testsdf dsdkkekkddn wejkjfj ", subject: nil, thread: nil, oobUrl: nil, date: Date(), pending: false),
|
||||||
Message(
|
Message(
|
||||||
id: "7",
|
id: "7",
|
||||||
type: .chat,
|
type: .chat,
|
||||||
|
@ -240,12 +244,12 @@ struct MessageTime: View {
|
||||||
subject: nil,
|
subject: nil,
|
||||||
thread: nil,
|
thread: nil,
|
||||||
oobUrl: nil,
|
oobUrl: nil,
|
||||||
date: Date()
|
date: Date(), pending: false
|
||||||
),
|
),
|
||||||
Message(id: "8", type: .chat, contentType: .text, from: acc, to: contact, body: "so test", subject: nil, thread: nil, oobUrl: nil, date: Date()),
|
Message(id: "8", type: .chat, contentType: .text, from: acc, to: contact, body: "so test", subject: nil, thread: nil, oobUrl: nil, date: Date(), pending: false),
|
||||||
Message(id: "9", type: .chat, contentType: .text, from: contact, to: acc, body: "so test", subject: nil, thread: nil, oobUrl: nil, date: Date()),
|
Message(id: "9", type: .chat, contentType: .text, from: contact, to: acc, body: "so test", subject: nil, thread: nil, oobUrl: nil, date: Date(), pending: false),
|
||||||
Message(id: "10", type: .chat, contentType: .text, from: acc, to: contact, body: "so test so test so test", subject: nil, thread: nil, oobUrl: nil, date: Date()),
|
Message(id: "10", type: .chat, contentType: .text, from: acc, to: contact, body: "so test so test so test", subject: nil, thread: nil, oobUrl: nil, date: Date(), pending: false),
|
||||||
Message(id: "11", type: .chat, contentType: .text, from: contact, to: acc, body: "xD", subject: nil, thread: nil, oobUrl: nil, date: Date())
|
Message(id: "11", type: .chat, contentType: .text, from: contact, to: acc, body: "xD", subject: nil, thread: nil, oobUrl: nil, date: Date(), pending: false)
|
||||||
]
|
]
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue