add missing statistic

This commit is contained in:
otsmr 2026-05-15 15:36:20 +02:00
parent 78cdb9244c
commit d52f1eefea
2 changed files with 34 additions and 0 deletions

View file

@ -126,6 +126,35 @@ class KeyVerificationDao extends DatabaseAccessor<TwonlyDB>
return rows.length; return rows.length;
} }
Future<int> getCountOfContactsWithVerificationBadge() async {
final kv = keyVerifications;
final ur = userDiscoveryUserRelations;
final query = selectOnly(ur, distinct: true)
..addColumns([ur.announcedUserId])
..join([
innerJoin(contacts, contacts.userId.equalsExp(ur.fromContactId)),
innerJoin(kv, kv.contactId.equalsExp(ur.fromContactId)),
])
..where(
ur.publicKeyVerifiedTimestamp.isNotNull() &
ur.announcedUserId.equalsExp(ur.fromContactId).not(),
)
..groupBy([ur.announcedUserId]);
final rows = await query.get();
final transferredIds = rows.map((r) => r.read(ur.announcedUserId)!).toSet();
final directVerifications = await select(kv).get();
final directIds = directVerifications.map((v) => v.contactId).toSet();
// Reduce transferred contacts where announcedUserId is already in KeyVerifications
transferredIds.removeWhere(directIds.contains);
// Add count of all users who are in the KeyVerification table
return transferredIds.length + directIds.length;
}
Stream<VerificationStatus> watchAllGroupMembersVerified(String groupId) { Stream<VerificationStatus> watchAllGroupMembersVerified(String groupId) {
final gm = groupMembers; final gm = groupMembers;
final directKv = alias(keyVerifications, 'directKv'); final directKv = alias(keyVerifications, 'directKv');

View file

@ -49,6 +49,9 @@ Future<void> handleUserStudyUpload() async {
final udVerifiedByContactsCount = await twonlyDB.keyVerificationDao final udVerifiedByContactsCount = await twonlyDB.keyVerificationDao
.getTransferredTrustVerificationsCount(); .getTransferredTrustVerificationsCount();
final totalContactsWithVerificationBadge = await twonlyDB.keyVerificationDao
.getCountOfContactsWithVerificationBadge();
final udFriendsShared = await twonlyDB.contactsDao final udFriendsShared = await twonlyDB.contactsDao
.getContactsAnnouncedViaUserDiscovery(); .getContactsAnnouncedViaUserDiscovery();
@ -87,6 +90,8 @@ Future<void> handleUserStudyUpload() async {
'accepted_contacts': contacts.where((c) => c.accepted).length, 'accepted_contacts': contacts.where((c) => c.accepted).length,
'verified_contacts': verifications.length, 'verified_contacts': verifications.length,
'total_contacts_with_verification_badge':
totalContactsWithVerificationBadge,
'verified_contacts_via_migrated_from_old_version': verifications.values 'verified_contacts_via_migrated_from_old_version': verifications.values
.where((c) => c == VerificationType.migratedFromOldVersion) .where((c) => c == VerificationType.migratedFromOldVersion)
.length, .length,