diff --git a/ConversationsClassic/AppCore/Actions/ChatsActions.swift b/ConversationsClassic/AppCore/Actions/ChatsActions.swift index e4a720b..debeb1e 100644 --- a/ConversationsClassic/AppCore/Actions/ChatsActions.swift +++ b/ConversationsClassic/AppCore/Actions/ChatsActions.swift @@ -1,3 +1,5 @@ enum ChatsAction: Codable { case chatsListUpdated(chats: [Chat]) + + case startChat(accountJid: String, participantJid: String) } diff --git a/ConversationsClassic/AppCore/Middlewares/AccountsMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/AccountsMiddleware.swift index b341cf3..9e1b9e2 100644 --- a/ConversationsClassic/AppCore/Middlewares/AccountsMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/AccountsMiddleware.swift @@ -30,7 +30,6 @@ final class AccountsMiddleware { default: promise(.success(.empty)) } - } else { promise(.success(.empty)) } diff --git a/ConversationsClassic/AppCore/Middlewares/ChatsMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/ChatsMiddleware.swift index ade60c2..2e76ba1 100644 --- a/ConversationsClassic/AppCore/Middlewares/ChatsMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/ChatsMiddleware.swift @@ -3,12 +3,22 @@ import Combine final class ChatsMiddleware { static let shared = ChatsMiddleware() - func middleware(state _: AppState, action: AppAction) -> AnyPublisher { + func middleware(state: AppState, action: AppAction) -> AnyPublisher { switch action { case .databaseAction(.storedChatsLoaded(let chats)): return Just(.chatsAction(.chatsListUpdated(chats: chats))) .eraseToAnyPublisher() + case .chatsAction(.startChat(accountJid: let accountJid, participantJid: let participantJid)): + return Future { promise in + // find existing chat + let exist = state.chatsState.chats.first { + $0.account == accountJid && $0.participant == participantJid + } + promise(.success(.empty)) + } + .eraseToAnyPublisher() + default: return Empty().eraseToAnyPublisher() } diff --git a/ConversationsClassic/View/Screens/ChatsListScreen.swift b/ConversationsClassic/View/Screens/ChatsListScreen.swift index 722dc70..39c93c6 100644 --- a/ConversationsClassic/View/Screens/ChatsListScreen.swift +++ b/ConversationsClassic/View/Screens/ChatsListScreen.swift @@ -90,7 +90,7 @@ private struct ChatsRow: View { } .sharedListRow() .onTapGesture { - // state.startChat(chat) + store.dispatch(.chatsAction(.startChat(accountJid: chat.account, participantJid: chat.participant))) } } } diff --git a/ConversationsClassic/View/Screens/ContactsScreen.swift b/ConversationsClassic/View/Screens/ContactsScreen.swift index e60809a..40cf0ea 100644 --- a/ConversationsClassic/View/Screens/ContactsScreen.swift +++ b/ConversationsClassic/View/Screens/ContactsScreen.swift @@ -120,7 +120,7 @@ private struct ContactsScreenRow: View { } .sharedListRow() .onTapGesture { - // state.startChat(roster) + store.dispatch(.chatsAction(.startChat(accountJid: roster.bareJid, participantJid: roster.contactBareJid))) } .onLongPressGesture { isShowingMenu.toggle() @@ -135,7 +135,7 @@ private struct ContactsScreenRow: View { } .contextMenu { Button(L10n.Contacts.sendMessage, systemImage: "message") { - // state.startChat(roster) + store.dispatch(.chatsAction(.startChat(accountJid: roster.bareJid, participantJid: roster.contactBareJid))) } Divider()