This commit is contained in:
fmodf 2024-06-20 07:27:13 +02:00
parent a182726352
commit f8a38b0fdd
5 changed files with 16 additions and 5 deletions

View file

@ -1,3 +1,5 @@
enum ChatsAction: Codable {
case chatsListUpdated(chats: [Chat])
case startChat(accountJid: String, participantJid: String)
}

View file

@ -30,7 +30,6 @@ final class AccountsMiddleware {
default:
promise(.success(.empty))
}
} else {
promise(.success(.empty))
}

View file

@ -3,12 +3,22 @@ import Combine
final class ChatsMiddleware {
static let shared = ChatsMiddleware()
func middleware(state _: AppState, action: AppAction) -> AnyPublisher<AppAction, Never> {
func middleware(state: AppState, action: AppAction) -> AnyPublisher<AppAction, Never> {
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<AppAction, Never> { 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()
}

View file

@ -90,7 +90,7 @@ private struct ChatsRow: View {
}
.sharedListRow()
.onTapGesture {
// state.startChat(chat)
store.dispatch(.chatsAction(.startChat(accountJid: chat.account, participantJid: chat.participant)))
}
}
}

View file

@ -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()