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)