remove mam for a while
This commit is contained in:
parent
a567c210c4
commit
eed175fe1f
|
@ -7,6 +7,4 @@ enum ConversationAction: Codable {
|
|||
case setReplyText(String)
|
||||
|
||||
case sendMediaMessages(from: String, to: String, messagesIds: [String], localFilesNames: [String])
|
||||
|
||||
case setArchivedMessagesRequested
|
||||
}
|
||||
|
|
|
@ -4,44 +4,46 @@ import Foundation
|
|||
final class ArchivedMessagesMiddleware {
|
||||
static let shared = ArchivedMessagesMiddleware()
|
||||
|
||||
func middleware(state: AppState, action: AppAction) -> AnyPublisher<AppAction, Never> {
|
||||
func middleware(state _: AppState, action: AppAction) -> AnyPublisher<AppAction, Never> {
|
||||
switch action {
|
||||
case .conversationAction(.messagesUpdated(let messages)):
|
||||
if state.conversationsState.archivedMessagesRequested {
|
||||
return Empty().eraseToAnyPublisher()
|
||||
} else {
|
||||
guard let chat = state.conversationsState.currentChat else {
|
||||
return Empty().eraseToAnyPublisher()
|
||||
}
|
||||
return Deferred {
|
||||
Future<AppAction, Never> { promise in
|
||||
if let currentClient = state.accountsState.accounts.first(where: { $0.bareJid == chat.account }) {
|
||||
let features = state.accountsState.discoFeatures[currentClient.bareJid] ?? []
|
||||
if features.map({ $0.xep }).contains("XEP-0313") {
|
||||
let roster = chat.participant
|
||||
if let lastMessage = state.conversationsState.currentMessages.first {
|
||||
promise(.success(.xmppAction(.xmppLoadArchivedMessages(jid: currentClient.bareJid, to: roster?.bareJid, fromDate: lastMessage.date))))
|
||||
} else {
|
||||
let date = Date()
|
||||
let archivesRequestDate = Calendar.current.date(byAdding: .day, value: -Const.mamRequestLength, to: date) ?? date
|
||||
promise(.success(.xmppAction(.xmppLoadArchivedMessages(jid: currentClient.bareJid, to: roster?.bareJid, fromDate: archivesRequestDate))))
|
||||
}
|
||||
// let oldestMessageDate = state.conversationsState.currentMessages.first?.date ?? Date()
|
||||
// let archivesRequestDate = Calendar.current.date(byAdding: .day, value: -Const.mamRequestLength, to: oldestMessageDate) ?? Date()
|
||||
// promise(.success(.xmppAction(.xmppLoadArchivedMessages(jid: currentClient.bareJid, to: roster?.bareJid, fromDate: archivesRequestDate))))
|
||||
} else {
|
||||
promise(.success(.info("MessageMiddleware: XEP-0313 not supported for client \(currentClient.bareJid)")))
|
||||
}
|
||||
} else {
|
||||
promise(.success(.info("MessageMiddleware: No client found for account \(chat.account), probably some error here")))
|
||||
}
|
||||
}
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
// case .conversationAction(.messagesUpdated(let messages)):
|
||||
// if state.conversationsState.archivedMessagesRequested {
|
||||
// return Empty().eraseToAnyPublisher()
|
||||
// } else {
|
||||
// guard let chat = state.conversationsState.currentChat else {
|
||||
// return Empty().eraseToAnyPublisher()
|
||||
// }
|
||||
// return Deferred {
|
||||
// Future<AppAction, Never> { promise in
|
||||
// if let currentClient = state.accountsState.accounts.first(where: { $0.bareJid == chat.account }) {
|
||||
// let features = state.accountsState.discoFeatures[currentClient.bareJid] ?? []
|
||||
// if features.map({ $0.xep }).contains("XEP-0313") {
|
||||
// let roster = state.conversationsState.currentRoster
|
||||
// let date = self.archivesRequestDate(from: messages)
|
||||
// promise(.success(.xmppAction(.xmppLoadArchivedMessages(jid: currentClient.bareJid, to: roster?.bareJid, fromDate: date))))
|
||||
// } else {
|
||||
// promise(.success(.info("MessageMiddleware: XEP-0313 not supported for client \(currentClient.bareJid)")))
|
||||
// }
|
||||
// } else {
|
||||
// promise(.success(.info("MessageMiddleware: No client found for account \(chat.account), probably some error here")))
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// .eraseToAnyPublisher()
|
||||
// }
|
||||
|
||||
default:
|
||||
return Empty().eraseToAnyPublisher()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension ArchivedMessagesMiddleware {
|
||||
func archivesRequestDate(from messages: [Message]) -> Date {
|
||||
if let lastDate = messages.first?.date {
|
||||
return lastDate
|
||||
} else {
|
||||
return Calendar.current.date(byAdding: .day, value: -Const.mamRequestLength, to: Date()) ?? Date()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,13 +144,14 @@ final class XMPPMiddleware {
|
|||
.eraseToAnyPublisher()
|
||||
|
||||
case .xmppAction(.xmppLoadArchivedMessages(let jid, let to, let fromDate)):
|
||||
return Deferred {
|
||||
Future<AppAction, Never> { [weak self] promise in
|
||||
self?.service.requestArchivedMessages(jid: jid, to: to, fromDate: fromDate)
|
||||
promise(.success(.conversationAction(.setArchivedMessagesRequested)))
|
||||
}
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
return Empty().eraseToAnyPublisher()
|
||||
// return Deferred {
|
||||
// Future<AppAction, Never> { [weak self] promise in
|
||||
// self?.service.requestArchivedMessages(jid: jid, to: to, fromDate: fromDate)
|
||||
// promise(.success(.conversationAction(.setArchivedMessagesRequested)))
|
||||
// }
|
||||
// }
|
||||
// .eraseToAnyPublisher()
|
||||
|
||||
default:
|
||||
return Empty().eraseToAnyPublisher()
|
||||
|
|
|
@ -17,9 +17,6 @@ extension ConversationState {
|
|||
state.replyText = text.makeReply
|
||||
}
|
||||
|
||||
case .setArchivedMessagesRequested:
|
||||
state.archivedMessagesRequested = true
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ struct ConversationState: Stateable {
|
|||
var currentMessages: [Message]
|
||||
|
||||
var replyText: String
|
||||
|
||||
var archivedMessagesRequested: Bool
|
||||
}
|
||||
|
||||
// MARK: Init
|
||||
|
@ -13,6 +11,5 @@ extension ConversationState {
|
|||
init() {
|
||||
currentMessages = []
|
||||
replyText = ""
|
||||
archivedMessagesRequested = false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,13 +77,13 @@ final class XMPPService: ObservableObject {
|
|||
.store(in: &clientMessagesCancellables)
|
||||
|
||||
// subscribe to archived messages
|
||||
client.module(.mam).archivedMessagesPublisher
|
||||
.sink(receiveValue: { [weak self] archived in
|
||||
let message = archived.message
|
||||
message.attribute("archived_date", newValue: "\(archived.timestamp.timeIntervalSince1970)")
|
||||
self?.clientMessagesPublisher.send((client, message))
|
||||
})
|
||||
.store(in: &clientMessagesCancellables)
|
||||
// client.module(.mam).archivedMessagesPublisher
|
||||
// .sink(receiveValue: { [weak self] archived in
|
||||
// let message = archived.message
|
||||
// message.attribute("archived_date", newValue: "\(archived.timestamp.timeIntervalSince1970)")
|
||||
// self?.clientMessagesPublisher.send((client, message))
|
||||
// })
|
||||
// .store(in: &clientMessagesCancellables)
|
||||
|
||||
// enable carbons if available
|
||||
client.module(.messageCarbons).$isAvailable.filter { $0 }
|
||||
|
|
Loading…
Reference in a new issue