wip
This commit is contained in:
parent
7ada932664
commit
3fc0be729e
|
@ -10,6 +10,7 @@ enum AppAction: Codable {
|
||||||
case rostersAction(_ action: RostersAction)
|
case rostersAction(_ action: RostersAction)
|
||||||
case chatsAction(_ action: ChatsAction)
|
case chatsAction(_ action: ChatsAction)
|
||||||
case conversationAction(_ action: ConversationAction)
|
case conversationAction(_ action: ConversationAction)
|
||||||
|
case messagesAction(_ action: MessagesAction)
|
||||||
case sharingAction(_ action: SharingAction)
|
case sharingAction(_ action: SharingAction)
|
||||||
case fileAction(_ action: FileAction)
|
case fileAction(_ action: FileAction)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
enum MessagesAction: Codable {
|
||||||
|
case currentConversationMessagesUpdated(messages: [Message])
|
||||||
|
}
|
|
@ -488,7 +488,7 @@ private extension DatabaseMiddleware {
|
||||||
} receiveValue: { messages in
|
} receiveValue: { messages in
|
||||||
// messages
|
// messages
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
store.dispatch(.conversationAction(.messagesUpdated(messages: messages)))
|
store.dispatch(.messagesAction(.currentConversationMessagesUpdated(messages: messages)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.store(in: &conversationCancellables)
|
.store(in: &conversationCancellables)
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
import Combine
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
final class MessagesMiddleware {
|
||||||
|
static let shared = MessagesMiddleware()
|
||||||
|
|
||||||
|
func middleware(state _: AppState, action: AppAction) -> AnyPublisher<AppAction, Never> {
|
||||||
|
switch action {
|
||||||
|
case .messagesAction(.currentConversationMessagesUpdated(let messages)):
|
||||||
|
return Just(.conversationAction(.messagesUpdated(messages: messages)))
|
||||||
|
.eraseToAnyPublisher()
|
||||||
|
|
||||||
|
default:
|
||||||
|
return Empty().eraseToAnyPublisher()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,7 +13,7 @@ extension AppState {
|
||||||
case .startAction(let action):
|
case .startAction(let action):
|
||||||
StartState.reducer(state: &state.startState, action: action)
|
StartState.reducer(state: &state.startState, action: action)
|
||||||
|
|
||||||
case .databaseAction, .xmppAction, .fileAction, .info:
|
case .databaseAction, .xmppAction, .fileAction, .info, .messagesAction:
|
||||||
break // this actions are processed by other middlewares
|
break // this actions are processed by other middlewares
|
||||||
|
|
||||||
case .accountsAction(let action):
|
case .accountsAction(let action):
|
||||||
|
|
|
@ -74,27 +74,31 @@ final class XMPPService: ObservableObject {
|
||||||
.store(in: &clientMessagesCancellables)
|
.store(in: &clientMessagesCancellables)
|
||||||
|
|
||||||
// enable carbons if available
|
// enable carbons if available
|
||||||
client.module(.messageCarbons).$isAvailable.filter { $0 }.sink(receiveValue: { [weak client] _ in
|
client.module(.messageCarbons).$isAvailable.filter { $0 }
|
||||||
client?.module(.messageCarbons).enable()
|
.sink(receiveValue: { [weak client] _ in
|
||||||
}).store(in: &clientMessagesCancellables)
|
client?.module(.messageCarbons).enable()
|
||||||
|
})
|
||||||
|
.store(in: &clientMessagesCancellables)
|
||||||
|
|
||||||
// MAM
|
// MAM
|
||||||
client.module(.mam).$availableVersions.sink(receiveValue: { [weak client] versions in
|
// client.module(.mam).$availableVersions.sink(receiveValue: { [weak client] versions in
|
||||||
guard !versions.isEmpty, let client = client else {
|
// guard !versions.isEmpty, let client = client else {
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
print("MAM available versions: \(versions)")
|
// print("MAM available versions: \(versions)")
|
||||||
// MessageEventHandler.syncMessagesScheduled(for: client)
|
// // MessageEventHandler.syncMessagesScheduled(for: client)
|
||||||
}).store(in: &clientMessagesCancellables)
|
// }).store(in: &clientMessagesCancellables)
|
||||||
|
|
||||||
client.module(.mam).archivedMessagesPublisher.sink(receiveValue: { archived in
|
client.module(.mam).archivedMessagesPublisher
|
||||||
print("MAM archived message: \(archived.message)")
|
.sink(receiveValue: { [weak self] archived in
|
||||||
|
self?.clientMessagesPublisher.send((client, archived.message))
|
||||||
// guard let conversation = MessageEventHandler.conversationKey(for: archived.message, on: account) else {
|
// print("MAM archived message: \(archived.message)")
|
||||||
// return
|
// guard let conversation = MessageEventHandler.conversationKey(for: archived.message, on: account) else {
|
||||||
// }
|
// return
|
||||||
// DBChatHistoryStore.instance.append(for: conversation, message: archived.message, source: .archive(source: archived.source, version: archived.query.version, messageId: archived.messageId, timestamp: archived.timestamp))
|
// }
|
||||||
}).store(in: &clientMessagesCancellables)
|
// DBChatHistoryStore.instance.append(for: conversation, message: archived.message, source: .archive(source: archived.source, version: archived.query.version, messageId: archived.messageId, timestamp: archived.timestamp))
|
||||||
|
})
|
||||||
|
.store(in: &clientMessagesCancellables)
|
||||||
|
|
||||||
// finally, do login
|
// finally, do login
|
||||||
client.login()
|
client.login()
|
||||||
|
|
|
@ -13,6 +13,7 @@ let store = AppStore(
|
||||||
XMPPMiddleware.shared.middleware,
|
XMPPMiddleware.shared.middleware,
|
||||||
RostersMiddleware.shared.middleware,
|
RostersMiddleware.shared.middleware,
|
||||||
ChatsMiddleware.shared.middleware,
|
ChatsMiddleware.shared.middleware,
|
||||||
|
MessagesMiddleware.shared.middleware,
|
||||||
ConversationMiddleware.shared.middleware,
|
ConversationMiddleware.shared.middleware,
|
||||||
SharingMiddleware.shared.middleware,
|
SharingMiddleware.shared.middleware,
|
||||||
FileMiddleware.shared.middleware
|
FileMiddleware.shared.middleware
|
||||||
|
|
Loading…
Reference in a new issue