wip
This commit is contained in:
parent
a182726352
commit
f8a38b0fdd
|
@ -1,3 +1,5 @@
|
|||
enum ChatsAction: Codable {
|
||||
case chatsListUpdated(chats: [Chat])
|
||||
|
||||
case startChat(accountJid: String, participantJid: String)
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ final class AccountsMiddleware {
|
|||
default:
|
||||
promise(.success(.empty))
|
||||
}
|
||||
|
||||
} else {
|
||||
promise(.success(.empty))
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ private struct ChatsRow: View {
|
|||
}
|
||||
.sharedListRow()
|
||||
.onTapGesture {
|
||||
// state.startChat(chat)
|
||||
store.dispatch(.chatsAction(.startChat(accountJid: chat.account, participantJid: chat.participant)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue