From 39846e317e0ea79c5290c0d339cd0dda563fc550 Mon Sep 17 00:00:00 2001 From: Fmar <_@fmar.link> Date: Mon, 4 Dec 2023 13:15:04 +0100 Subject: [PATCH] add notifications reactions/reposts/zaps settings + Re-broadcast with popup for choosing to which relays --- lib/ui/event/event_main_component.dart | 19 ++++++--- lib/ui/event/event_reactions_component.dart | 46 ++++++++++++++++++++- pubspec.lock | 4 +- pubspec.yaml | 4 +- 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/lib/ui/event/event_main_component.dart b/lib/ui/event/event_main_component.dart index f995040a..5d21e069 100644 --- a/lib/ui/event/event_main_component.dart +++ b/lib/ui/event/event_main_component.dart @@ -296,15 +296,24 @@ class _EventMainComponent extends State { "${s.Replying}: ", style: textStyle, )); + int maxPTags = 20; for (var index = 0; index < length; index++) { - var p = eventRelation.tagPList[index]; - var isLast = index < length - 1 ? false : true; - replyingList.add(EventReplyingcomponent(pubkey: p)); - if (!isLast) { + if (index < maxPTags) { + var p = eventRelation.tagPList[index]; + var isLast = index < length - 1 ? false : true; + replyingList.add(EventReplyingcomponent(pubkey: p)); + if (!isLast) { + replyingList.add(Text( + " & ", + style: textStyle, + )); + } + } else { replyingList.add(Text( - " & ", + " ${length - 20} more", style: textStyle, )); + break; } } list.add(Container( diff --git a/lib/ui/event/event_reactions_component.dart b/lib/ui/event/event_reactions_component.dart index e3e17049..5c746d61 100644 --- a/lib/ui/event/event_reactions_component.dart +++ b/lib/ui/event/event_reactions_component.dart @@ -1,9 +1,12 @@ import 'dart:convert'; +import 'package:dart_ndk/models/relay_set.dart'; import 'package:dart_ndk/nips/nip01/event.dart'; import 'package:dart_ndk/nips/nip51/nip51.dart'; +import 'package:dart_ndk/read_write.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_quill/flutter_quill.dart' as quill; import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:provider/provider.dart'; @@ -289,7 +292,7 @@ class _EventReactionsComponent extends State { if (widget.eventRelation.pubkey == loggedUserSigner!.getPublicKey()) { list.add(PopupMenuItem( value: "broadcast", - child: Text(s.Broadcast, style: popFontStyle), + child: Text("Re-Broadcast", style: popFontStyle), )); } list.add(PopupMenuItem( @@ -376,7 +379,46 @@ class _EventReactionsComponent extends State { } else if (value == "star") { // TODO star event } else if (value == "broadcast") { - await relayManager.broadcastEvent(widget.event, myOutboxRelaySet!.urls, loggedUserSigner!); + Set relays = {}; + relays.addAll(myOutboxRelaySet!.urls.toList()); + if (settingProvider.inboxForReactions == 1) { + List pubKeys = widget.event.pTags; + if (pubKeys.length == 1) { + relays.addAll(await getInboxRelays(pubKeys.first)); + } else if (pubKeys.isNotEmpty) { + EasyLoading.show(status: 'Calculating inbox relays of participants...', maskType: EasyLoadingMaskType.black, dismissOnTap: true); + RelaySet inboxRelaySet = await relayManager + .calculateRelaySet( + name: "replyInboxRelaySet", + ownerPubKey: loggedUserSigner!.getPublicKey(), + pubKeys: pubKeys, + direction: RelayDirection.inbox, + relayMinCountPerPubKey: settingProvider + .broadcastToInboxMaxCount); + relays.addAll(inboxRelaySet.urls.toSet()); + relays.removeWhere((element) => relayManager.blockedRelays.contains(element)); + EasyLoading.dismiss(); + } + } + List? results = await showDialog( + context: context, + builder: (BuildContext context) { + return MultiSelect(items: relays!.toList(), selectedItems: relays!.toList().take(myOutboxRelaySet!.urls.length+settingProvider + .broadcastToInboxMaxCount).toList(), sending: false,); + }, + ); + if (results!=null && results.isNotEmpty) { + // await showDialog( + // context: context, + // builder: (BuildContext context) { + // return MultiSelect(items: results!, selectedItems: [], sending: true,); + // }, + // ); + await relayManager.broadcastEvent(widget.event, results, loggedUserSigner!); + widget.event.sources.addAll(results); + cacheManager.saveEvent(widget.event); + } + } else if (value.startsWith("mute-")) { setState(() { muting = true; diff --git a/pubspec.lock b/pubspec.lock index a3fc8f8f..e0363d3c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -301,10 +301,10 @@ packages: dependency: "direct main" description: name: dart_ndk - sha256: f880c8fe0486d2609a8d2a0eb2b5057674820ea681a1136af8b7cd70f6a47c1a + sha256: b615de1684fbd058aa93cd7136ea0595197e97dcea95a69d5e5128f3a1572284 url: "https://pub.dev" source: hosted - version: "0.1.0-dev4" + version: "0.1.0-dev5" dart_style: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 76b0f89b..bb08683a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 0.12.3 +version: 0.13.0 environment: sdk: '>=3.0.0 <3.11.0' @@ -120,7 +120,7 @@ dependencies: # git: # url: https://github.com/relaystr/dart_ndk.git # ref: master - dart_ndk: 0.1.0-dev4 + dart_ndk: 0.1.0-dev5 # path: ../dart_ndk dev_dependencies: