This commit is contained in:
Woit 2024-11-28 17:34:41 +01:00
parent dce50cddca
commit ca5e4b930c

View file

@ -68,7 +68,21 @@ extension MonalXmppWrapper {
func chat(with: Chat) -> MonalChatWrapper? {
guard let account = accounts.first(where: { $0.id == with.accountId }) else { return nil }
guard let contact = contacts.first(where: { $0.ownerId == with.accountId && $0.contactJid == with.participantJid }) else { return nil }
var contact = contacts.first(where: { $0.ownerId == with.accountId && $0.contactJid == with.participantJid })
if contact == nil {
let semaphore = DispatchSemaphore(value: 0)
Task {
await addContact(contactJid: with.participantJid, forAccountID: with.accountId)
semaphore.signal()
}
semaphore.wait()
refreshChats()
refreshContacts()
contact = contacts.first(where: { $0.ownerId == with.accountId && $0.contactJid == with.participantJid })
}
guard let contact else { return nil }
let chatModel = MonalChatWrapper(account: account, contact: contact, db: db, xmpp: xmpp)
return chatModel
}