This commit is contained in:
fmodf 2024-07-14 19:08:43 +02:00
parent cb1f159a7a
commit c1ce9b133d
4 changed files with 53 additions and 7 deletions

View file

@ -5,4 +5,6 @@ enum ConversationAction: Codable {
case sendMessage(from: String, to: String, body: String)
case setReplyText(String)
case sendMediaMessages(from: String, to: String, messagesIds: [String], localFilesNames: [String])
}

View file

@ -355,6 +355,44 @@ final class DatabaseMiddleware {
}
.eraseToAnyPublisher()
case .conversationAction(.sendMediaMessages(let from, let to, let messageIds, let localFilesNames)):
return Future<AppAction, Never> { promise in
Task(priority: .background) { [weak self] in
guard let database = self?.database else {
promise(.success(.databaseAction(.storeMessageFailed(reason: L10n.Global.Error.genericDbError)))
)
return
}
do {
for (index, id) in messageIds.enumerated() {
let message = Message(
id: id,
type: .chat,
contentType: .attachment,
from: from,
to: to,
body: nil,
subject: nil,
thread: nil,
oobUrl: nil,
date: Date(),
pending: true,
sentError: false,
attachmentLocalName: localFilesNames[index]
)
try database._db.write { db in
try message.insert(db)
}
}
promise(.success(.empty))
} catch {
promise(.success(.databaseAction(.storeMessageFailed(reason: error.localizedDescription)))
)
}
}
}
.eraseToAnyPublisher()
default:
return Empty().eraseToAnyPublisher()
}

View file

@ -85,13 +85,6 @@ final class FileMiddleware {
}
.eraseToAnyPublisher()
case .fileAction(.galleryItemsCopiedForUploading(let newMessageIds, let localNames)):
print("!!!!!!")
print(newMessageIds)
print(localNames)
print("!!!!!!")
return Empty().eraseToAnyPublisher()
default:
return Empty().eraseToAnyPublisher()
}

View file

@ -69,6 +69,19 @@ final class SharingMiddleware {
print("Camera captured: \(media.count)")
return Empty().eraseToAnyPublisher()
case .fileAction(.galleryItemsCopiedForUploading(let newMessageIds, let localNames)):
if let chat = state.conversationsState.currentChat {
return Just(.conversationAction(.sendMediaMessages(
from: chat.account,
to: chat.participant,
messagesIds: newMessageIds,
localFilesNames: localNames
)))
.eraseToAnyPublisher()
} else {
return Empty().eraseToAnyPublisher()
}
case .sharingAction(.shareLocation(let lat, let lon)):
if let chat = state.conversationsState.currentChat {
let msg = "geo:\(lat),\(lon)"