diff --git a/ConversationsClassic/AppCore/Actions/ConversationActions.swift b/ConversationsClassic/AppCore/Actions/ConversationActions.swift index 838f835..c8cb715 100644 --- a/ConversationsClassic/AppCore/Actions/ConversationActions.swift +++ b/ConversationsClassic/AppCore/Actions/ConversationActions.swift @@ -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]) } diff --git a/ConversationsClassic/AppCore/Database/Database+Migrations.swift b/ConversationsClassic/AppCore/Database/Database+Migrations.swift index f8d4c59..3b93a9a 100644 --- a/ConversationsClassic/AppCore/Database/Database+Migrations.swift +++ b/ConversationsClassic/AppCore/Database/Database+Migrations.swift @@ -56,6 +56,7 @@ extension Database { table.column("thread", .text) table.column("oobUrl", .text) table.column("date", .datetime).notNull() + table.column("pending", .boolean).notNull() } } diff --git a/ConversationsClassic/AppCore/Middlewares/ConversationMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/ConversationMiddleware.swift index bfdafc7..943a191 100644 --- a/ConversationsClassic/AppCore/Middlewares/ConversationMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/ConversationMiddleware.swift @@ -16,24 +16,24 @@ final class ConversationMiddleware { case .conversationAction(.makeConversationActive): return Just(AppAction.changeFlow(.conversation)).eraseToAnyPublisher() - case .xmppAction(.xmppMessageReceived(let message)): - return Future { 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 { promise in - var currentMessages = state.conversationsState.currentMessages - currentMessages.append(message) - promise(.success(.conversationAction(.messagesUpdated(messages: currentMessages)))) - } - .eraseToAnyPublisher() + // case .xmppAction(.xmppMessageReceived(let message)): + // return Future { 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 { promise in + // var currentMessages = state.conversationsState.currentMessages + // currentMessages.append(message) + // promise(.success(.conversationAction(.messagesUpdated(messages: currentMessages)))) + // } + // .eraseToAnyPublisher() default: return Empty().eraseToAnyPublisher() diff --git a/ConversationsClassic/AppCore/Middlewares/XMPPMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/XMPPMiddleware.swift index eaa20af..18011b1 100644 --- a/ConversationsClassic/AppCore/Middlewares/XMPPMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/XMPPMiddleware.swift @@ -86,13 +86,13 @@ final class XMPPMiddleware { } .eraseToAnyPublisher() - case .conversationAction(.sendMessage(let from, let to, let body)): - return Future { [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 { [weak self] promise in + // // TODO: handle errors + // self?.service.sendMessage(from: from, to: to, body: body) + // promise(.success(.empty)) + // } + // .eraseToAnyPublisher() default: return Empty().eraseToAnyPublisher() diff --git a/ConversationsClassic/AppCore/Models/Message.swift b/ConversationsClassic/AppCore/Models/Message.swift index b5f0beb..7c7ba5c 100644 --- a/ConversationsClassic/AppCore/Models/Message.swift +++ b/ConversationsClassic/AppCore/Models/Message.swift @@ -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 } diff --git a/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift b/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift index 164afb0..ad87e81 100644 --- a/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift +++ b/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift @@ -7,9 +7,6 @@ extension ConversationState { state.currentChat = chat state.currentRoster = roster - case .messagesUpdated(let messages): - state.currentMessages = messages - default: break } diff --git a/ConversationsClassic/View/Screens/ConversationScreen.swift b/ConversationsClassic/View/Screens/ConversationScreen.swift index a7ffb07..759bdda 100644 --- a/ConversationsClassic/View/Screens/ConversationScreen.swift +++ b/ConversationsClassic/View/Screens/ConversationScreen.swift @@ -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 }