This commit is contained in:
fmodf 2024-06-26 09:27:23 +02:00
parent fc88c50ae8
commit e23a312538
7 changed files with 52 additions and 52 deletions

View file

@ -1,7 +1,3 @@
enum ConversationAction: Codable {
case makeConversationActive(chat: Chat, roster: Roster?)
case messageForCurrentConversationReceived(Message)
case sendMessage(from: String, to: String, body: String)
case messagesUpdated(messages: [Message])
}

View file

@ -56,6 +56,7 @@ extension Database {
table.column("thread", .text)
table.column("oobUrl", .text)
table.column("date", .datetime).notNull()
table.column("pending", .boolean).notNull()
}
}

View file

@ -16,24 +16,24 @@ final class ConversationMiddleware {
case .conversationAction(.makeConversationActive):
return Just(AppAction.changeFlow(.conversation)).eraseToAnyPublisher()
case .xmppAction(.xmppMessageReceived(let message)):
return Future<AppAction, Never> { promise in
let currentChat = state.conversationsState.currentChat
if message.from == currentChat?.participant, message.to == currentChat?.account, message.contentType != .typing {
promise(.success(.conversationAction(.messageForCurrentConversationReceived(message))))
} else {
promise(.success(.empty))
}
}
.eraseToAnyPublisher()
case .conversationAction(.messageForCurrentConversationReceived(let message)):
return Future<AppAction, Never> { promise in
var currentMessages = state.conversationsState.currentMessages
currentMessages.append(message)
promise(.success(.conversationAction(.messagesUpdated(messages: currentMessages))))
}
.eraseToAnyPublisher()
// case .xmppAction(.xmppMessageReceived(let message)):
// return Future<AppAction, Never> { promise in
// let currentChat = state.conversationsState.currentChat
// if message.from == currentChat?.participant, message.to == currentChat?.account, message.contentType != .typing {
// promise(.success(.conversationAction(.messageForCurrentConversationReceived(message))))
// } else {
// promise(.success(.empty))
// }
// }
// .eraseToAnyPublisher()
//
// case .conversationAction(.messageForCurrentConversationReceived(let message)):
// return Future<AppAction, Never> { promise in
// var currentMessages = state.conversationsState.currentMessages
// currentMessages.append(message)
// promise(.success(.conversationAction(.messagesUpdated(messages: currentMessages))))
// }
// .eraseToAnyPublisher()
default:
return Empty().eraseToAnyPublisher()

View file

@ -86,13 +86,13 @@ final class XMPPMiddleware {
}
.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()
// 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:
return Empty().eraseToAnyPublisher()

View file

@ -28,6 +28,7 @@ struct Message: Stateable, Identifiable, DatabaseValueConvertible {
let oobUrl: String?
let date: Date
let pending: Bool
}
extension Message {
@ -72,7 +73,8 @@ extension Message {
subject: martinMessage.subject,
thread: martinMessage.thread,
oobUrl: martinMessage.oob,
date: Date()
date: Date(),
pending: false
)
return msg
}

View file

@ -7,9 +7,6 @@ extension ConversationState {
state.currentChat = chat
state.currentRoster = roster
case .messagesUpdated(let messages):
state.currentMessages = messages
default:
break
}

View file

@ -27,10 +27,14 @@ struct ConversationScreen: View {
}
.listStyle(.plain)
.background(Color.Main.backgroundLight)
.scrollDismissesKeyboard(.immediately)
} else {
Spacer()
}
}
.onTapGesture {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}
.safeAreaInset(edge: .bottom, spacing: 0) {
ConversationScreenTextInput()
@ -66,13 +70,13 @@ struct ConversationScreenTextInput: View {
.padding(.trailing, 8)
.tappablePadding(.symmetric(8)) {
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
)))
// 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 = ""
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
@ -217,18 +221,18 @@ struct MessageTime: View {
contentType: .text,
from: contact,
to: acc,
body: "this is for test sdgdsfg dsfg dsfgdg dsfgdfgsdgsdfgdfg sdfgdsfgdfsg dsfgdsfgsdfg dsfgdfgsdg fgf fgfg sdfsdf sdfsdf sdf sdfsdf sdf sdfsdf sdfsdfsdf sdfsdf ",
subject: nil,
thread: 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: "3", type: .chat, contentType: .text, from: contact, to: acc, body: "this is for test", 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()),
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: "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: "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(), 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(), 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(), 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(), pending: false),
Message(
id: "7",
type: .chat,
@ -240,12 +244,12 @@ struct MessageTime: View {
subject: nil,
thread: 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: "9", type: .chat, contentType: .text, from: contact, to: acc, body: "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()),
Message(id: "11", type: .chat, contentType: .text, from: contact, to: acc, body: "xD", 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(), 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(), pending: false),
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
}