Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Update logo queries (#2413)

Leendert de Borst828e4e6f0c37
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/queries/PasskeyQueries.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/queries/PasskeyQueries.kt
index da2691be2..8c6f6bfaa 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/queries/PasskeyQueries.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/queries/PasskeyQueries.kt
@@ -174,12 +174,11 @@ object LogoQueries {
"""
/**
- * The kind and key of an existing logo. Binds (id).
+ * The kind and key of an item's logo, which always lives in the item's own manifest. Binds (id, manifestId).
*/
const val GET_BY_ID = """
SELECT Id, Kind, Source, Name FROM Logos
- WHERE Id = ? AND IsDeleted = 0
- LIMIT 1
+ WHERE Id = ? AND ManifestId = ? AND IsDeleted = 0
"""
/**
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/repositories/PasskeyRepository.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/repositories/PasskeyRepository.kt
index a388556b5..7c9404e43 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/repositories/PasskeyRepository.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/repositories/PasskeyRepository.kt
@@ -453,7 +453,7 @@ class PasskeyRepository(database: VaultDatabase) : BaseRepository(database) {
* @return The logo id, or null when the item should keep what it has (update) or get none (create)
*/
private fun resolveLogoId(scope: String, existingLogoId: String?, url: String, logo: ByteArray?, timestamp: String): String? {
- val existing = existingLogoId?.let { getLogoById(it) }
+ val existing = existingLogoId?.let { getLogoById(it, scope) }
if (existing != null && existing.kind != LOGO_KIND_FAVICON) {
return ensureInScope(scope, existing.kind, existing.source, timestamp)
}
@@ -476,10 +476,10 @@ class PasskeyRepository(database: VaultDatabase) : BaseRepository(database) {
}
/**
- * The kind and key of a logo row, in whichever manifest holds it, or null when it no longer exists.
+ * The kind and key of an item's logo in the item's manifest, or null when it no longer exists.
*/
- private fun getLogoById(logoId: String): LogoRef? {
- val row = executeQuery(LogoQueries.GET_BY_ID, arrayOf(logoId)).firstOrNull() ?: return null
+ private fun getLogoById(logoId: String, manifestId: String): LogoRef? {
+ val row = executeQuery(LogoQueries.GET_BY_ID, arrayOf(logoId, manifestId)).firstOrNull() ?: return null
val source = row["Source"] as? String ?: return null
return LogoRef(row["Kind"] as? String ?: LOGO_KIND_FAVICON, source)
}
diff --git a/apps/mobile-app/ios/VaultStoreKit/Database/Queries/PasskeyQueries.swift b/apps/mobile-app/ios/VaultStoreKit/Database/Queries/PasskeyQueries.swift
index 727b3c236..8cdf74be5 100644
--- a/apps/mobile-app/ios/VaultStoreKit/Database/Queries/PasskeyQueries.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/Database/Queries/PasskeyQueries.swift
@@ -150,11 +150,10 @@ public struct LogoQueries {
LIMIT 1
"""
- /// The kind and key of an existing logo.
+ /// The kind and key of an item's logo, bound as [logoId, item manifest]; it always lives in the item's own manifest.
public static let getById = """
SELECT Id, Kind, Source, Name FROM Logos
- WHERE Id = ? AND IsDeleted = 0
- LIMIT 1
+ WHERE Id = ? AND ManifestId = ? AND IsDeleted = 0
"""
/// Insert or update a logo, bound as [id, kind, source, manifestId, fileData, mimeType, name, now, now].
diff --git a/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepository.swift b/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepository.swift
index 271c22dc9..dd54d78ed 100644
--- a/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepository.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepository.swift
@@ -265,9 +265,9 @@ public class PasskeyRepository: BaseRepository {
let name: String?
}
- /// The kind and key of an existing logo, or nil when it no longer exists.
- private func getLogo(byId logoId: String) throws -> (kind: String, source: String)? {
- guard let row = try client.executeQuery(LogoQueries.getById, params: [logoId]).first, let kind = row["Kind"] as? String, let source = row["Source"] as? String else {
+ /// The kind and key of an item's logo in the item's manifest, or nil when it no longer exists.
+ private func getLogo(byId logoId: String, manifestId: String) throws -> (kind: String, source: String)? {
+ guard let row = try client.executeQuery(LogoQueries.getById, params: [logoId, manifestId]).first, let kind = row["Kind"] as? String, let source = row["Source"] as? String else {
return nil
}
return (kind, source)
@@ -289,7 +289,7 @@ public class PasskeyRepository: BaseRepository {
/// a built-in or uploaded logo the user chose is kept, a favicon already on file for this domain is reused, fresh
/// bytes go under the domain's own row, and without a derivable domain the logo is left as it is.
private func resolveLogoId(existingLogoId: String?, manifestId: String, rpId: String, logo: Data?, now: String) throws -> String? {
- let existing = try existingLogoId.flatMap { try getLogo(byId: $0) }
+ let existing = try existingLogoId.flatMap { try getLogo(byId: $0, manifestId: manifestId) }
if let existing = existing, existing.kind != "favicon" {
return try ensureInScope(LogoKey(manifestId: manifestId, kind: existing.kind, source: existing.source), now: now)
}