when user is excluded from find friend all promotions are now also removed

This commit is contained in:
otsmr 2026-04-24 13:56:17 +02:00
parent eed5d292c6
commit 919aec464e
4 changed files with 39 additions and 14 deletions

View file

@ -145,6 +145,28 @@ class UserDiscoveryService {
}
}
static Future<void> changeExclusionForContact(
int contactId,
bool exclude,
) async {
// Remove old versions from the user...
await (twonlyDB.update(
twonlyDB.userDiscoveryOwnPromotions,
)..where((t) => t.contactId.equals(contactId))).write(
UserDiscoveryOwnPromotionsCompanion(promotion: Value(Uint8List(0))),
);
await twonlyDB.contactsDao.updateContact(
contactId,
ContactsCompanion(
userDiscoveryExcluded: Value(exclude),
userDiscoveryVersion: const Value(
null, // If the user is included again, this will trigger a new request of his original announcement
),
),
);
}
static Future<void> disable() async {
await updateUser((u) {
u.isUserDiscoveryEnabled = false;

View file

@ -10,6 +10,7 @@ import 'package:twonly/src/constants/routes.keys.dart';
import 'package:twonly/src/database/daos/contacts.dao.dart';
import 'package:twonly/src/database/tables/contacts.table.dart';
import 'package:twonly/src/database/twonly.db.dart';
import 'package:twonly/src/services/user_discovery.service.dart';
import 'package:twonly/src/utils/misc.dart';
import 'package:twonly/src/visual/components/alert.dialog.dart';
import 'package:twonly/src/visual/components/avatar_icon.comp.dart';
@ -324,9 +325,9 @@ class _ContactViewState extends State<ContactView> {
child: Switch(
value: !contact.userDiscoveryExcluded,
onChanged: (a) async {
await twonlyDB.contactsDao.updateContact(
await UserDiscoveryService.changeExclusionForContact(
contact.userId,
ContactsCompanion(userDiscoveryExcluded: Value(!a)),
!a,
);
},
),

View file

@ -1,6 +1,5 @@
import 'dart:async';
import 'package:drift/drift.dart' show Value;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
@ -135,14 +134,11 @@ class _UserDiscoveryEnabledCompState extends State<UserDiscoveryEnabledComp> {
context.lang.userDiscoveryEnabledStopSharing,
style: const TextStyle(fontSize: 10),
),
onPressed: () async {
await twonlyDB.contactsDao.updateContact(
contact.userId,
const ContactsCompanion(
userDiscoveryExcluded: Value(true),
onPressed: () =>
UserDiscoveryService.changeExclusionForContact(
contact.userId,
true,
),
);
},
),
),
),

View file

@ -216,10 +216,13 @@ impl<Store: UserDiscoveryStore, Utils: UserDiscoveryUtils> UserDiscovery<Store,
}
if received_version.promotion < config.promotion_version {
tracing::info!("New promotion message available for user {}", contact_id);
let promoting_messages = self
let promoting_messages: Vec<Vec<u8>> = self
.store
.get_own_promotions_after_version(received_version.promotion)
.await?;
.await?
.into_iter()
.filter(|x| x.is_empty()) // filter ignored versions
.collect();
messages.extend_from_slice(&promoting_messages);
}
Ok(messages)
@ -281,7 +284,10 @@ impl<Store: UserDiscoveryStore, Utils: UserDiscoveryUtils> UserDiscovery<Store,
messages: Vec<Vec<u8>>,
) -> Result<()> {
for message in messages {
let message = UserDiscoveryMessage::decode(message.as_slice())?;
let Ok(message) = UserDiscoveryMessage::decode(message.as_slice()) else {
tracing::error!("Could not parse the message. Continue to the next message...");
continue;
};
let Some(version) = message.version else {
continue;
};
@ -302,7 +308,7 @@ impl<Store: UserDiscoveryStore, Utils: UserDiscoveryUtils> UserDiscovery<Store,
tracing::warn!("Ignoring: {err}");
}
} else {
tracing::warn!("Got unknown user discovery messaging. Ignoring it.");
tracing::info!("Got unknown user discovery messaging. Ignoring it.");
continue;
}