Vertex follows who follow impl

This commit is contained in:
franzap
2025-01-15 17:00:44 -03:00
parent cf319079ad
commit 98da76f1d3
3 changed files with 20 additions and 21 deletions
+4
View File
@@ -14,6 +14,7 @@ import 'package:zapstore/widgets/latest_releases_container.dart';
// const kAppRelays = {'ws://10.0.2.2:3000'};
const kAppRelays = {'wss://relay.zapstore.dev'};
const kSocialRelays = {'wss://relay.damus.io', 'wss://relay.primal.net', 'ndk'};
const kVertexRelay = {'wss://relay.vertexlab.io'};
mixin NostrAdapter<T extends DataModelMixin<T>> on Adapter<T> {
RelayMessageNotifier get relay =>
@@ -22,6 +23,9 @@ mixin NostrAdapter<T extends DataModelMixin<T>> on Adapter<T> {
RelayMessageNotifier get socialRelays =>
ref.read(relayProviderFamily(kSocialRelays).notifier);
RelayMessageNotifier get vertexRelay =>
ref.read(relayProviderFamily(kVertexRelay).notifier);
@override
Future<void> onInitialized() async {
await super.onInitialized();
+14 -20
View File
@@ -226,26 +226,20 @@ mixin UserAdapter on NostrAdapter<User> {
return super.deserialize(data);
}
Future<List<User>> getTrusted(String npub1, String npub2) async {
final url = 'https://trustgraph.live/api/fwf/$npub1/$npub2';
final users = await sendRequest(
Uri.parse(url),
onSuccess: (response, label) async {
if (response.body == null) return null;
final map =
Map<String, dynamic>.from(jsonDecode(response.body.toString()));
final trustedKeys = map.keys.map((npub) => npub.hexKey);
return await findAll(
params: {'authors': trustedKeys},
onSuccess: (response, label, adapter) {
final data = deserialize(response.body);
return data.models;
},
);
},
);
return users!;
Future<List<User>> getFollowsWhoFollow(String npub1, String npub2) async {
final search = jsonEncode({
'source': npub1.hexKey,
'targets': [npub2.hexKey]
});
final response = await ref.users.nostrAdapter.vertexRelay
.queryRaw(base.RelayRequest(kinds: {6312, 7000}, search: search));
if (response.isEmpty || response.first['kind'] == 7000) {
return [];
}
final result = response.first['content'];
final pubkeyList = (jsonDecode(result) as List).map((e) => e['pubkey']);
final users = await findAll(params: {'authors': pubkeyList});
return users;
}
}
@@ -59,6 +59,7 @@ class FollowsWhoFollowContainer extends HookConsumerWidget {
final followsWhoFollowProvider = FutureProvider.autoDispose
.family<List<User>, ({String from, String to})>((ref, arg) async {
final _ = ref.watch(signedInUserProvider);
final users = await ref.users.userAdapter.getTrusted(arg.from, arg.to);
final users =
await ref.users.userAdapter.getFollowsWhoFollow(arg.from, arg.to);
return users.toSet().toList();
});