This commit is contained in:
fmodf 2024-09-16 14:10:35 +02:00
parent edf1b8782c
commit 40ebe72e1b
3 changed files with 21 additions and 0 deletions

View file

@ -77,6 +77,18 @@ extension Client {
) )
} }
func addRosterLocally(_ jid: String, name: String?, groups: [String]) async throws {
try await Roster.addRosterLocally(.init(
bareJid: credentials.bareJid,
contactBareJid: jid,
name: name,
subscription: "to",
ask: true,
data: .init(groups: groups, annotations: []),
locallyDeleted: false
))
}
func deleteRoster(_ roster: Roster) async throws { func deleteRoster(_ roster: Roster) async throws {
_ = try await connection.module(.roster).removeItem(jid: JID(roster.contactBareJid)) _ = try await connection.module(.roster).removeItem(jid: JID(roster.contactBareJid))
} }

View file

@ -101,4 +101,10 @@ extension Roster {
} }
} }
} }
static func addRosterLocally(_ roster: Roster) async throws {
try await Database.shared.dbQueue.write { db in
try roster.save(db)
}
}
} }

View file

@ -113,6 +113,9 @@ extension ClientsStore {
throw AppError.clientNotFound throw AppError.clientNotFound
} }
try await addRoster(client.credentials, contactJID: chat.participant, name: nil, groups: []) try await addRoster(client.credentials, contactJID: chat.participant, name: nil, groups: [])
// Hack here. Because we want to show chat immediately after adding roster (without waiting for server
// response and update rosters list) we need to write it to db manually
try await client.addRosterLocally(chat.participant, name: nil, groups: [])
} }
} }
} }