mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-05-25 02:12:13 +00:00
when user is excluded from find friend all promotions are now also removed
This commit is contained in:
parent
eed5d292c6
commit
919aec464e
4 changed files with 39 additions and 14 deletions
|
|
@ -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 {
|
static Future<void> disable() async {
|
||||||
await updateUser((u) {
|
await updateUser((u) {
|
||||||
u.isUserDiscoveryEnabled = false;
|
u.isUserDiscoveryEnabled = false;
|
||||||
|
|
|
||||||
|
|
@ -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/daos/contacts.dao.dart';
|
||||||
import 'package:twonly/src/database/tables/contacts.table.dart';
|
import 'package:twonly/src/database/tables/contacts.table.dart';
|
||||||
import 'package:twonly/src/database/twonly.db.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/utils/misc.dart';
|
||||||
import 'package:twonly/src/visual/components/alert.dialog.dart';
|
import 'package:twonly/src/visual/components/alert.dialog.dart';
|
||||||
import 'package:twonly/src/visual/components/avatar_icon.comp.dart';
|
import 'package:twonly/src/visual/components/avatar_icon.comp.dart';
|
||||||
|
|
@ -324,9 +325,9 @@ class _ContactViewState extends State<ContactView> {
|
||||||
child: Switch(
|
child: Switch(
|
||||||
value: !contact.userDiscoveryExcluded,
|
value: !contact.userDiscoveryExcluded,
|
||||||
onChanged: (a) async {
|
onChanged: (a) async {
|
||||||
await twonlyDB.contactsDao.updateContact(
|
await UserDiscoveryService.changeExclusionForContact(
|
||||||
contact.userId,
|
contact.userId,
|
||||||
ContactsCompanion(userDiscoveryExcluded: Value(!a)),
|
!a,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:drift/drift.dart' show Value;
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
@ -135,14 +134,11 @@ class _UserDiscoveryEnabledCompState extends State<UserDiscoveryEnabledComp> {
|
||||||
context.lang.userDiscoveryEnabledStopSharing,
|
context.lang.userDiscoveryEnabledStopSharing,
|
||||||
style: const TextStyle(fontSize: 10),
|
style: const TextStyle(fontSize: 10),
|
||||||
),
|
),
|
||||||
onPressed: () async {
|
onPressed: () =>
|
||||||
await twonlyDB.contactsDao.updateContact(
|
UserDiscoveryService.changeExclusionForContact(
|
||||||
contact.userId,
|
contact.userId,
|
||||||
const ContactsCompanion(
|
true,
|
||||||
userDiscoveryExcluded: Value(true),
|
|
||||||
),
|
),
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -216,10 +216,13 @@ impl<Store: UserDiscoveryStore, Utils: UserDiscoveryUtils> UserDiscovery<Store,
|
||||||
}
|
}
|
||||||
if received_version.promotion < config.promotion_version {
|
if received_version.promotion < config.promotion_version {
|
||||||
tracing::info!("New promotion message available for user {}", contact_id);
|
tracing::info!("New promotion message available for user {}", contact_id);
|
||||||
let promoting_messages = self
|
let promoting_messages: Vec<Vec<u8>> = self
|
||||||
.store
|
.store
|
||||||
.get_own_promotions_after_version(received_version.promotion)
|
.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);
|
messages.extend_from_slice(&promoting_messages);
|
||||||
}
|
}
|
||||||
Ok(messages)
|
Ok(messages)
|
||||||
|
|
@ -281,7 +284,10 @@ impl<Store: UserDiscoveryStore, Utils: UserDiscoveryUtils> UserDiscovery<Store,
|
||||||
messages: Vec<Vec<u8>>,
|
messages: Vec<Vec<u8>>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for message in messages {
|
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 {
|
let Some(version) = message.version else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
@ -302,7 +308,7 @@ impl<Store: UserDiscoveryStore, Utils: UserDiscoveryUtils> UserDiscovery<Store,
|
||||||
tracing::warn!("Ignoring: {err}");
|
tracing::warn!("Ignoring: {err}");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tracing::warn!("Got unknown user discovery messaging. Ignoring it.");
|
tracing::info!("Got unknown user discovery messaging. Ignoring it.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue