Skip to content

Commit

Permalink
add notifications reactions/reposts/zaps settings + Re-broadcast with…
Browse files Browse the repository at this point in the history
… popup for choosing to which relays
  • Loading branch information
Fmar committed Dec 4, 2023
1 parent 8d1c6fb commit 39846e3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
19 changes: 14 additions & 5 deletions lib/ui/event/event_main_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,24 @@ class _EventMainComponent extends State<EventMainComponent> {
"${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(
Expand Down
46 changes: 44 additions & 2 deletions lib/ui/event/event_reactions_component.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -289,7 +292,7 @@ class _EventReactionsComponent extends State<EventReactionsComponent> {
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(
Expand Down Expand Up @@ -376,7 +379,46 @@ class _EventReactionsComponent extends State<EventReactionsComponent> {
} else if (value == "star") {
// TODO star event
} else if (value == "broadcast") {
await relayManager.broadcastEvent(widget.event, myOutboxRelaySet!.urls, loggedUserSigner!);
Set<String> relays = {};
relays.addAll(myOutboxRelaySet!.urls.toList());
if (settingProvider.inboxForReactions == 1) {
List<String> 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<String>? 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;
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 39846e3

Please sign in to comment.