From 444545b1d81657a5587afdc2a48c98d4158983bb Mon Sep 17 00:00:00 2001 From: fmodf Date: Mon, 2 Sep 2024 17:53:54 +0200 Subject: [PATCH] wip --- .../AppData/Store/ClientsStore.swift | 12 ++++++++++++ .../View/Main/ChatList/ChatsListScreen.swift | 1 + 2 files changed, 13 insertions(+) diff --git a/ConversationsClassic/AppData/Store/ClientsStore.swift b/ConversationsClassic/AppData/Store/ClientsStore.swift index a6fd61f..58dc65c 100644 --- a/ConversationsClassic/AppData/Store/ClientsStore.swift +++ b/ConversationsClassic/AppData/Store/ClientsStore.swift @@ -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) { diff --git a/ConversationsClassic/View/Main/ChatList/ChatsListScreen.swift b/ConversationsClassic/View/Main/ChatList/ChatsListScreen.swift index 9dc70e6..cfae0c1 100644 --- a/ConversationsClassic/View/Main/ChatList/ChatsListScreen.swift +++ b/ConversationsClassic/View/Main/ChatList/ChatsListScreen.swift @@ -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)