This commit is contained in:
fmodf 2024-09-02 17:53:54 +02:00
parent fa0381e238
commit 444545b1d8
2 changed files with 13 additions and 0 deletions

View file

@ -105,6 +105,18 @@ extension ClientsStore {
}
}
extension ClientsStore {
func addRosterForNewChatIfNeeded(_ chat: Chat) async throws {
let exists = try? await chat.fetchRoster()
if exists == nil {
guard let client = clients.first(where: { $0.credentials.bareJid == chat.account }) else {
throw AppError.clientNotFound
}
try await addRoster(client.credentials, contactJID: chat.participant, name: nil, groups: [])
}
}
}
// MARK: - Produce stores for conversation
extension ClientsStore {
func conversationStores(for roster: Roster) async throws -> (MessagesStore, AttachmentsStore) {

View file

@ -60,6 +60,7 @@ private struct ChatsRow: View {
}
do {
try? await clientsStore.addRosterForNewChatIfNeeded(chat)
let (messages, attachments) = try await clientsStore.conversationStores(for: chat)
router.showScreen(.push) { _ in
ConversationScreen(messagesStore: messages, attachments: attachments)