wip
This commit is contained in:
parent
a182726352
commit
f8a38b0fdd
|
@ -1,3 +1,5 @@
|
||||||
enum ChatsAction: Codable {
|
enum ChatsAction: Codable {
|
||||||
case chatsListUpdated(chats: [Chat])
|
case chatsListUpdated(chats: [Chat])
|
||||||
|
|
||||||
|
case startChat(accountJid: String, participantJid: String)
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ final class AccountsMiddleware {
|
||||||
default:
|
default:
|
||||||
promise(.success(.empty))
|
promise(.success(.empty))
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
promise(.success(.empty))
|
promise(.success(.empty))
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,22 @@ import Combine
|
||||||
final class ChatsMiddleware {
|
final class ChatsMiddleware {
|
||||||
static let shared = 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 {
|
switch action {
|
||||||
case .databaseAction(.storedChatsLoaded(let chats)):
|
case .databaseAction(.storedChatsLoaded(let chats)):
|
||||||
return Just(.chatsAction(.chatsListUpdated(chats: chats)))
|
return Just(.chatsAction(.chatsListUpdated(chats: chats)))
|
||||||
.eraseToAnyPublisher()
|
.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:
|
default:
|
||||||
return Empty().eraseToAnyPublisher()
|
return Empty().eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ private struct ChatsRow: View {
|
||||||
}
|
}
|
||||||
.sharedListRow()
|
.sharedListRow()
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
// state.startChat(chat)
|
store.dispatch(.chatsAction(.startChat(accountJid: chat.account, participantJid: chat.participant)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ private struct ContactsScreenRow: View {
|
||||||
}
|
}
|
||||||
.sharedListRow()
|
.sharedListRow()
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
// state.startChat(roster)
|
store.dispatch(.chatsAction(.startChat(accountJid: roster.bareJid, participantJid: roster.contactBareJid)))
|
||||||
}
|
}
|
||||||
.onLongPressGesture {
|
.onLongPressGesture {
|
||||||
isShowingMenu.toggle()
|
isShowingMenu.toggle()
|
||||||
|
@ -135,7 +135,7 @@ private struct ContactsScreenRow: View {
|
||||||
}
|
}
|
||||||
.contextMenu {
|
.contextMenu {
|
||||||
Button(L10n.Contacts.sendMessage, systemImage: "message") {
|
Button(L10n.Contacts.sendMessage, systemImage: "message") {
|
||||||
// state.startChat(roster)
|
store.dispatch(.chatsAction(.startChat(accountJid: roster.bareJid, participantJid: roster.contactBareJid)))
|
||||||
}
|
}
|
||||||
Divider()
|
Divider()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue