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