Limit new DM thread creation to people the user follows or mutual (back end errors out if not connected)

merge-requests/71/head
Hank Grabowski 2025-07-24 15:06:49 -04:00
rodzic 00cd377ae2
commit adcb40baf4
6 zmienionych plików z 53 dodań i 12 usunięć

Wyświetl plik

@ -13,10 +13,12 @@ class MentionAutocompleteOptions extends ConsumerWidget {
required this.id, required this.id,
required this.query, required this.query,
required this.onMentionUserTap, required this.onMentionUserTap,
this.matchingStatus,
}); });
final String id; final String id;
final String query; final String query;
final Set<ConnectionStatus>? matchingStatus;
final ValueSetter<Connection> onMentionUserTap; final ValueSetter<Connection> onMentionUserTap;
@override @override
@ -25,13 +27,17 @@ class MentionAutocompleteOptions extends ConsumerWidget {
final postTreeUsers = ref final postTreeUsers = ref
.watch(postTreeConnectionIdsProvider(profile, id)) .watch(postTreeConnectionIdsProvider(profile, id))
.getValueOrElse(() => []) .getValueOrElse(() => [])
.map((id) => ref.watch(connectionByIdProvider(profile, id))) .map((id) => ref.read(connectionByIdProvider(profile, id)))
.where((result) => result.isSuccess) .where((result) => result.isSuccess)
.map((result) => result.value) .map((result) => result.value)
.toList() .toList()
..sort((u1, u2) => u1.name.compareTo(u2.name)); ..sort((u1, u2) => u1.name.compareTo(u2.name));
final knownUsers = ref.watch(knownUsersByNameProvider(profile, query)); final knownUsers = ref.watch(knownUsersByNameProvider(
profile,
query,
matchingStatus: matchingStatus,
));
final users = [...postTreeUsers, ...knownUsers]; final users = [...postTreeUsers, ...knownUsers];

Wyświetl plik

@ -41,7 +41,10 @@ Result<List<String>, ExecError> postTreeConnectionIds(
_ptcLogger.info('Building for $id for $profile'); _ptcLogger.info('Building for $id for $profile');
ref.cacheFor(_cacheDuration); ref.cacheFor(_cacheDuration);
return ref return ref
.watch(postTreeEntryByIdProvider(profile, id)) .watch(postTreeEntryByIdProvider(
profile,
id,
))
.transform( .transform(
(entryTreeItem) => entryTreeItem (entryTreeItem) => entryTreeItem
.flatten(ref: ref, profile: profile) .flatten(ref: ref, profile: profile)

Wyświetl plik

@ -71,9 +71,19 @@ Future<bool> connectionRepoInit(Ref ref, Profile profile) async {
} }
@riverpod @riverpod
List<Connection> knownUsersByName(Ref ref, Profile profile, String userName) { List<Connection> knownUsersByName(Ref ref, Profile profile, String userName,
{Set<ConnectionStatus>? matchingStatus}) {
return ref.watch(_connectionsRepoSyncProvider(profile)).fold( return ref.watch(_connectionsRepoSyncProvider(profile)).fold(
onSuccess: (repo) => repo.getKnownUsersByName(userName), onSuccess: (repo) {
final knownUsers = repo.getKnownUsersByName(userName);
if (matchingStatus == null) {
return knownUsers;
}
return knownUsers
.where((u) => matchingStatus.contains(u.status))
.toList();
},
onError: (_) => []); onError: (_) => []);
} }

Wyświetl plik

@ -288,7 +288,7 @@ class _ConnectionRepoInitProviderElement
Profile get profile => (origin as ConnectionRepoInitProvider).profile; Profile get profile => (origin as ConnectionRepoInitProvider).profile;
} }
String _$knownUsersByNameHash() => r'564fbbf69fcc62f0c18c8ec98e8a0382df95f8a3'; String _$knownUsersByNameHash() => r'89ebe37e2257f9124b614b3aeddc81213ec41475';
/// See also [knownUsersByName]. /// See also [knownUsersByName].
@ProviderFor(knownUsersByName) @ProviderFor(knownUsersByName)
@ -302,11 +302,13 @@ class KnownUsersByNameFamily extends Family<List<Connection>> {
/// See also [knownUsersByName]. /// See also [knownUsersByName].
KnownUsersByNameProvider call( KnownUsersByNameProvider call(
Profile profile, Profile profile,
String userName, String userName, {
) { Set<ConnectionStatus>? matchingStatus,
}) {
return KnownUsersByNameProvider( return KnownUsersByNameProvider(
profile, profile,
userName, userName,
matchingStatus: matchingStatus,
); );
} }
@ -317,6 +319,7 @@ class KnownUsersByNameFamily extends Family<List<Connection>> {
return call( return call(
provider.profile, provider.profile,
provider.userName, provider.userName,
matchingStatus: provider.matchingStatus,
); );
} }
@ -340,12 +343,14 @@ class KnownUsersByNameProvider extends AutoDisposeProvider<List<Connection>> {
/// See also [knownUsersByName]. /// See also [knownUsersByName].
KnownUsersByNameProvider( KnownUsersByNameProvider(
Profile profile, Profile profile,
String userName, String userName, {
) : this._internal( Set<ConnectionStatus>? matchingStatus,
}) : this._internal(
(ref) => knownUsersByName( (ref) => knownUsersByName(
ref as KnownUsersByNameRef, ref as KnownUsersByNameRef,
profile, profile,
userName, userName,
matchingStatus: matchingStatus,
), ),
from: knownUsersByNameProvider, from: knownUsersByNameProvider,
name: r'knownUsersByNameProvider', name: r'knownUsersByNameProvider',
@ -358,6 +363,7 @@ class KnownUsersByNameProvider extends AutoDisposeProvider<List<Connection>> {
KnownUsersByNameFamily._allTransitiveDependencies, KnownUsersByNameFamily._allTransitiveDependencies,
profile: profile, profile: profile,
userName: userName, userName: userName,
matchingStatus: matchingStatus,
); );
KnownUsersByNameProvider._internal( KnownUsersByNameProvider._internal(
@ -369,10 +375,12 @@ class KnownUsersByNameProvider extends AutoDisposeProvider<List<Connection>> {
required super.from, required super.from,
required this.profile, required this.profile,
required this.userName, required this.userName,
required this.matchingStatus,
}) : super.internal(); }) : super.internal();
final Profile profile; final Profile profile;
final String userName; final String userName;
final Set<ConnectionStatus>? matchingStatus;
@override @override
Override overrideWith( Override overrideWith(
@ -389,6 +397,7 @@ class KnownUsersByNameProvider extends AutoDisposeProvider<List<Connection>> {
debugGetCreateSourceHash: null, debugGetCreateSourceHash: null,
profile: profile, profile: profile,
userName: userName, userName: userName,
matchingStatus: matchingStatus,
), ),
); );
} }
@ -402,7 +411,8 @@ class KnownUsersByNameProvider extends AutoDisposeProvider<List<Connection>> {
bool operator ==(Object other) { bool operator ==(Object other) {
return other is KnownUsersByNameProvider && return other is KnownUsersByNameProvider &&
other.profile == profile && other.profile == profile &&
other.userName == userName; other.userName == userName &&
other.matchingStatus == matchingStatus;
} }
@override @override
@ -410,6 +420,7 @@ class KnownUsersByNameProvider extends AutoDisposeProvider<List<Connection>> {
var hash = _SystemHash.combine(0, runtimeType.hashCode); var hash = _SystemHash.combine(0, runtimeType.hashCode);
hash = _SystemHash.combine(hash, profile.hashCode); hash = _SystemHash.combine(hash, profile.hashCode);
hash = _SystemHash.combine(hash, userName.hashCode); hash = _SystemHash.combine(hash, userName.hashCode);
hash = _SystemHash.combine(hash, matchingStatus.hashCode);
return _SystemHash.finish(hash); return _SystemHash.finish(hash);
} }
@ -423,6 +434,9 @@ mixin KnownUsersByNameRef on AutoDisposeProviderRef<List<Connection>> {
/// The parameter `userName` of this provider. /// The parameter `userName` of this provider.
String get userName; String get userName;
/// The parameter `matchingStatus` of this provider.
Set<ConnectionStatus>? get matchingStatus;
} }
class _KnownUsersByNameProviderElement class _KnownUsersByNameProviderElement
@ -434,6 +448,9 @@ class _KnownUsersByNameProviderElement
Profile get profile => (origin as KnownUsersByNameProvider).profile; Profile get profile => (origin as KnownUsersByNameProvider).profile;
@override @override
String get userName => (origin as KnownUsersByNameProvider).userName; String get userName => (origin as KnownUsersByNameProvider).userName;
@override
Set<ConnectionStatus>? get matchingStatus =>
(origin as KnownUsersByNameProvider).matchingStatus;
} }
String _$myContactsHash() => r'd627cbc98c66e636fdf057ef7d946b5b0248d2a9'; String _$myContactsHash() => r'd627cbc98c66e636fdf057ef7d946b5b0248d2a9';

Wyświetl plik

@ -495,7 +495,7 @@ class _CreateCircleProviderElement extends AutoDisposeFutureProviderElement<
String get title => (origin as CreateCircleProvider).title; String get title => (origin as CreateCircleProvider).title;
} }
String _$renameCircleHash() => r'4bb3b90fc0dc47b59a1154e55857ec21b98fa622'; String _$renameCircleHash() => r'aee93f520a0021c8eb2e17d1ec0d7142b204abcd';
/// See also [renameCircle]. /// See also [renameCircle].
@ProviderFor(renameCircle) @ProviderFor(renameCircle)

Wyświetl plik

@ -6,6 +6,7 @@ import 'package:multi_trigger_autocomplete/multi_trigger_autocomplete.dart';
import '../controls/autocomplete/mention_autocomplete_options.dart'; import '../controls/autocomplete/mention_autocomplete_options.dart';
import '../controls/padding.dart'; import '../controls/padding.dart';
import '../controls/standard_appbar.dart'; import '../controls/standard_appbar.dart';
import '../models/connection.dart';
import '../riverpod_controllers/account_services.dart'; import '../riverpod_controllers/account_services.dart';
import '../riverpod_controllers/connection_manager_services.dart'; import '../riverpod_controllers/connection_manager_services.dart';
import '../riverpod_controllers/direct_message_services.dart'; import '../riverpod_controllers/direct_message_services.dart';
@ -52,6 +53,10 @@ class MessagesNewThread extends ConsumerWidget {
return MentionAutocompleteOptions( return MentionAutocompleteOptions(
id: '', id: '',
query: autocompleteQuery.query, query: autocompleteQuery.query,
matchingStatus: const {
ConnectionStatus.mutual,
ConnectionStatus.youFollowThem
},
onMentionUserTap: (user) { onMentionUserTap: (user) {
final autocomplete = final autocomplete =
MultiTriggerAutocomplete.of(context); MultiTriggerAutocomplete.of(context);