From ddcafa7d9ad313b45fbed5aae8ea124414420e80 Mon Sep 17 00:00:00 2001 From: Sarthak Gupta Date: Sat, 22 Jul 2023 22:10:58 +0530 Subject: [PATCH 1/9] comments platform --- lib/bloc/app_blocs.dart | 5 + lib/home_page.dart | 48 +++- lib/routes/podcast/podcast_page.dart | 8 +- lib/user_app.dart | 3 + pubspec.lock | 314 +++++++++++++++------------ pubspec.yaml | 7 +- 6 files changed, 232 insertions(+), 153 deletions(-) diff --git a/lib/bloc/app_blocs.dart b/lib/bloc/app_blocs.dart index 5e48cfb60..3d3678a08 100644 --- a/lib/bloc/app_blocs.dart +++ b/lib/bloc/app_blocs.dart @@ -4,6 +4,7 @@ import 'package:breez/bloc/connect_pay/connect_pay_bloc.dart'; import 'package:breez/bloc/fastbitcoins/fastbitcoins_bloc.dart'; import 'package:breez/bloc/lnurl/lnurl_bloc.dart'; import 'package:breez/bloc/marketplace/marketplace_bloc.dart'; +import 'package:breez/bloc/nostr/nostr_bloc.dart'; import 'package:breez/bloc/payment_options/payment_options_bloc.dart'; import 'package:breez/bloc/podcast_clip/podcast_clip_bloc.dart'; import 'package:breez/bloc/podcast_history/podcast_history_bloc.dart'; @@ -26,6 +27,7 @@ class AppBlocs { final InvoiceBloc invoicesBloc; final ConnectPayBloc connectPayBloc; final BackupBloc backupBloc; + final NostrBloc nostrBloc; final MarketplaceBloc marketplaceBloc; final FastbitcoinsBloc fastbitcoinsBloc; final LSPBloc lspBloc; @@ -74,6 +76,7 @@ class AppBlocs { blocsByType); MarketplaceBloc marketplaceBloc = _registerBloc(MarketplaceBloc(), blocsByType); + NostrBloc nostrBloc = _registerBloc(NostrBloc(), blocsByType); LSPBloc lspBloc = _registerBloc(LSPBloc(accountBloc.accountStream), blocsByType); LNUrlBloc lnurlBloc = _registerBloc(LNUrlBloc(), blocsByType); @@ -110,6 +113,7 @@ class AppBlocs { invoicesBloc, connectPayBloc, backupBloc, + nostrBloc, marketplaceBloc, fastbitcoinsBloc, lspBloc, @@ -129,6 +133,7 @@ class AppBlocs { this.invoicesBloc, this.connectPayBloc, this.backupBloc, + this.nostrBloc, this.marketplaceBloc, this.fastbitcoinsBloc, this.lspBloc, diff --git a/lib/home_page.dart b/lib/home_page.dart index b2cf8d4a1..f39f823df 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:io'; +import 'package:anytime/bloc/comments/comments_bloc.dart'; import 'package:anytime/bloc/podcast/audio_bloc.dart'; import 'package:anytime/ui/anytime_podcast_app.dart'; import 'package:anytime/ui/podcast/now_playing.dart'; @@ -15,6 +16,7 @@ import 'package:breez/bloc/connect_pay/connect_pay_bloc.dart'; import 'package:breez/bloc/invoice/invoice_bloc.dart'; import 'package:breez/bloc/lnurl/lnurl_bloc.dart'; import 'package:breez/bloc/lsp/lsp_bloc.dart'; +import 'package:breez/bloc/nostr/nostr_bloc.dart'; import 'package:breez/bloc/reverse_swap/reverse_swap_bloc.dart'; import 'package:breez/bloc/user_profile/breez_user_model.dart'; import 'package:breez/bloc/user_profile/user_profile_bloc.dart'; @@ -55,9 +57,13 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -final GlobalKey firstPaymentItemKey = GlobalKey(debugLabel: "firstPaymentItemKey"); +import 'bloc/nostr/nostr_actions.dart'; + +final GlobalKey firstPaymentItemKey = + GlobalKey(debugLabel: "firstPaymentItemKey"); final ScrollController scrollController = ScrollController(); -final GlobalKey _scaffoldKey = GlobalKey(debugLabel: "scaffoldKey"); +final GlobalKey _scaffoldKey = + GlobalKey(debugLabel: "scaffoldKey"); class Home extends StatefulWidget { final AccountBloc accountBloc; @@ -68,6 +74,7 @@ class Home extends StatefulWidget { final LSPBloc lspBloc; final ReverseSwapBloc reverseSwapBloc; final LNUrlBloc lnurlBloc; + final NostrBloc nostrBloc; Home( this.accountBloc, @@ -78,6 +85,7 @@ class Home extends StatefulWidget { this.lspBloc, this.reverseSwapBloc, this.lnurlBloc, + this.nostrBloc, ); final List _screens = List.unmodifiable([ @@ -97,6 +105,7 @@ class HomeState extends State with WidgetsBindingObserver { final Set _hiddenRoutes = {}; StreamSubscription _accountNotificationsSubscription; bool _listensInit = false; + CommentBloc commentBloc; @override void initState() { @@ -127,6 +136,25 @@ class HomeState extends State with WidgetsBindingObserver { } }); }); + commentBloc = Provider.of(context, listen: false); + + commentBloc.pubKeyStream.listen((event) async { + widget.nostrBloc.actionsSink.add(GetPublicKey()); + + final publicKey = await widget.nostrBloc.publicKeyStream.first; + commentBloc.getPubKeyResult(publicKey); + }); + + // Listener for signing the comment + commentBloc.signEventStream.listen((event) async { + final nostrPrivateKey = widget.nostrBloc.nostrPrivateKey; + + widget.nostrBloc.actionsSink.add(SignEvent(event, nostrPrivateKey)); + + final Map signedEventObject = + await widget.nostrBloc.eventStream.first; + commentBloc.signEventResult(signedEventObject); + }); AudioService.notificationClicked.where((event) => event == true).listen( (event) async { @@ -191,7 +219,6 @@ class HomeState extends State with WidgetsBindingObserver { stream: userProfileBloc.userStream, builder: (context, userSnapshot) { final appMode = userSnapshot.data?.appMode; - return Scaffold( resizeToAvoidBottomInset: false, key: _scaffoldKey, @@ -203,10 +230,16 @@ class HomeState extends State with WidgetsBindingObserver { _onNavigationItemSelected, _filterItems, ), - bottomNavigationBar: appMode == AppMode.balance ? BottomActionsBar(firstPaymentItemKey) : null, - floatingActionButton: appMode == AppMode.balance ? QrActionButton(firstPaymentItemKey) : null, - floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, - body: widget._screenBuilders[_activeScreen] ?? _homePage(context, appMode), + bottomNavigationBar: appMode == AppMode.balance + ? BottomActionsBar(firstPaymentItemKey) + : null, + floatingActionButton: appMode == AppMode.balance + ? QrActionButton(firstPaymentItemKey) + : null, + floatingActionButtonLocation: + FloatingActionButtonLocation.centerDocked, + body: widget._screenBuilders[_activeScreen] ?? + _homePage(context, appMode), ); }, ), @@ -217,7 +250,6 @@ class HomeState extends State with WidgetsBindingObserver { if (appMode == null) { return AccountPage(firstPaymentItemKey, scrollController); } - final texts = context.texts(); final themeData = Theme.of(context); diff --git a/lib/routes/podcast/podcast_page.dart b/lib/routes/podcast/podcast_page.dart index 7e2ee14a5..1eff30bd0 100644 --- a/lib/routes/podcast/podcast_page.dart +++ b/lib/routes/podcast/podcast_page.dart @@ -1,4 +1,5 @@ import 'package:anytime/api/podcast/podcast_api.dart'; +import 'package:anytime/bloc/comments/comments_bloc.dart'; import 'package:anytime/bloc/discovery/discovery_bloc.dart'; import 'package:anytime/bloc/new_podcasts/new_podcasts_bloc.dart'; import 'package:anytime/bloc/podcast/audio_bloc.dart'; @@ -180,7 +181,12 @@ class AnytimePodcastAppState extends State { podcastService: widget.podcastService, ), dispose: (_, value) => value.dispose(), - ) + ), + Provider( + create: (_) => CommentBloc( + episodeStream: widget.audioPlayerService.episodeEvent), + dispose: (_, value) => value.dispose(), + ), ], child: widget.child, ); diff --git a/lib/user_app.dart b/lib/user_app.dart index 7eaad1cba..a9976e48c 100644 --- a/lib/user_app.dart +++ b/lib/user_app.dart @@ -7,6 +7,7 @@ import 'package:breez/bloc/connect_pay/connect_pay_bloc.dart'; import 'package:breez/bloc/invoice/invoice_bloc.dart'; import 'package:breez/bloc/lnurl/lnurl_bloc.dart'; import 'package:breez/bloc/lsp/lsp_bloc.dart'; +import 'package:breez/bloc/nostr/nostr_bloc.dart'; import 'package:breez/bloc/pos_catalog/bloc.dart'; import 'package:breez/bloc/reverse_swap/reverse_swap_bloc.dart'; import 'package:breez/bloc/user_profile/breez_user_model.dart'; @@ -76,6 +77,7 @@ class UserApp extends StatelessWidget { var reverseSwapBloc = AppBlocsProvider.of(context); var lnurlBloc = AppBlocsProvider.of(context); var posCatalogBloc = AppBlocsProvider.of(context); + var nostrBloc = AppBlocsProvider.of(context); return StreamBuilder( stream: userProfileBloc.userStream, @@ -196,6 +198,7 @@ class UserApp extends StatelessWidget { lspBloc, reverseSwapBloc, lnurlBloc, + nostrBloc, ), settings: settings, ); diff --git a/pubspec.lock b/pubspec.lock index d7e2ebb87..4dd5de291 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -13,10 +13,10 @@ packages: dependency: transitive description: name: _flutterfire_internals - sha256: "8eb354cb8ebed8a9fdf63699d15deff533bc133128898afaf754926b57d611b6" + sha256: a742f71d7f3484253a623b30e19256aa4668ecbb3de6ad1beb0bcf8d4777ecd8 url: "https://pub.dev" source: hosted - version: "1.3.1" + version: "1.3.3" analyzer: dependency: transitive description: @@ -36,11 +36,9 @@ packages: anytime: dependency: "direct main" description: - path: "." - ref: c9a97586b9f116014675a2c856b55f29731b93e2 - resolved-ref: c9a97586b9f116014675a2c856b55f29731b93e2 - url: "https://github.com/breez/anytime_podcast_player.git" - source: git + path: "/Users/sarthakgupta/Documents/breez/breez_anytime/anytime/anytime_podcast_player" + relative: false + source: path version: "1.2.1+74-breez" app_settings: dependency: "direct main" @@ -62,10 +60,10 @@ packages: dependency: transitive description: name: args - sha256: c372bb384f273f0c2a8aaaa226dad84dc27c8519a691b888725dec59518ad53a + sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 url: "https://pub.dev" source: hosted - version: "2.4.1" + version: "2.4.2" async: dependency: transitive description: @@ -78,10 +76,10 @@ packages: dependency: "direct main" description: name: audio_service - sha256: "7e86d7ce23caad605199f7b25e548fe7b618fb0c150fa0585f47a910fe7e7a67" + sha256: "8b719ac7982fdea1a54a528f19e345907295489c53709ba4cdee65a2955c0f4d" url: "https://pub.dev" source: hosted - version: "0.18.9" + version: "0.18.10" audio_service_platform_interface: dependency: transitive description: @@ -102,10 +100,10 @@ packages: dependency: transitive description: name: audio_session - sha256: "97317505460ab705e8e186e87a3924d67c74d8c8a07cbc087e3b988bbce7cfaa" + sha256: "8a2bc5e30520e18f3fb0e366793d78057fb64cd5287862c76af0c8771f2a52ad" url: "https://pub.dev" source: hosted - version: "0.1.14" + version: "0.1.16" auto_size_text: dependency: "direct main" description: @@ -129,7 +127,7 @@ packages: sha256: "789f898eef0bd88312470bdb2cc996f895ad7dd5f89e9adde84b204546a90b45" url: "https://pub.dev" source: hosted - version: "2.2.3" + version: "2.2.4" base58check: dependency: transitive description: @@ -263,10 +261,10 @@ packages: dependency: transitive description: name: built_value - sha256: "7dd62d9faf105c434f3d829bbe9c4be02ec67f5ed94832222116122df67c5452" + sha256: "598a2a682e2a7a90f08ba39c0aaa9374c5112340f0a2e275f61b59389543d166" url: "https://pub.dev" source: hosted - version: "8.6.0" + version: "8.6.1" characters: dependency: transitive description: @@ -311,10 +309,10 @@ packages: dependency: transitive description: name: code_builder - sha256: "0d43dd1288fd145de1ecc9a3948ad4a6d5a82f0a14c4fdd0892260787d975cbe" + sha256: "4ad01d6e56db961d29661561effde45e519939fdaeb46c351275b182eac70189" url: "https://pub.dev" source: hosted - version: "4.4.0" + version: "4.5.0" collection: dependency: "direct main" description: @@ -323,6 +321,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.17.2" + comment_box: + dependency: transitive + description: + name: comment_box + sha256: "6a0d9cc8d181435b123cc4249c567bd8bdf1bde8d714691b069b942e3e7d4fbb" + url: "https://pub.dev" + source: hosted + version: "0.0.18" confetti: dependency: "direct main" description: @@ -432,10 +438,10 @@ packages: dependency: transitive description: name: device_info_plus - sha256: "499c61743e13909c13374a8c209075385858c614b9c0f2487b5f9995eeaf7369" + sha256: "2c35b6d1682b028e42d07b3aee4b98fa62996c10bc12cb651ec856a80d6a761b" url: "https://pub.dev" source: hosted - version: "9.0.1" + version: "9.0.2" device_info_plus_platform_interface: dependency: transitive description: @@ -448,10 +454,10 @@ packages: dependency: "direct main" description: name: dio - sha256: "347d56c26d63519552ef9a569f2a593dda99a81fdbdff13c584b7197cfe05059" + sha256: a9d76e72985d7087eb7c5e7903224ae52b337131518d127c554b9405936752b8 url: "https://pub.dev" source: hosted - version: "5.1.2" + version: "5.2.1+1" drag_and_drop_lists: dependency: "direct main" description: @@ -540,14 +546,46 @@ packages: url: "https://pub.dev" source: hosted version: "5.3.1" + file_selector_linux: + dependency: transitive + description: + name: file_selector_linux + sha256: "770eb1ab057b5ae4326d1c24cc57710758b9a46026349d021d6311bd27580046" + url: "https://pub.dev" + source: hosted + version: "0.9.2" + file_selector_macos: + dependency: transitive + description: + name: file_selector_macos + sha256: "7a6f1ae6107265664f3f7f89a66074882c4d506aef1441c9af313c1f7e6f41ce" + url: "https://pub.dev" + source: hosted + version: "0.9.3" + file_selector_platform_interface: + dependency: transitive + description: + name: file_selector_platform_interface + sha256: "412705a646a0ae90f33f37acfae6a0f7cbc02222d6cd34e479421c3e74d3853c" + url: "https://pub.dev" + source: hosted + version: "2.6.0" + file_selector_windows: + dependency: transitive + description: + name: file_selector_windows + sha256: "1372760c6b389842b77156203308940558a2817360154084368608413835fc26" + url: "https://pub.dev" + source: hosted + version: "0.9.3" firebase_core: dependency: "direct main" description: name: firebase_core - sha256: "250678b816279b3240c3a33e1f76bf712c00718f1fbeffc85873a5da8c077379" + sha256: a4a99204da264a0aa9d54a332ea0315ce7b0768075139c77abefe98093dd98be url: "https://pub.dev" source: hosted - version: "2.13.0" + version: "2.14.0" firebase_core_platform_interface: dependency: "direct main" description: @@ -560,74 +598,74 @@ packages: dependency: transitive description: name: firebase_core_web - sha256: "8c0f4c87d20e2d001a5915df238c1f9c88704231f591324205f5a5d2a7740a45" + sha256: "0fd5c4b228de29b55fac38aed0d9e42514b3d3bd47675de52bf7f8fccaf922fa" url: "https://pub.dev" source: hosted - version: "2.5.0" + version: "2.6.0" firebase_database: dependency: "direct main" description: name: firebase_database - sha256: d10fe0a2187e4c84381338f38a38af2fb11d2d8ea37324522c124d27819e7dbd + sha256: "36699bda00feb31433606f034078c690f148c15a4721b351a83c796ba4bba4e7" url: "https://pub.dev" source: hosted - version: "10.2.1" + version: "10.2.3" firebase_database_platform_interface: dependency: transitive description: name: firebase_database_platform_interface - sha256: c1474743f110b100703f1d5ad3593c805084668506eeeff5f0c6fd710b06c4fd + sha256: "8bd62f80b51d71a81087a33fe2e2a868fb818a6e33b319a137a7bcb35dec262d" url: "https://pub.dev" source: hosted - version: "0.2.5+1" + version: "0.2.5+3" firebase_database_web: dependency: transitive description: name: firebase_database_web - sha256: "05de906a507ca6a10c7db00ff97395c9284e328cad01d794bc5e123eae7b55fa" + sha256: "05e6b0c2a192569cd5ce2be4a708756ca9f56e4c7b6fe1916f0f9d96a826f235" url: "https://pub.dev" source: hosted - version: "0.2.3+1" + version: "0.2.3+3" firebase_dynamic_links: dependency: "direct main" description: name: firebase_dynamic_links - sha256: "057b48fc8126583c54e32641ca5b7c25f041fd119e98c4888cd1665baeff7fe4" + sha256: "9b984d0abd227a702451a997abcca763f4dbf67e260dad60e5506d55e3eff244" url: "https://pub.dev" source: hosted - version: "5.3.1" + version: "5.3.3" firebase_dynamic_links_platform_interface: dependency: transitive description: name: firebase_dynamic_links_platform_interface - sha256: "861a4468f435dc3ab5d1b14d07cabe6db12e3c3bc2e69be2fa51cb0886d27fa2" + sha256: "6ef00a0be18f3231e9727f7c4b31db89dbfa16792098beb850603c30854560ff" url: "https://pub.dev" source: hosted - version: "0.2.6+1" + version: "0.2.6+3" firebase_messaging: dependency: "direct main" description: name: firebase_messaging - sha256: "9cfe5c4560fb83393511ca7620f8fb3f22c9a80303052f10290e732fcfb801bd" + sha256: "7a09d8c21147f009882a27c96de1918ea283f974d73cb6fae1d234bb9ec18d8b" url: "https://pub.dev" source: hosted - version: "14.6.1" + version: "14.6.4" firebase_messaging_platform_interface: dependency: transitive description: name: firebase_messaging_platform_interface - sha256: "7e25cb71019ccef8b1fd7b37969af79f04c467974cce4dfc291fa36974edd7ba" + sha256: e9e9dc48a3d8ffa67aaba3d6b1ebf74bc7d7d8c83d10b1458ff97878b9d8a2b0 url: "https://pub.dev" source: hosted - version: "4.5.1" + version: "4.5.3" firebase_messaging_web: dependency: transitive description: name: firebase_messaging_web - sha256: "5d9840cc8126ea723b1bda901389cb542902f664f2653c16d4f8114e95f13cec" + sha256: "381f217e41e0e407baf8df21787b97e46fabfacefd6a953425be3a6cdf2269f4" url: "https://pub.dev" source: hosted - version: "3.5.1" + version: "3.5.3" fixnum: dependency: "direct main" description: @@ -670,18 +708,18 @@ packages: dependency: transitive description: name: flutter_html - sha256: "850c07bc6c1ed060d3eb3e88469a598260a13eb45d8978b197c1348e0a2b101f" + sha256: "02ad69e813ecfc0728a455e4bf892b9379983e050722b1dce00192ee2e41d1ee" url: "https://pub.dev" source: hosted - version: "3.0.0-beta.1" + version: "3.0.0-beta.2" flutter_keyboard_visibility: dependency: transitive description: name: flutter_keyboard_visibility - sha256: be41db80ab7156d893878ca48a7520d667075c4841a0435d5544fd836197b55a + sha256: "4983655c26ab5b959252ee204c2fffa4afeb4413cd030455194ec0caa3b8e7cb" url: "https://pub.dev" source: hosted - version: "5.4.3" + version: "5.4.1" flutter_keyboard_visibility_linux: dependency: transitive description: @@ -730,14 +768,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.13.1" - flutter_lints: - dependency: transitive - description: - name: flutter_lints - sha256: aeb0b80a8b3709709c9cc496cdc027c5b3216796bc0af0ce1007eaf24464fd4c - url: "https://pub.dev" - source: hosted - version: "2.0.1" flutter_localizations: dependency: "direct main" description: flutter @@ -811,10 +841,10 @@ packages: dependency: "direct main" description: name: flutter_svg - sha256: "6ff8c902c8056af9736de2689f63f81c42e2d642b9f4c79dbf8790ae48b63012" + sha256: "8c5d68a82add3ca76d792f058b186a0599414f279f00ece4830b9b231b570338" url: "https://pub.dev" source: hosted - version: "2.0.6" + version: "2.0.7" flutter_test: dependency: "direct dev" description: flutter @@ -918,10 +948,10 @@ packages: dependency: transitive description: name: html - sha256: "58e3491f7bf0b6a4ea5110c0c688877460d1a6366731155c4a4580e7ded773e8" + sha256: "3a7812d5bcd2894edf53dfaf8cd640876cf6cef50a8f238745c8b8120ea74d3a" url: "https://pub.dev" source: hosted - version: "0.15.3" + version: "0.15.4" http: dependency: "direct main" description: @@ -998,42 +1028,66 @@ packages: dependency: "direct main" description: name: image_picker - sha256: "9978d3510af4e6a902e545ce19229b926e6de6a1828d6134d3aab2e129a4d270" + sha256: b6951e25b795d053a6ba03af5f710069c99349de9341af95155d52665cb4607c url: "https://pub.dev" source: hosted - version: "0.8.7+5" + version: "0.8.9" image_picker_android: dependency: transitive description: name: image_picker_android - sha256: c2f3c66400649bd132f721c88218945d6406f693092b2f741b79ae9cdb046e59 + sha256: d2bab152deb2547ea6f53d82ebca9b7e77386bb706e5789e815d37e08ea475bb url: "https://pub.dev" source: hosted - version: "0.8.6+16" + version: "0.8.7+3" image_picker_for_web: dependency: transitive description: name: image_picker_for_web - sha256: "98f50d6b9f294c8ba35e25cc0d13b04bfddd25dbc8d32fa9d566a6572f2c081c" + sha256: "869fe8a64771b7afbc99fc433a5f7be2fea4d1cb3d7c11a48b6b579eb9c797f0" url: "https://pub.dev" source: hosted - version: "2.1.12" + version: "2.2.0" image_picker_ios: dependency: transitive description: name: image_picker_ios - sha256: d779210bda268a03b57e923fb1e410f32f5c5e708ad256348bcbf1f44f558fd0 + sha256: b3e2f21feb28b24dd73a35d7ad6e83f568337c70afab5eabac876e23803f264b + url: "https://pub.dev" + source: hosted + version: "0.8.8" + image_picker_linux: + dependency: transitive + description: + name: image_picker_linux + sha256: "02cbc21fe1706b97942b575966e5fbbeaac535e76deef70d3a242e4afb857831" + url: "https://pub.dev" + source: hosted + version: "0.2.1" + image_picker_macos: + dependency: transitive + description: + name: image_picker_macos + sha256: cee2aa86c56780c13af2c77b5f2f72973464db204569e1ba2dd744459a065af4 url: "https://pub.dev" source: hosted - version: "0.8.7+4" + version: "0.2.1" image_picker_platform_interface: dependency: transitive description: name: image_picker_platform_interface - sha256: "1991219d9dbc42a99aff77e663af8ca51ced592cd6685c9485e3458302d3d4f8" + sha256: "7c7b96bb9413a9c28229e717e6fd1e3edd1cc5569c1778fcca060ecf729b65ee" url: "https://pub.dev" source: hosted - version: "2.6.3" + version: "2.8.0" + image_picker_windows: + dependency: transitive + description: + name: image_picker_windows + sha256: c3066601ea42113922232c7b7b3330a2d86f029f685bba99d82c30e799914952 + url: "https://pub.dev" + source: hosted + version: "0.2.1" ini: dependency: "direct main" description: @@ -1086,10 +1140,10 @@ packages: dependency: transitive description: name: just_audio - sha256: d7ff71169927a2237c902aef6baf2f69d063d4c427590dee479d279d4d57c984 + sha256: "890cd0fc41a1a4530c171e375a2a3fb6a09d84e9d508c5195f40bcff54330327" url: "https://pub.dev" source: hosted - version: "0.9.33" + version: "0.9.34" just_audio_platform_interface: dependency: transitive description: @@ -1105,7 +1159,7 @@ packages: sha256: ff62f733f437b25a0ff590f0e295fa5441dcb465f1edbdb33b3dea264705bc13 url: "https://pub.dev" source: hosted - version: "0.4.7" + version: "0.4.8" kepler: dependency: transitive description: @@ -1114,14 +1168,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.3" - lints: - dependency: transitive - description: - name: lints - sha256: "5e4a9cd06d447758280a8ac2405101e0e2094d2a1dbdd3756aec3fe7775ba593" - url: "https://pub.dev" - source: hosted - version: "2.0.1" list_counter: dependency: transitive description: @@ -1191,10 +1237,10 @@ packages: dependency: "direct main" description: name: mobile_scanner - sha256: da55204e5439bc8dc058df56231a7a1d513c6ec9cbad84492f56d493382d296f + sha256: "54dd914e1bb5758b3db7aa02e56d65d80285ba0705e0e5fa5cfbb11e27344c4b" url: "https://pub.dev" source: hosted - version: "3.2.0" + version: "3.3.0" mockito: dependency: "direct dev" description: @@ -1232,10 +1278,10 @@ packages: dependency: "direct main" description: name: nfc_manager - sha256: cff1e59e316388f4508b4ba0cea4430e4ba39f8a68ecfb3e1256be25c13b0f4a + sha256: d6a4cc6a8a37119b1e8cc242392c0c87623d319cf1423f6a90cb998a52970baf url: "https://pub.dev" source: hosted - version: "3.2.0" + version: "3.3.0" nm: dependency: transitive description: @@ -1260,14 +1306,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.7" - numerus: - dependency: transitive - description: - name: numerus - sha256: "436759d84f233b40107d0cc31cfa92d24e0960afeb2e506be70926d4cddffd9e" - url: "https://pub.dev" - source: hosted - version: "2.0.0" package_config: dependency: transitive description: @@ -1280,10 +1318,10 @@ packages: dependency: "direct main" description: name: package_info_plus - sha256: "28386bbe89ab5a7919a47cea99cdd1128e5a6e0bbd7eaafe20440ead84a15de3" + sha256: ceb027f6bc6a60674a233b4a90a7658af1aebdea833da0b5b53c1e9821a78c7b url: "https://pub.dev" source: hosted - version: "4.0.1" + version: "4.0.2" package_info_plus_platform_interface: dependency: transitive description: @@ -1352,10 +1390,10 @@ packages: dependency: transitive description: name: path_provider_windows - sha256: d3f80b32e83ec208ac95253e0cd4d298e104fbc63cb29c5c69edaed43b0c69d6 + sha256: "1cb68ba4cd3a795033de62ba1b7b4564dace301f952de6bfb3cd91b202b6ee96" url: "https://pub.dev" source: hosted - version: "2.1.6" + version: "2.1.7" pdf: dependency: "direct main" description: @@ -1392,34 +1430,34 @@ packages: dependency: transitive description: name: permission_handler - sha256: "33c6a1253d1f95fd06fa74b65b7ba907ae9811f9d5c1d3150e51417d04b8d6a8" + sha256: "1b6b3e73f0bcbc856548bbdfb1c33084a401c4f143e220629a9055233d76c331" url: "https://pub.dev" source: hosted - version: "10.2.0" + version: "10.3.0" permission_handler_android: dependency: transitive description: name: permission_handler_android - sha256: d8cc6a62ded6d0f49c6eac337e080b066ee3bce4d405bd9439a61e1f1927bfe8 + sha256: "8f6a95ccbca13766882f95d32684d7c9bfe6c45650c32bedba948ef1c6a4ddf7" url: "https://pub.dev" source: hosted - version: "10.2.1" + version: "10.2.3" permission_handler_apple: dependency: transitive description: name: permission_handler_apple - sha256: ee96ac32f5a8e6f80756e25b25b9f8e535816c8e6665a96b6d70681f8c4f7e85 + sha256: "08dcb6ce628ac0b257e429944b4c652c2a4e6af725bdf12b498daa2c6b2b1edb" url: "https://pub.dev" source: hosted - version: "9.0.8" + version: "9.1.0" permission_handler_platform_interface: dependency: transitive description: name: permission_handler_platform_interface - sha256: "68abbc472002b5e6dfce47fe9898c6b7d8328d58b5d2524f75e277c07a97eb84" + sha256: de20a5c3269229c1ae2e5a6b822f6cb59578b23e8255c93fbeebfc82116e6b11 url: "https://pub.dev" source: hosted - version: "3.9.0" + version: "3.10.0" permission_handler_windows: dependency: transitive description: @@ -1466,11 +1504,9 @@ packages: description: name: pointycastle sha256: "7c1e5f0d23c9016c5bbd8b1473d0d3fb3fc851b876046039509e18e0c7485f2c" - sha256: "7c1e5f0d23c9016c5bbd8b1473d0d3fb3fc851b876046039509e18e0c7485f2c" url: "https://pub.dev" source: hosted version: "3.7.3" - version: "3.7.3" pool: dependency: transitive description: @@ -1572,18 +1608,18 @@ packages: dependency: transitive description: name: sembast - sha256: "74f6c57e2d230c55287372830239701286628b81ceb06a5507d7686a6d7d4b44" + sha256: da8dd3774b6001bde09378da28e94c40bd4daecde32adb44837517c12e991321 url: "https://pub.dev" source: hosted - version: "3.4.5" + version: "3.4.9" share_plus: dependency: "direct main" description: name: share_plus - sha256: "44fc0bc2d35a8fafa1b564e1c6888bdc4fbb2d0197e4a4c21bac0e66123be9cd" + sha256: ed3fcea4f789ed95913328e629c0c53e69e80e08b6c24542f1b3576046c614e8 url: "https://pub.dev" source: hosted - version: "7.0.1" + version: "7.0.2" share_plus_platform_interface: dependency: transitive description: @@ -1596,10 +1632,10 @@ packages: dependency: "direct main" description: name: shared_preferences - sha256: "16d3fb6b3692ad244a695c0183fca18cf81fd4b821664394a781de42386bf022" + sha256: "396f85b8afc6865182610c0a2fc470853d56499f75f7499e2a73a9f0539d23d0" url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" shared_preferences_android: dependency: transitive description: @@ -1628,10 +1664,10 @@ packages: dependency: transitive description: name: shared_preferences_platform_interface - sha256: fb5cf25c0235df2d0640ac1b1174f6466bd311f621574997ac59018a6664548d + sha256: "23b052f17a25b90ff2b61aad4cc962154da76fb62848a9ce088efe30d7c50ab1" url: "https://pub.dev" source: hosted - version: "2.2.0" + version: "2.3.0" shared_preferences_web: dependency: transitive description: @@ -1692,10 +1728,10 @@ packages: dependency: "direct main" description: name: simple_animations - sha256: "6da9a59389d7f6695391f702b0893a0fc63aed2b4d41509cfc1f8781218db635" + sha256: "1ea7b93fb98e2a611b6865d632de55607b766328d14700143353129ee0559d3a" url: "https://pub.dev" source: hosted - version: "5.0.0+3" + version: "5.0.2" sky_engine: dependency: transitive description: flutter @@ -1753,10 +1789,10 @@ packages: dependency: transitive description: name: sqflite_common - sha256: e77abf6ff961d69dfef41daccbb66b51e9983cdd5cb35bf30733598057401555 + sha256: "8f7603f3f8f126740bc55c4ca2d1027aab4b74a1267a3e31ce51fe40e3b65b8f" url: "https://pub.dev" source: hosted - version: "2.4.5" + version: "2.4.5+1" sqflite_common_ffi: dependency: "direct dev" description: @@ -1769,10 +1805,10 @@ packages: dependency: transitive description: name: sqlite3 - sha256: "2cef47b59d310e56f8275b13734ee80a9cf4a48a43172020cb55a620121fbf66" + sha256: "281b672749af2edf259fc801f0fcba092257425bcd32a0ce1c8237130bc934c7" url: "https://pub.dev" source: hosted - version: "1.11.1" + version: "1.11.2" stack_trace: dependency: transitive description: @@ -1865,10 +1901,10 @@ packages: dependency: "direct main" description: name: tutorial_coach_mark - sha256: "669d4bd517d22e14671f3ddee0e7442d976ab71f94bb6eec6ad057ca3944fd73" + sha256: ba60583d1b500111bf5040eb24330862b25162d926f72923b8e45c16621878b0 url: "https://pub.dev" source: hosted - version: "1.2.8" + version: "1.2.9" typed_data: dependency: transitive description: @@ -1913,10 +1949,10 @@ packages: dependency: transitive description: name: url_launcher_android - sha256: eed4e6a1164aa9794409325c3b707ff424d4d1c2a785e7db67f8bbda00e36e51 + sha256: "15f5acbf0dce90146a0f5a2c4a002b1814a6303c4c5c075aa2623b2d16156f03" url: "https://pub.dev" source: hosted - version: "6.0.35" + version: "6.0.36" url_launcher_ios: dependency: transitive description: @@ -1945,10 +1981,10 @@ packages: dependency: transitive description: name: url_launcher_platform_interface - sha256: "6c9ca697a5ae218ce56cece69d46128169a58aa8653c1b01d26fcd4aad8c4370" + sha256: bfdfa402f1f3298637d71ca8ecfe840b4696698213d5346e9d12d4ab647ee2ea url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.3" url_launcher_web: dependency: transitive description: @@ -1985,26 +2021,26 @@ packages: dependency: transitive description: name: vector_graphics - sha256: b96f10cbdfcbd03a65758633a43e7d04574438f059b1043104b5d61b23d38a4f + sha256: "670f6e07aca990b4a2bcdc08a784193c4ccdd1932620244c3a86bb72a0eac67f" url: "https://pub.dev" source: hosted - version: "1.1.6" + version: "1.1.7" vector_graphics_codec: dependency: transitive description: name: vector_graphics_codec - sha256: "57a8e6e24662a3bdfe3b3d61257db91768700c0b8f844e235877b56480f31c69" + sha256: "7451721781d967db9933b63f5733b1c4533022c0ba373a01bdd79d1a5457f69f" url: "https://pub.dev" source: hosted - version: "1.1.6" + version: "1.1.7" vector_graphics_compiler: dependency: transitive description: name: vector_graphics_compiler - sha256: "7430f5d834d0db4560d7b19863362cd892f1e52b43838553a3c5cdfc9ab28e5b" + sha256: "80a13c613c8bde758b1464a1755a7b3a8f2b6cec61fbf0f5a53c94c30f03ba2e" url: "https://pub.dev" source: hosted - version: "1.1.6" + version: "1.1.7" vector_math: dependency: transitive description: @@ -2057,38 +2093,34 @@ packages: dependency: "direct main" description: name: webview_flutter - sha256: "5604dac1178680a34fbe4a08c7b69ec42cca6601dc300009ec9ff69bef284cc2" + sha256: "789d52bd789373cc1e100fb634af2127e86c99cf9abde09499743270c5de8d00" url: "https://pub.dev" source: hosted - version: "4.2.1" + version: "4.2.2" webview_flutter_android: dependency: "direct main" description: name: webview_flutter_android - sha256: "57a22c86065375c1598b57224f92d6008141be0c877c64100de8bfb6f71083d8" - sha256: "57a22c86065375c1598b57224f92d6008141be0c877c64100de8bfb6f71083d8" + sha256: "532135f6f6b8030cd039f30eab23f340d650350e29f38e9b37d2eaad028f1018" url: "https://pub.dev" source: hosted - version: "3.7.1" - version: "3.7.1" + version: "3.8.0" webview_flutter_platform_interface: dependency: transitive description: name: webview_flutter_platform_interface sha256: "656e2aeaef318900fffd21468b6ddc7958c7092a642f0e7220bac328b70d4a81" - sha256: "656e2aeaef318900fffd21468b6ddc7958c7092a642f0e7220bac328b70d4a81" url: "https://pub.dev" source: hosted version: "2.3.1" - version: "2.3.1" webview_flutter_wkwebview: dependency: transitive description: name: webview_flutter_wkwebview - sha256: "6bbc6ade302b842999b27cbaa7171241c273deea8a9c73f92ceb3d811c767de2" + sha256: "7b203961d6830f3e5ed1df4c4f0493fea8388a46c4d43716167c4a8ba8ecbe83" url: "https://pub.dev" source: hosted - version: "3.4.4" + version: "3.6.0" win32: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index ac9a7a3a3..a74fc3e18 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -95,9 +95,10 @@ dependencies: webview_flutter: ^4.2.1 anytime: - git: - url: https://github.com/breez/anytime_podcast_player.git - ref: c9a97586b9f116014675a2c856b55f29731b93e2 + # git: + # url: https://github.com/breez/anytime_podcast_player.git + # ref: c9a97586b9f116014675a2c856b55f29731b93e2 + path: /Users/sarthakgupta/Documents/breez/breez_anytime/anytime/anytime_podcast_player flutter_downloader: git: url: https://github.com/breez/flutter_downloader.git From 5062f78f6eda73ffee137297960a9cb76fb387f2 Mon Sep 17 00:00:00 2001 From: Sarthak Gupta Date: Sun, 23 Jul 2023 14:39:14 +0530 Subject: [PATCH 2/9] toggle comments check --- lib/bloc/marketplace/marketplace_bloc.dart | 2 +- lib/bloc/marketplace/nostr_settings.dart | 16 +-- lib/home_page.dart | 8 ++ lib/routes/dev/dev.dart | 8 +- lib/user_app.dart | 4 + pubspec.lock | 160 +++++++++------------ 6 files changed, 91 insertions(+), 107 deletions(-) diff --git a/lib/bloc/marketplace/marketplace_bloc.dart b/lib/bloc/marketplace/marketplace_bloc.dart index 4737974e0..3af5f91c0 100644 --- a/lib/bloc/marketplace/marketplace_bloc.dart +++ b/lib/bloc/marketplace/marketplace_bloc.dart @@ -34,7 +34,7 @@ class MarketplaceBloc { _listenNostrSettings() async { SharedPreferences pref = await SharedPreferences.getInstance(); nostrSettingsStream.listen((settings) async { - _isSnortToggled = settings.showSnort; + _isSnortToggled = settings.enableNostr; pref.setString(NostrSettings.NOSTR_SETTINGS_PREFERENCES_KEY, json.encode(settings.toJson())); await loadVendors(); diff --git a/lib/bloc/marketplace/nostr_settings.dart b/lib/bloc/marketplace/nostr_settings.dart index 457a84dcd..023f03891 100644 --- a/lib/bloc/marketplace/nostr_settings.dart +++ b/lib/bloc/marketplace/nostr_settings.dart @@ -1,12 +1,10 @@ -import 'package:shared_preferences/shared_preferences.dart'; - class NostrSettings { - final bool showSnort; + final bool enableNostr; final bool isRememberPubKey; final bool isRememberSignEvent; NostrSettings( - {this.showSnort = true, + {this.enableNostr = true, this.isRememberPubKey = false, this.isRememberSignEvent = false}); @@ -14,15 +12,15 @@ class NostrSettings { NostrSettings.start() : this( - showSnort: true, + enableNostr: true, isRememberPubKey: false, isRememberSignEvent: false, ); NostrSettings copyWith( - {bool showSnort, bool isRememberPubKey, bool isRememberSignEvent}) { + {bool enableNostr, bool isRememberPubKey, bool isRememberSignEvent}) { return NostrSettings( - showSnort: showSnort ?? this.showSnort, + enableNostr: enableNostr ?? this.enableNostr, isRememberPubKey: isRememberPubKey ?? this.isRememberPubKey, isRememberSignEvent: isRememberSignEvent ?? this.isRememberSignEvent, ); @@ -30,13 +28,13 @@ class NostrSettings { NostrSettings.fromJson(Map json) : this( - showSnort: json["showSnort"] ?? true, + enableNostr: json["enableNostr"] ?? true, isRememberPubKey: json["isRememberPubKey"] ?? false, isRememberSignEvent: json["isRememberSignEvent"] ?? false, ); Map toJson() => { - "showSnort": showSnort, + "enableNostr": enableNostr, "isRememberPubKey": isRememberPubKey, "isRememberSignEvent": isRememberSignEvent, }; diff --git a/lib/home_page.dart b/lib/home_page.dart index 08d44f212..87fc30947 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -15,6 +15,7 @@ import 'package:breez/bloc/connect_pay/connect_pay_bloc.dart'; import 'package:breez/bloc/invoice/invoice_bloc.dart'; import 'package:breez/bloc/lnurl/lnurl_bloc.dart'; import 'package:breez/bloc/lsp/lsp_bloc.dart'; +import 'package:breez/bloc/marketplace/marketplace_bloc.dart'; import 'package:breez/bloc/nostr/nostr_bloc.dart'; import 'package:breez/bloc/reverse_swap/reverse_swap_bloc.dart'; import 'package:breez/bloc/user_profile/breez_user_model.dart'; @@ -74,6 +75,7 @@ class Home extends StatefulWidget { final ReverseSwapBloc reverseSwapBloc; final LNUrlBloc lnurlBloc; final NostrBloc nostrBloc; + final MarketplaceBloc marketplaceBloc; Home( this.accountBloc, @@ -85,6 +87,7 @@ class Home extends StatefulWidget { this.reverseSwapBloc, this.lnurlBloc, this.nostrBloc, + this.marketplaceBloc, ); final List _screens = List.unmodifiable([ @@ -135,8 +138,13 @@ class HomeState extends State with WidgetsBindingObserver { } }); }); + commentBloc = Provider.of(context, listen: false); + // widget.marketplaceBloc.nostrSettingsStream.listen((event) { + // commentBloc.toggleCommentController.add(event.enableNostr); + // }); + commentBloc.pubKeyStream.listen((event) async { widget.nostrBloc.actionsSink.add(GetPublicKey()); diff --git a/lib/routes/dev/dev.dart b/lib/routes/dev/dev.dart index 273961c57..e96a7ea43 100644 --- a/lib/routes/dev/dev.dart +++ b/lib/routes/dev/dev.dart @@ -616,10 +616,10 @@ class DevViewState extends State { ), ); choices.add(Choice( - title: "${nostrSettings.showSnort ? "Display" : "Hide"} Snort", + title: "${nostrSettings.enableNostr ? "Enable" : "Diable"} Nostr", icon: Icons.phone_android, function: () { - _toggleSnort(marketplaceBloc, nostrSettings); + _toggleNostr(marketplaceBloc, nostrSettings); }, )); @@ -633,13 +633,13 @@ class DevViewState extends State { .pushReplacementNamed("/splash"); }*/ - void _toggleSnort( + void _toggleNostr( MarketplaceBloc bloc, NostrSettings nostrSettings, ) { bloc.nostrSettingsSettingsSink.add( nostrSettings.copyWith( - showSnort: !nostrSettings.showSnort, + enableNostr: !nostrSettings.enableNostr, ), ); } diff --git a/lib/user_app.dart b/lib/user_app.dart index a9976e48c..e026f181e 100644 --- a/lib/user_app.dart +++ b/lib/user_app.dart @@ -46,6 +46,8 @@ import 'package:breez_translations/breez_translations_locales.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'bloc/marketplace/marketplace_bloc.dart'; + final routeObserver = RouteObserver(); Widget _withTheme(BreezUserModel user, Widget child) { @@ -78,6 +80,7 @@ class UserApp extends StatelessWidget { var lnurlBloc = AppBlocsProvider.of(context); var posCatalogBloc = AppBlocsProvider.of(context); var nostrBloc = AppBlocsProvider.of(context); + var marketplaceBloc = AppBlocsProvider.of(context); return StreamBuilder( stream: userProfileBloc.userStream, @@ -199,6 +202,7 @@ class UserApp extends StatelessWidget { reverseSwapBloc, lnurlBloc, nostrBloc, + marketplaceBloc, ), settings: settings, ); diff --git a/pubspec.lock b/pubspec.lock index c69ae2bd7..d648cac90 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -13,12 +13,10 @@ packages: dependency: transitive description: name: _flutterfire_internals - sha256: a742f71d7f3484253a623b30e19256aa4668ecbb3de6ad1beb0bcf8d4777ecd8 - sha256: a742f71d7f3484253a623b30e19256aa4668ecbb3de6ad1beb0bcf8d4777ecd8 + sha256: "5dce45a06d386358334eb1689108db6455d90ceb0d75848d5f4819283d4ee2b8" url: "https://pub.dev" source: hosted - version: "1.3.3" - version: "1.3.3" + version: "1.3.4" analyzer: dependency: transitive description: @@ -46,10 +44,10 @@ packages: dependency: "direct main" description: name: app_settings - sha256: "34c6b7dbf493d486b082f9538ea11b2ee665e7125618660555d5415592e78667" + sha256: e6a34735d4ddb24ca9c5fd7e965ec65c8b611cbd3a329152c294f9e9f4bacb33 url: "https://pub.dev" source: hosted - version: "4.3.0" + version: "4.3.1" archive: dependency: "direct main" description: @@ -63,11 +61,9 @@ packages: description: name: args sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 - sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 url: "https://pub.dev" source: hosted version: "2.4.2" - version: "2.4.2" async: dependency: transitive description: @@ -81,11 +77,9 @@ packages: description: name: audio_service sha256: "8b719ac7982fdea1a54a528f19e345907295489c53709ba4cdee65a2955c0f4d" - sha256: "8b719ac7982fdea1a54a528f19e345907295489c53709ba4cdee65a2955c0f4d" url: "https://pub.dev" source: hosted version: "0.18.10" - version: "0.18.10" audio_service_platform_interface: dependency: transitive description: @@ -107,11 +101,9 @@ packages: description: name: audio_session sha256: "8a2bc5e30520e18f3fb0e366793d78057fb64cd5287862c76af0c8771f2a52ad" - sha256: "8a2bc5e30520e18f3fb0e366793d78057fb64cd5287862c76af0c8771f2a52ad" url: "https://pub.dev" source: hosted version: "0.1.16" - version: "0.1.16" auto_size_text: dependency: "direct main" description: @@ -136,7 +128,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.2.4" - version: "2.2.4" base58check: dependency: transitive description: @@ -160,7 +151,7 @@ packages: sha256: "6794b226bc939731308b8539c49bb6c2fdbf0e78c3a65e9b9e81e727c256dfe6" url: "https://pub.dev" source: hosted - version: "2.0.6" + version: "2.0.7" bip32: dependency: transitive description: @@ -177,7 +168,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.1.0" - bip39: dependency: "direct main" description: @@ -331,14 +321,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.17.2" - comment_box: - dependency: transitive - description: - name: comment_box - sha256: "6a0d9cc8d181435b123cc4249c567bd8bdf1bde8d714691b069b942e3e7d4fbb" - url: "https://pub.dev" - source: hosted - version: "0.0.18" confetti: dependency: "direct main" description: @@ -464,10 +446,10 @@ packages: dependency: "direct main" description: name: dio - sha256: a9d76e72985d7087eb7c5e7903224ae52b337131518d127c554b9405936752b8 + sha256: "3866d67f93523161b643187af65f5ac08bc991a5bcdaf41a2d587fe4ccb49993" url: "https://pub.dev" source: hosted - version: "5.2.1+1" + version: "5.3.0" drag_and_drop_lists: dependency: "direct main" description: @@ -480,10 +462,10 @@ packages: dependency: "direct main" description: name: duration - sha256: d0b29d0a345429e3986ac56d60e4aef65b37d11e653022b2b9a4b361332b777f + sha256: "0548a12d235dab185c677ef660995f23fdc06a02a2b984aa23805f6a03d82815" url: "https://pub.dev" source: hosted - version: "3.0.12" + version: "3.0.13" email_validator: dependency: "direct main" description: @@ -568,10 +550,10 @@ packages: dependency: transitive description: name: file_selector_macos - sha256: "7a6f1ae6107265664f3f7f89a66074882c4d506aef1441c9af313c1f7e6f41ce" + sha256: "4ada532862917bf16e3adb3891fe3a5917a58bae03293e497082203a80909412" url: "https://pub.dev" source: hosted - version: "0.9.3" + version: "0.9.3+1" file_selector_platform_interface: dependency: transitive description: @@ -592,10 +574,10 @@ packages: dependency: "direct main" description: name: firebase_core - sha256: a4a99204da264a0aa9d54a332ea0315ce7b0768075139c77abefe98093dd98be + sha256: "2e9324f719e90200dc7d3c4f5d2abc26052f9f2b995d3b6626c47a0dfe1c8192" url: "https://pub.dev" source: hosted - version: "2.14.0" + version: "2.15.0" firebase_core_platform_interface: dependency: "direct main" description: @@ -616,66 +598,66 @@ packages: dependency: "direct main" description: name: firebase_database - sha256: "36699bda00feb31433606f034078c690f148c15a4721b351a83c796ba4bba4e7" + sha256: "08eff8d3321973f73f94633d807fb1f4589b4e2d2e0c33c7e656f42d2f9eba72" url: "https://pub.dev" source: hosted - version: "10.2.3" + version: "10.2.4" firebase_database_platform_interface: dependency: transitive description: name: firebase_database_platform_interface - sha256: "8bd62f80b51d71a81087a33fe2e2a868fb818a6e33b319a137a7bcb35dec262d" + sha256: db95e96b27c6d8ee4e1daf9ee7ff0e7433c5c340f9cfb5d855e65cbdb7430b9c url: "https://pub.dev" source: hosted - version: "0.2.5+3" + version: "0.2.5+4" firebase_database_web: dependency: transitive description: name: firebase_database_web - sha256: "05e6b0c2a192569cd5ce2be4a708756ca9f56e4c7b6fe1916f0f9d96a826f235" + sha256: "1ae57beac0a002d0a778bcde569c3fad2457b7ca3d9ef2936287e562d0af6962" url: "https://pub.dev" source: hosted - version: "0.2.3+3" + version: "0.2.3+4" firebase_dynamic_links: dependency: "direct main" description: name: firebase_dynamic_links - sha256: "9b984d0abd227a702451a997abcca763f4dbf67e260dad60e5506d55e3eff244" + sha256: "4872f4d7e94736041398bc3490c2ddd87ee159d6b051ba01ca2708e5260a7ebe" url: "https://pub.dev" source: hosted - version: "5.3.3" + version: "5.3.4" firebase_dynamic_links_platform_interface: dependency: transitive description: name: firebase_dynamic_links_platform_interface - sha256: "6ef00a0be18f3231e9727f7c4b31db89dbfa16792098beb850603c30854560ff" + sha256: "946fccfefb67e26bf63e392f1b3917d79ea031d3071488f0c5e8ab72de8219ab" url: "https://pub.dev" source: hosted - version: "0.2.6+3" + version: "0.2.6+4" firebase_messaging: dependency: "direct main" description: name: firebase_messaging - sha256: "7a09d8c21147f009882a27c96de1918ea283f974d73cb6fae1d234bb9ec18d8b" + sha256: "8ac91d83a028eef050de770f1dc98421e215714d245f34de7b154d436676fbd0" url: "https://pub.dev" source: hosted - version: "14.6.4" + version: "14.6.5" firebase_messaging_platform_interface: dependency: transitive description: name: firebase_messaging_platform_interface - sha256: e9e9dc48a3d8ffa67aaba3d6b1ebf74bc7d7d8c83d10b1458ff97878b9d8a2b0 + sha256: b2995e3640efb646e9ebf0e2fa50dea84895f0746a31d7e3af0e5e009a533a1a url: "https://pub.dev" source: hosted - version: "4.5.3" + version: "4.5.4" firebase_messaging_web: dependency: transitive description: name: firebase_messaging_web - sha256: "381f217e41e0e407baf8df21787b97e46fabfacefd6a953425be3a6cdf2269f4" + sha256: "5d8446a28339124a2cb4f57a6ca454a3aca7d0c5c0cdfa5707afb192f7c830a7" url: "https://pub.dev" source: hosted - version: "3.5.3" + version: "3.5.4" fixnum: dependency: "direct main" description: @@ -778,7 +760,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.13.1" - flutter_lints: dependency: "direct dev" description: @@ -1055,10 +1036,10 @@ packages: dependency: transitive description: name: image_picker_android - sha256: d2bab152deb2547ea6f53d82ebca9b7e77386bb706e5789e815d37e08ea475bb + sha256: "8179b54039b50eee561676232304f487602e2950ffb3e8995ed9034d6505ca34" url: "https://pub.dev" source: hosted - version: "0.8.7+3" + version: "0.8.7+4" image_picker_for_web: dependency: transitive description: @@ -1091,15 +1072,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.2.1" - image_picker_platform_interface: dependency: transitive description: name: image_picker_platform_interface - sha256: "7c7b96bb9413a9c28229e717e6fd1e3edd1cc5569c1778fcca060ecf729b65ee" + sha256: c1134543ae2187e85299996d21c526b2f403854994026d575ae4cf30d7bb2a32 url: "https://pub.dev" source: hosted - version: "2.8.0" + version: "2.9.0" image_picker_windows: dependency: transitive description: @@ -1188,6 +1168,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.3" + lints: + dependency: transitive + description: + name: lints + sha256: "5e4a9cd06d447758280a8ac2405101e0e2094d2a1dbdd3756aec3fe7775ba593" + url: "https://pub.dev" + source: hosted + version: "2.0.1" list_counter: dependency: transitive description: @@ -1386,10 +1374,10 @@ packages: dependency: transitive description: name: path_provider_foundation - sha256: "1995d88ec2948dac43edf8fe58eb434d35d22a2940ecee1a9fefcd62beee6eb3" + sha256: "916731ccbdce44d545414dd9961f26ba5fbaa74bcbb55237d8e65a623a8c7297" url: "https://pub.dev" source: hosted - version: "2.2.3" + version: "2.2.4" path_provider_linux: dependency: transitive description: @@ -1442,36 +1430,34 @@ packages: dependency: transitive description: name: permission_handler - sha256: "1b6b3e73f0bcbc856548bbdfb1c33084a401c4f143e220629a9055233d76c331" + sha256: "63e5216aae014a72fe9579ccd027323395ce7a98271d9defa9d57320d001af81" url: "https://pub.dev" source: hosted - version: "10.3.0" + version: "10.4.3" permission_handler_android: dependency: transitive description: name: permission_handler_android - sha256: "8f6a95ccbca13766882f95d32684d7c9bfe6c45650c32bedba948ef1c6a4ddf7" + sha256: "2ffaf52a21f64ac9b35fe7369bb9533edbd4f698e5604db8645b1064ff4cf221" url: "https://pub.dev" source: hosted - version: "10.3.0" + version: "10.3.3" permission_handler_apple: dependency: transitive description: name: permission_handler_apple - - sha256: "7a187b671a39919462af2b5e813148365b71a615979165a119868d667fe90c03" + sha256: "99e220bce3f8877c78e4ace901082fb29fa1b4ebde529ad0932d8d664b34f3f5" url: "https://pub.dev" source: hosted - version: "9.1.3" + version: "9.1.4" permission_handler_platform_interface: dependency: transitive description: name: permission_handler_platform_interface - - sha256: "463a07cb7cc6c758a7a1c7da36ce666bb80a0b4b5e92df0fa36872e0ed456993" + sha256: "7c6b1500385dd1d2ca61bb89e2488ca178e274a69144d26bbd65e33eae7c02a9" url: "https://pub.dev" source: hosted - version: "3.11.1" + version: "3.11.3" permission_handler_windows: dependency: transitive description: @@ -1500,10 +1486,10 @@ packages: dependency: "direct main" description: name: plugin_platform_interface - sha256: "6a2128648c854906c53fa8e33986fc0247a1116122f9534dd20e3ab9e16a32bc" + sha256: "43798d895c929056255600343db8f049921cbec94d31ec87f1dc5c16c01935dd" url: "https://pub.dev" source: hosted - version: "2.1.4" + version: "2.1.5" podcast_search: dependency: "direct main" description: @@ -1537,14 +1523,6 @@ packages: url: "https://pub.dev" source: hosted version: "5.10.4" - process: - dependency: transitive - description: - name: process - sha256: "53fd8db9cec1d37b0574e12f07520d582019cb6c44abf5479a01505099a34a09" - url: "https://pub.dev" - source: hosted - version: "4.2.4" protobuf: dependency: "direct main" description: @@ -1662,11 +1640,10 @@ packages: dependency: transitive description: name: shared_preferences_foundation - - sha256: b046999bf0ff58f04c364491bb803dcfa8f42e47b19c75478f53d323684a8cc1 + sha256: f39696b83e844923b642ce9dd4bd31736c17e697f6731a5adf445b1274cf3cd4 url: "https://pub.dev" source: hosted - version: "2.3.1" + version: "2.3.2" shared_preferences_linux: dependency: transitive description: @@ -1964,10 +1941,10 @@ packages: dependency: transitive description: name: url_launcher_android - sha256: "15f5acbf0dce90146a0f5a2c4a002b1814a6303c4c5c075aa2623b2d16156f03" + sha256: "78cb6dea3e93148615109e58e42c35d1ffbf5ef66c44add673d0ab75f12ff3af" url: "https://pub.dev" source: hosted - version: "6.0.36" + version: "6.0.37" url_launcher_ios: dependency: transitive description: @@ -1988,10 +1965,10 @@ packages: dependency: transitive description: name: url_launcher_macos - sha256: "91ee3e75ea9dadf38036200c5d3743518f4a5eb77a8d13fda1ee5764373f185e" + sha256: "1c4fdc0bfea61a70792ce97157e5cc17260f61abbe4f39354513f39ec6fd73b1" url: "https://pub.dev" source: hosted - version: "3.0.5" + version: "3.0.6" url_launcher_platform_interface: dependency: transitive description: @@ -2109,7 +2086,6 @@ packages: description: name: webview_flutter sha256: "789d52bd789373cc1e100fb634af2127e86c99cf9abde09499743270c5de8d00" - sha256: "789d52bd789373cc1e100fb634af2127e86c99cf9abde09499743270c5de8d00" url: "https://pub.dev" source: hosted version: "4.2.2" @@ -2117,28 +2093,26 @@ packages: dependency: "direct main" description: name: webview_flutter_android - - sha256: "1c93e96f3069bacdc734fad6b7e1d3a480fd516a3ae5b8858becf7f07515a2f3" + sha256: "8587d0b4991bd0f223f4b4957101c2c7449f905601571315f4967072498dd3fb" url: "https://pub.dev" source: hosted - version: "3.8.2" + version: "3.9.1" webview_flutter_platform_interface: dependency: transitive description: name: webview_flutter_platform_interface - sha256: "656e2aeaef318900fffd21468b6ddc7958c7092a642f0e7220bac328b70d4a81" + sha256: "564ef378cafc1a0e29f1d76ce175ef517a0a6115875dff7b43fccbef2b0aeb30" url: "https://pub.dev" source: hosted - version: "2.3.1" + version: "2.4.0" webview_flutter_wkwebview: dependency: transitive description: name: webview_flutter_wkwebview - - sha256: a8d7e8b4be2a79e83b70235369971ec97d14df4cdbb40d305a8eeae67d8e6432 + sha256: "3e36a8f564809cb7c257ff4278502b185e2191349df0ddee98837f91805c74b8" url: "https://pub.dev" source: hosted - version: "3.6.2" + version: "3.7.1" win32: dependency: transitive description: @@ -2159,10 +2133,10 @@ packages: dependency: transitive description: name: xdg_directories - sha256: ee1505df1426458f7f60aac270645098d318a8b4766d85fde75f76f2e21807d1 + sha256: e0b1147eec179d3911f1f19b59206448f78195ca1d20514134e10641b7d7fbff url: "https://pub.dev" source: hosted - version: "1.0.0" + version: "1.0.1" xml: dependency: transitive description: From 93a07611cf36a4dfe54b43533a0f08e83e9e5095 Mon Sep 17 00:00:00 2001 From: Sarthak Gupta Date: Thu, 27 Jul 2023 22:29:55 +0530 Subject: [PATCH 3/9] toggle comments changes --- lib/home_page.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/home_page.dart b/lib/home_page.dart index 87fc30947..f8a693866 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -141,9 +141,9 @@ class HomeState extends State with WidgetsBindingObserver { commentBloc = Provider.of(context, listen: false); - // widget.marketplaceBloc.nostrSettingsStream.listen((event) { - // commentBloc.toggleCommentController.add(event.enableNostr); - // }); + widget.marketplaceBloc.nostrSettingsStream.listen((event) { + commentBloc.toggleCommentController.add(!event.enableNostr); + }); commentBloc.pubKeyStream.listen((event) async { widget.nostrBloc.actionsSink.add(GetPublicKey()); From 5f7e0daf0db979e93ec60d45e12a66462791c843 Mon Sep 17 00:00:00 2001 From: Sarthak Gupta Date: Thu, 27 Jul 2023 23:09:48 +0530 Subject: [PATCH 4/9] Disable Nostr title corrected --- lib/routes/dev/dev.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/routes/dev/dev.dart b/lib/routes/dev/dev.dart index e96a7ea43..23a7f6fdc 100644 --- a/lib/routes/dev/dev.dart +++ b/lib/routes/dev/dev.dart @@ -616,7 +616,7 @@ class DevViewState extends State { ), ); choices.add(Choice( - title: "${nostrSettings.enableNostr ? "Enable" : "Diable"} Nostr", + title: "${nostrSettings.enableNostr ? "Enable" : "Disable"} Nostr", icon: Icons.phone_android, function: () { _toggleNostr(marketplaceBloc, nostrSettings); From 610bed53805365c9d67953a251f0391eca57d153 Mon Sep 17 00:00:00 2001 From: Sarthak Gupta Date: Sat, 29 Jul 2023 16:01:19 +0530 Subject: [PATCH 5/9] anytime ref changes --- pubspec.yaml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 11c30bc38..8e201d4a5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -95,10 +95,9 @@ dependencies: webview_flutter: ^4.2.1 anytime: - # git: - # url: https://github.com/breez/anytime_podcast_player.git - # ref: c9a97586b9f116014675a2c856b55f29731b93e2 - path: /Users/sarthakgupta/Documents/breez/breez_anytime/anytime/anytime_podcast_player + git: + url: https://github.com/breez/anytime_podcast_player.git + ref: c9a97586b9f116014675a2c856b55f29731b93e2 flutter_downloader: git: url: https://github.com/breez/flutter_downloader.git From 9100324148868f9b90be7b3c1f174f69e9cf1c62 Mon Sep 17 00:00:00 2001 From: Sarthak Gupta Date: Fri, 11 Aug 2023 15:14:45 +0530 Subject: [PATCH 6/9] commentsBloc -> NostrCommentBloc --- lib/home_page.dart | 6 +++--- lib/routes/podcast/podcast_page.dart | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/home_page.dart b/lib/home_page.dart index f8a693866..e8bd975f7 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:anytime/bloc/comments/comments_bloc.dart'; +import 'package:anytime/bloc/nostr_comments/nostr_comments_bloc.dart'; import 'package:anytime/bloc/podcast/audio_bloc.dart'; import 'package:anytime/ui/anytime_podcast_app.dart'; import 'package:anytime/ui/podcast/now_playing.dart'; @@ -107,7 +107,7 @@ class HomeState extends State with WidgetsBindingObserver { final Set _hiddenRoutes = {}; StreamSubscription _accountNotificationsSubscription; bool _listensInit = false; - CommentBloc commentBloc; + NostrCommentBloc commentBloc; @override void initState() { @@ -139,7 +139,7 @@ class HomeState extends State with WidgetsBindingObserver { }); }); - commentBloc = Provider.of(context, listen: false); + commentBloc = Provider.of(context, listen: false); widget.marketplaceBloc.nostrSettingsStream.listen((event) { commentBloc.toggleCommentController.add(!event.enableNostr); diff --git a/lib/routes/podcast/podcast_page.dart b/lib/routes/podcast/podcast_page.dart index 1eff30bd0..1eadb067c 100644 --- a/lib/routes/podcast/podcast_page.dart +++ b/lib/routes/podcast/podcast_page.dart @@ -1,7 +1,7 @@ import 'package:anytime/api/podcast/podcast_api.dart'; -import 'package:anytime/bloc/comments/comments_bloc.dart'; import 'package:anytime/bloc/discovery/discovery_bloc.dart'; import 'package:anytime/bloc/new_podcasts/new_podcasts_bloc.dart'; +import 'package:anytime/bloc/nostr_comments/nostr_comments_bloc.dart'; import 'package:anytime/bloc/podcast/audio_bloc.dart'; import 'package:anytime/bloc/podcast/episode_bloc.dart'; import 'package:anytime/bloc/podcast/opml_bloc.dart'; @@ -182,8 +182,8 @@ class AnytimePodcastAppState extends State { ), dispose: (_, value) => value.dispose(), ), - Provider( - create: (_) => CommentBloc( + Provider( + create: (_) => NostrCommentBloc( episodeStream: widget.audioPlayerService.episodeEvent), dispose: (_, value) => value.dispose(), ), From 22e0afe8fc6411999dae26abc0269080b137e5f8 Mon Sep 17 00:00:00 2001 From: Sarthak Gupta Date: Tue, 15 Aug 2023 20:30:05 +0530 Subject: [PATCH 7/9] anytime ref changes --- pubspec.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 5dfddfeff..6cd53bb83 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -69,7 +69,6 @@ dependencies: protobuf: <3.0.0 # Requires Flutter 3.10 provider: ^6.0.5 meta: ^1.9.1 - mobile_scanner: ^3.4.1 # qr_flutter has already fixed the build issue with the qr package but did not publish an updated # version, they will publish as 4.0.1 for now they recommend to use the master but instead of that # we are using an specific commit to avoid unexpected behaviour in future builds. @@ -96,8 +95,8 @@ dependencies: anytime: git: - url: https://github.com/breez/anytime_podcast_player.git - ref: f8eb92fb61165b1eb018d928adcf689f0bc9e554 + url: https://github.com/sarthak13gupta/anytime_podcast_player + ref: 89be27a95763bfb7878f4143784d17db54799641 flutter_downloader: git: url: https://github.com/breez/flutter_downloader.git @@ -114,6 +113,7 @@ dependencies: git: url: https://github.com/breez/nfc_in_flutter.git ref: 97f610be82bfe42d5ce86c348d931d61949fa517 + mobile_scanner: 3.3.0 dependency_overrides: collection: ^1.18.0 From f8980845419f3d40ac77412cf73da89d89400c1a Mon Sep 17 00:00:00 2001 From: Sarthak Gupta Date: Tue, 5 Sep 2023 16:13:38 +0530 Subject: [PATCH 8/9] injecting nostrComments from BreezMobile to Anytime(without toggling) --- .../nostr_comments/nostr_comments_bloc.dart | 403 ++++++++++++++++++ .../nostr_comments/nostr_comments_model.dart | 58 +++ .../nostr_comments_state_event.dart | 23 + lib/home_page.dart | 26 -- lib/main.dart | 6 +- lib/routes/podcast/comment_child.dart | 49 +++ lib/routes/podcast/comment_render.dart | 108 +++++ lib/routes/podcast/episode_comment_box.dart | 147 +++++++ lib/routes/podcast/episode_comments.dart | 117 +++++ lib/routes/podcast/podcast_page.dart | 18 +- lib/widgets/comment_user_image.dart | 51 +++ 11 files changed, 975 insertions(+), 31 deletions(-) create mode 100644 lib/bloc/nostr/nostr_comments/nostr_comments_bloc.dart create mode 100644 lib/bloc/nostr/nostr_comments/nostr_comments_model.dart create mode 100644 lib/bloc/nostr/nostr_comments/nostr_comments_state_event.dart create mode 100644 lib/routes/podcast/comment_child.dart create mode 100644 lib/routes/podcast/comment_render.dart create mode 100644 lib/routes/podcast/episode_comment_box.dart create mode 100644 lib/routes/podcast/episode_comments.dart create mode 100644 lib/widgets/comment_user_image.dart diff --git a/lib/bloc/nostr/nostr_comments/nostr_comments_bloc.dart b/lib/bloc/nostr/nostr_comments/nostr_comments_bloc.dart new file mode 100644 index 000000000..c856de16b --- /dev/null +++ b/lib/bloc/nostr/nostr_comments/nostr_comments_bloc.dart @@ -0,0 +1,403 @@ +import 'dart:async'; +import 'dart:convert'; + +import 'package:anytime/entities/episode.dart'; +import 'package:breez/bloc/blocs_provider.dart'; +import 'package:breez/bloc/nostr/nostr_actions.dart'; +import 'package:breez/bloc/nostr/nostr_bloc.dart'; +import 'package:breez/bloc/nostr/nostr_comments/nostr_comments_model.dart'; +import 'package:breez/bloc/nostr/nostr_comments/nostr_comments_state_event.dart'; +import 'package:nostr_tools/nostr_tools.dart'; + +class NostrCommentBloc extends Bloc { + final Stream episodeStream; + final NostrBloc nostrBloc; + NostrCommentBloc({this.episodeStream, this.nostrBloc}) { + init(); + } + + final relaysList = [ + "wss://relay.damus.io", + "wss://nostr1.tunnelsats.com", + "wss://nostr-pub.wellorder.net", + "wss://relay.nostr.info", + "wss://nostr-relay.wlvs.space", + "wss://nostr.bitcoiner.social", + "wss://nostr-01.bolt.observer", + "wss://relayer.fiatjaf.com", + ]; + RelayPoolApi _relayPool; + + Set _connectedRelays; + + List sortedEvents; + String _rootId; + bool isRootEventPresent; + Episode currentEpisode; + String replyToRoot; + + String userPubKey; + + Map metaDatas; + + Map _eventMap; + + bool _isAddEventToController; + + bool isRelayConnected; + + bool nostrEnabled = false; + + List _userRelayList; + + final StreamController toggleCommentController = + StreamController.broadcast(); + + Stream get toggleCommentStream => toggleCommentController.stream; + + final StreamController commentActionController = + StreamController.broadcast(); + + Stream get commentActionStream => + commentActionController.stream; + + final StreamController _eventController = + StreamController.broadcast(); + + final StreamController _publicKeyController = + StreamController.broadcast(); + + final StreamController> _signEventController = + StreamController>.broadcast(); + + final StreamController _userMetaDataController = + StreamController.broadcast(); + + Stream get userMetaDataStream => _userMetaDataController.stream; + + Stream get pubKeyStream => _publicKeyController.stream; + Stream> get signEventStream => + _signEventController.stream; + + Map previousEvent; + + Stream stream = StreamController.broadcast().stream; + + Stream _streamConnect; + StreamSubscription _streamSubscription; + + Stream get eventStream => _eventController.stream; + + void init() { + _relayPool = RelayPoolApi(relaysList: relaysList); + metaDatas = {}; + _eventMap = {}; + sortedEvents = []; + _isAddEventToController = false; + _isAddEventToController = false; + isRelayConnected = false; + + _listenToEnableNostr(); + + // making sure keyPair is generated and fetching the pubKey + _getPubKey(); + + _listenToEpisode(); + _listenToActions(); + } + + void _listenToEnableNostr() { + toggleCommentStream.listen((event) { + nostrEnabled = event; + }); + } + + void _listenToActions() { + commentActionStream.listen((event) { + if (event is CreateRootComment) { + createRootEvent(event.userComment); + } else if (event is CreateReplyComment) { + createComment(event.userComment); + } else if (event is ReloadConnection) { + reloadConnection(); + } else if (event is GetUserPubKey) { + _getPubKey(); + } + }); + } + + // setting listener for episode + void _listenToEpisode() { + episodeStream.listen((episode) { + if (currentEpisode == null && episode != null) { + currentEpisode = episode; + initRelayConnection(); + } + // reload in case of a different episode + else if (currentEpisode != episode) { + currentEpisode = episode; + reloadConnection(); + } + }); + } + + void _getUserMetaData(Metadata metadata) async { + String profile = metadata.nip05; + // fetching the nip05 identifier of the user to get their RelayList + ProfilePointer nostrProfile = await Nip05().queryProfile(profile); + _userRelayList = nostrProfile?.relays; + if (_userRelayList != null) { + _relayPool = RelayPoolApi(relaysList: _userRelayList); + reloadConnection(); + } + _userMetaDataController.add(metadata); + } + + // create a comment + Future createComment(String content) async { + Map eventData = { + "created_at": DateTime.now().millisecondsSinceEpoch ~/ 1000, + "kind": 1, + "tags": [ + ['e', _rootId], + ], + "content": content, + }; + await signEvent(eventData); + } + + Future reloadConnection() async { + // setting each variable to its default value + isRootEventPresent = false; + _isAddEventToController = false; + isRelayConnected = false; + _rootId = null; + sortedEvents.clear(); + metaDatas.clear(); + _eventMap.clear(); + _connectedRelays.clear(); + + // need to close the relay stream for a fresh connection + _relayPool.close(); + _streamSubscription?.cancel(); + + // calling relay connection again + await initRelayConnection(); + } + + Future createRootEvent(String userComment) async { + replyToRoot = userComment; + // if no Root Event present then create one + Map eventData = { + "created_at": DateTime.now().millisecondsSinceEpoch ~/ 1000, + "kind": 1, + "tags": [ + ['t', currentEpisode.contentUrl], + ], + "content": + "comments about episode ${currentEpisode.title} at ${currentEpisode.contentUrl}", + }; + await signEvent(eventData); + } + + Future initRelayConnection() async { + // connecting to relays + try { + _streamConnect = await _relayPool.connect(); + + _relayPool.on((event) { + if (event == RelayEvent.connect) { + isRelayConnected = true; + // if relay is connected add this to _isConnectedController + } else if (event == RelayEvent.error || + event == RelayEvent.disconnect) {} + _connectedRelays = _relayPool.connectedRelays; + if (_connectedRelays.isEmpty) { + isRelayConnected = false; + } + }); + } catch (e) { + throw Exception(e); + } + + // for fetching userMetaData + _relayPool.sub([ + Filter( + kinds: [1], + authors: [userPubKey], + ), + ]); + + // checking for root event to be present or not + if (_rootId == null) { + _relayPool.sub([ + Filter( + kinds: [1], + // limit: 1, + t: [currentEpisode.contentUrl], + ) + ]); + } else { + _relayPool.sub([ + Filter( + kinds: [1], + limit: 100, + // denoting that this is a root level reply + e: [_rootId], + ) + ]); + } + + try { + _streamSubscription = _streamConnect.listen( + (message) { + if (message.type == 'EVENT') { + Event event = message.message as Event; + if (event.kind == 1) { + // check for being the rootEvent + if (event.tags.isNotEmpty && + event.tags[0][0] == "t" && + event.tags[0][1] == currentEpisode.contentUrl) { + _rootId = event.id; + isRootEventPresent = true; + + _relayPool.sub([ + Filter( + kinds: [1], + limit: 100, + // denoting that this is a root level reply + e: [_rootId], + ) + ]); + } else if (event.tags.isNotEmpty && + event.tags[0][0] == "e" && + event.tags[0][1] == _rootId) { + _addEvent(event); + + // if event is already present in List then return to avoid duplication + if (_isAddEventToController == false) { + return; + } + + _eventController.add(event); + // setting _addEventController to false to check for the next event to be added + _isAddEventToController = false; + } + + // to get the metadata of the user of the comment + _relayPool.sub([ + Filter(kinds: [0], authors: [event.pubkey]) + ]); + } else if (event.kind == 0) { + Metadata metadata = Metadata.fromJson( + jsonDecode(event.content) as Map); + if (event.pubkey == userPubKey) { + _getUserMetaData(metadata); + } + metaDatas[event.pubkey] = metadata; + } + } + }, + ); + } catch (e) { + throw Exception(e); + } + } + + void _insertInDescendingOrder(Event event) { + // using binary search to insert the new event + int start = 0; + int end = sortedEvents.length - 1; + int midpoint; + int position = start; + + if (end < 0) { + position = 0; + } else if (event.created_at < sortedEvents[end].created_at) { + position = end + 1; + } else if (event.created_at >= sortedEvents[start].created_at) { + position = start; + } else { + while (true) { + if (end <= start + 1) { + position = end; + break; + } + midpoint = (start + (end - start) / 2).floor(); + if (sortedEvents[midpoint].created_at > event.created_at) { + start = midpoint; + } else if (sortedEvents[midpoint].created_at > event.created_at) { + end = midpoint; + } else { + position = midpoint; + } + } + } + sortedEvents.insert(position, event); + } + + void _addEvent(Event event) { + if (_eventMap.containsKey(event.id) == false) { + // adding the event according its creation time + _insertInDescendingOrder(event); + _isAddEventToController = true; + _eventMap[event.id] = true; + } else { + _isAddEventToController = false; + } + } + + // this method is to make sure keyPair is made before signing the sortedEvents + Future _getPubKey() async { + nostrBloc.actionsSink.add(GetPublicKey()); + } + + Future signEvent(Map eventData) async { + // _signEventController.add(eventData); + + nostrBloc.actionsSink.add(SignEvent(eventData, nostrBloc.nostrPrivateKey)); + Map signedEvent = await nostrBloc.eventStream.first; + final signedNostrEvent = CommentEvent.mapToEvent(signedEvent); + await _publishNewEvent(signedNostrEvent); + } + + void getPubKeyResult(String pubKey) { + print('Received public key from Breez: $pubKey'); + userPubKey = pubKey; + } + + // Future signEventResult(Map signedEvent) async { + // final signedNostrEvent = CommentEvent.mapToEvent(signedEvent); + + // await _publishNewEvent(signedNostrEvent); + // } + + Future _publishNewEvent(Event signedNostrEvent) async { + try { + _relayPool.publish(signedNostrEvent); + } catch (e) { + throw Exception(e); + } + + // if it was the root event being published + // creating the user comment as a reply to it + if (signedNostrEvent.tags[0][0] == 't' && + signedNostrEvent.tags[0][1] == currentEpisode.contentUrl) { + _rootId = signedNostrEvent.id; + isRootEventPresent = true; + await createComment(replyToRoot); + } + } + + @override + void dispose() { + // super.dispose(); + _relayPool.close(); + _eventController.close(); + _publicKeyController.close(); + _signEventController.close(); + toggleCommentController.close(); + commentActionController.close(); + _userMetaDataController.close(); + } +} diff --git a/lib/bloc/nostr/nostr_comments/nostr_comments_model.dart b/lib/bloc/nostr/nostr_comments/nostr_comments_model.dart new file mode 100644 index 000000000..2173e92c2 --- /dev/null +++ b/lib/bloc/nostr/nostr_comments/nostr_comments_model.dart @@ -0,0 +1,58 @@ +import 'package:nostr_tools/nostr_tools.dart'; + +class CommentModel { + String userName; + String userPic; + String userMessage; + String date; + String replyTo; + String id; + bool showReplies; + CommentModel({ + this.userName, + this.userPic, + this.userMessage, + this.date, + this.replyTo, + this.id, + this.showReplies, + }); +} + +class CommentEvent { + static Event mapToEvent(Map comment) { + return Event( + kind: comment['kind'] as int, + tags: comment['tags'] as List>, + content: comment['content'] as String, + created_at: comment['created_at'] as int, + id: comment['id'] as String, + sig: comment['sig'] as String, + pubkey: comment['pubkey'] as String, + ); + } +} + +class TimeAgo { + static String format(int timestamp) { + DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000); + Duration difference = DateTime.now().difference(dateTime); + + String timeAgo = ''; + + if (difference.inDays > 0) { + timeAgo = + '${difference.inDays} ${difference.inDays == 1 ? 'day' : 'days'} ago'; + } else if (difference.inHours > 0) { + timeAgo = + '${difference.inHours} ${difference.inHours == 1 ? 'hour' : 'hours'} ago'; + } else if (difference.inMinutes > 0) { + timeAgo = + '${difference.inMinutes} ${difference.inMinutes == 1 ? 'minute' : 'minutes'} ago'; + } else { + timeAgo = 'just now'; + } + + return timeAgo; + } +} diff --git a/lib/bloc/nostr/nostr_comments/nostr_comments_state_event.dart b/lib/bloc/nostr/nostr_comments/nostr_comments_state_event.dart new file mode 100644 index 000000000..5d36b4a73 --- /dev/null +++ b/lib/bloc/nostr/nostr_comments/nostr_comments_state_event.dart @@ -0,0 +1,23 @@ +class CommentAction {} + +/// Events +class CreateRootComment extends CommentAction { + final String userComment; + CreateRootComment(this.userComment); +} + +class CreateReplyComment extends CommentAction { + final String userComment; + CreateReplyComment(this.userComment); +} + +class ReloadConnection extends CommentAction { + ReloadConnection(); +} + +class GetUserPubKey extends CommentAction { + GetUserPubKey(); +} + +/// State +class CommentLoadingState extends CommentAction {} diff --git a/lib/home_page.dart b/lib/home_page.dart index e8bd975f7..3a2fda6b5 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -1,6 +1,5 @@ import 'dart:async'; -import 'package:anytime/bloc/nostr_comments/nostr_comments_bloc.dart'; import 'package:anytime/bloc/podcast/audio_bloc.dart'; import 'package:anytime/ui/anytime_podcast_app.dart'; import 'package:anytime/ui/podcast/now_playing.dart'; @@ -107,7 +106,6 @@ class HomeState extends State with WidgetsBindingObserver { final Set _hiddenRoutes = {}; StreamSubscription _accountNotificationsSubscription; bool _listensInit = false; - NostrCommentBloc commentBloc; @override void initState() { @@ -139,30 +137,6 @@ class HomeState extends State with WidgetsBindingObserver { }); }); - commentBloc = Provider.of(context, listen: false); - - widget.marketplaceBloc.nostrSettingsStream.listen((event) { - commentBloc.toggleCommentController.add(!event.enableNostr); - }); - - commentBloc.pubKeyStream.listen((event) async { - widget.nostrBloc.actionsSink.add(GetPublicKey()); - - final publicKey = await widget.nostrBloc.publicKeyStream.first; - commentBloc.getPubKeyResult(publicKey); - }); - - // Listener for signing the comment - commentBloc.signEventStream.listen((event) async { - final nostrPrivateKey = widget.nostrBloc.nostrPrivateKey; - - widget.nostrBloc.actionsSink.add(SignEvent(event, nostrPrivateKey)); - - final Map signedEventObject = - await widget.nostrBloc.eventStream.first; - commentBloc.signEventResult(signedEventObject); - }); - AudioService.notificationClicked.where((event) => event == true).listen( (event) async { final navigator = Navigator.of(context); diff --git a/lib/main.dart b/lib/main.dart index 6ffc73bb6..119f77191 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -69,8 +69,10 @@ void main() async { builder: sharePodcastButtonBuilder, child: ShareEpisodeButtonBuilder( builder: shareEpisodeButtonBuilder, - child: - UserApp(repository.reloadDatabaseSink))))), + child: NostrCommentsBuilder( + builder: nostrCommentsBuilder, + child: UserApp( + repository.reloadDatabaseSink)))))), )))); }); }, (error, stackTrace) async { diff --git a/lib/routes/podcast/comment_child.dart b/lib/routes/podcast/comment_child.dart new file mode 100644 index 000000000..683d772bf --- /dev/null +++ b/lib/routes/podcast/comment_child.dart @@ -0,0 +1,49 @@ +import 'package:breez/bloc/nostr/nostr_comments/nostr_comments_model.dart'; +import 'package:breez/widgets/comment_user_image.dart'; +import 'package:flutter/material.dart'; + +class CommentChild extends StatefulWidget { + final CommentModel userRootComment; + + CommentChild(this.userRootComment); + + @override + State createState() => _CommentChildState(); +} + +class _CommentChildState extends State { + Widget userCommentTree = Container(); + + @override + Widget build(BuildContext context) { + final themeData = Theme.of(context); + return Theme( + data: themeData, + child: Padding( + padding: const EdgeInsets.fromLTRB(2.0, 8.0, 2.0, 0.0), + child: Column( + children: [ + ListTile( + leading: Container( + height: 35.0, + width: 35.0, + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(50))), + child: + CommentUserImage(userImage: widget.userRootComment.userPic), + ), + title: Text( + '@${widget.userRootComment.userName} • ${widget.userRootComment.date}', + style: themeData.primaryTextTheme.bodySmall, + ), + subtitle: Text( + widget.userRootComment.userMessage, + style: themeData.primaryTextTheme.bodyLarge, + ), + ), + ], + ), + ), + ); + } +} diff --git a/lib/routes/podcast/comment_render.dart b/lib/routes/podcast/comment_render.dart new file mode 100644 index 000000000..72fc96e07 --- /dev/null +++ b/lib/routes/podcast/comment_render.dart @@ -0,0 +1,108 @@ +import 'package:anytime/ui/widgets/delayed_progress_indicator.dart'; +import 'package:breez/bloc/nostr/nostr_comments/nostr_comments_bloc.dart'; +import 'package:breez/bloc/nostr/nostr_comments/nostr_comments_model.dart'; +import 'package:breez/routes/podcast/comment_child.dart'; +import 'package:flutter/material.dart'; + +import 'package:nostr_tools/nostr_tools.dart'; + +class CommentRender extends StatefulWidget { + final NostrCommentBloc commentBloc; + const CommentRender({Key key, this.commentBloc}) : super(key: key); + + @override + State createState() => _CommentRenderState(); +} + +class _CommentRenderState extends State { + List _events = []; + Map _metaDatas = {}; + + Stream relayStream; + + @override + void initState() { + super.initState(); + _init(); + _setCommentListener(); + } + + void _init() { + _events = widget.commentBloc.sortedEvents; + _metaDatas = widget.commentBloc.metaDatas; + } + + void _setCommentListener() { + widget.commentBloc.eventStream.listen((Event event) { + setState(() { + _events = widget.commentBloc.sortedEvents; + _metaDatas = widget.commentBloc.metaDatas; + }); + }); + } + + CommentModel _formUserComment(Event event, Metadata metadata) { + return CommentModel( + userName: metadata?.displayName ?? + (metadata?.display_name ?? + Nip19().npubEncode(event.pubkey).substring(0, 11)), + userPic: metadata?.picture, + userMessage: event.content, + date: TimeAgo.format(event.created_at), + id: event.id, + ); + } + + @override + Widget build(BuildContext context) { + return StreamBuilder( + stream: widget.commentBloc.eventStream, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + if (_events.isNotEmpty) + Expanded( + child: ListView.builder( + itemCount: _events.length, + itemBuilder: (context, index) { + final event = _events[index]; + final metadata = _metaDatas[event.pubkey]; + final userRootComment = _formUserComment(event, metadata); + + return CommentChild(userRootComment); + }, + ), + ), + SizedBox( + height: 10, + ), + DelayedCircularProgressIndicator(), + ], + ); + } + if (snapshot.connectionState == ConnectionState.active || + snapshot.connectionState == ConnectionState.done) { + return ListView.builder( + itemCount: _events.length, + itemBuilder: (context, index) { + final event = _events[index]; + final metadata = _metaDatas[event.pubkey]; + final userRootComment = _formUserComment(event, metadata); + + return CommentChild(userRootComment); + }, + ); + } else if (snapshot.hasError) { + return Center( + child: Text('${snapshot.error}'), + ); + } else { + return DelayedCircularProgressIndicator(); + } + }, + ); + } +} diff --git a/lib/routes/podcast/episode_comment_box.dart b/lib/routes/podcast/episode_comment_box.dart new file mode 100644 index 000000000..bf2a34ea5 --- /dev/null +++ b/lib/routes/podcast/episode_comment_box.dart @@ -0,0 +1,147 @@ +import 'package:breez/widgets/comment_user_image.dart'; +import 'package:flutter/material.dart'; + +// ignore: must_be_immutable +class CommentBox extends StatefulWidget { + final Widget child; + final Key formKey; + final Function() sendButtonMethod; + final TextEditingController commentController; + final String userImage; + String hintText; + final Widget sendWidget; + final Color backgroundColor; + final Color textColor; + final bool withBorder; + final Widget header; + final FocusNode focusNode; + CommentBox({ + @required this.child, + this.header, + @required this.sendButtonMethod, + this.formKey, + this.commentController, + this.sendWidget, + this.userImage, + this.focusNode, + this.withBorder = true, + this.backgroundColor, + this.textColor, + this.hintText, + }); + + @override + State createState() => _CommentBoxState(); +} + +class _CommentBoxState extends State { + int maxLines = 2; + Color sendWidgetColor = Colors.grey; + + @override + Widget build(BuildContext context) { + final themeData = Theme.of(context); + return Theme( + data: themeData, + child: Column( + children: [ + ListTile( + minLeadingWidth: 35, + tileColor: widget.backgroundColor, + leading: Container( + height: 35.0, + width: 35.0, + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(30))), + child: CommentUserImage(userImage: widget.userImage), + ), + title: Form( + key: widget.formKey, + child: Row( + children: [ + Expanded( + flex: 1, + child: Container( + color: themeData.colorScheme.background, + height: 53, + width: double.infinity, + padding: EdgeInsets.fromLTRB(0, 2, 0, 2), + alignment: Alignment.centerLeft, + child: TextFormField( + textAlignVertical: TextAlignVertical.center, + onChanged: (value) { + if (value == '') { + setState(() { + sendWidgetColor = Colors.grey; + }); + } else { + setState(() { + sendWidgetColor = Colors.white; + }); + } + }, + keyboardType: TextInputType.multiline, + maxLines: 2, + focusNode: widget.focusNode, + cursorColor: widget.textColor, + style: TextStyle(color: widget.textColor), + controller: widget.commentController, + decoration: InputDecoration( + contentPadding: EdgeInsets.only( + top: 15, bottom: 2, left: 10, right: 5), + isCollapsed: true, + hintText: widget.hintText, + floatingLabelBehavior: FloatingLabelBehavior.never, + enabledBorder: !widget.withBorder + ? InputBorder.none + : OutlineInputBorder( + borderSide: + BorderSide(color: widget.textColor), + ), + focusedBorder: !widget.withBorder + ? InputBorder.none + : OutlineInputBorder( + borderSide: + BorderSide(color: widget.textColor), + ), + border: !widget.withBorder + ? InputBorder.none + : OutlineInputBorder( + borderSide: + BorderSide(color: widget.textColor), + ), + focusColor: widget.textColor, + labelStyle: TextStyle(color: widget.textColor), + ), + ), + ), + ), + widget.focusNode.hasFocus + ? IconButton( + alignment: Alignment.centerRight, + icon: Icon( + Icons.send_sharp, + size: 25, + color: sendWidgetColor, + ), + onPressed: () { + if (widget.commentController.text != '') { + widget.sendButtonMethod(); + } + }, + ) + : SizedBox.shrink(), + ], + ), + ), + ), + Divider( + thickness: 1, + height: 0.5, + ), + Expanded(child: widget.child), + ], + ), + ); + } +} diff --git a/lib/routes/podcast/episode_comments.dart b/lib/routes/podcast/episode_comments.dart new file mode 100644 index 000000000..4345e4644 --- /dev/null +++ b/lib/routes/podcast/episode_comments.dart @@ -0,0 +1,117 @@ +import 'package:anytime/entities/episode.dart'; +import 'package:breez/bloc/nostr/nostr_comments/nostr_comments_bloc.dart'; +import 'package:breez/bloc/nostr/nostr_comments/nostr_comments_state_event.dart'; +import 'package:breez/routes/podcast/comment_render.dart'; +import 'package:breez/routes/podcast/episode_comment_box.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +class EpisodeComments extends StatefulWidget { + final Episode episode; + EpisodeComments({@required this.episode, Key key}) : super(key: key); + + @override + State createState() => _EpisodeCommentsState(); +} + +class _EpisodeCommentsState extends State { + final formKey = GlobalKey(); + final TextEditingController commentController = TextEditingController(); + String hintText = "Add a comment..."; + + final FocusNode _textFieldFocusNode = FocusNode(); + String userImage; + + NostrCommentBloc commentBloc; + + @override + void initState() { + super.initState(); + commentBloc = Provider.of(context, listen: false); + + _init(); + _setUserMetaDataListener(); + } + + void _setUserMetaDataListener() { + commentBloc.userMetaDataStream.listen((metadata) { + if (metadata != null) { + setState(() { + userImage = metadata.picture; + }); + } + }); + } + + Future _init() async { + commentBloc.commentActionController.add(GetUserPubKey()); + commentBloc.commentActionController.add(ReloadConnection()); + } + + @override + void dispose() { + super.dispose(); + _textFieldFocusNode.dispose(); + } + + void _createComment() async { + if (commentBloc.isRootEventPresent == false) { + commentBloc.commentActionController + .add(CreateRootComment(commentController.text.trim())); + } else { + commentBloc.commentActionController + .add(CreateReplyComment(commentController.text.trim())); + } + setState(() {}); + } + + @override + Widget build(BuildContext context) { + final themeData = Theme.of(context); + + return Theme( + data: themeData, + child: RefreshIndicator( + onRefresh: () async { + await _init(); + }, + child: GestureDetector( + onTap: () { + FocusScopeNode currentFocus = FocusScope.of(context); + + if (!currentFocus.hasPrimaryFocus) { + _textFieldFocusNode.unfocus(); + } + }, + child: CommentBox( + userImage: userImage, + hintText: hintText, + withBorder: _textFieldFocusNode.hasFocus ? true : false, + sendButtonMethod: () { + if (formKey.currentState.validate()) { + _createComment(); + commentController.clear(); + FocusScope.of(context).unfocus(); + } else { + formKey.currentState.setState(() {}); + } + }, + focusNode: _textFieldFocusNode, + formKey: formKey, + commentController: commentController, + textColor: themeData.textTheme.titleMedium.color, + sendWidget: _textFieldFocusNode.hasFocus + ? Icon( + Icons.send, + size: 20, + ) + : SizedBox.shrink(), + child: CommentRender( + commentBloc: commentBloc, + ), + ), + ), + ), + ); + } +} diff --git a/lib/routes/podcast/podcast_page.dart b/lib/routes/podcast/podcast_page.dart index 1eadb067c..0c5821fbb 100644 --- a/lib/routes/podcast/podcast_page.dart +++ b/lib/routes/podcast/podcast_page.dart @@ -1,7 +1,6 @@ import 'package:anytime/api/podcast/podcast_api.dart'; import 'package:anytime/bloc/discovery/discovery_bloc.dart'; import 'package:anytime/bloc/new_podcasts/new_podcasts_bloc.dart'; -import 'package:anytime/bloc/nostr_comments/nostr_comments_bloc.dart'; import 'package:anytime/bloc/podcast/audio_bloc.dart'; import 'package:anytime/bloc/podcast/episode_bloc.dart'; import 'package:anytime/bloc/podcast/opml_bloc.dart'; @@ -10,6 +9,7 @@ import 'package:anytime/bloc/podcast/queue_bloc.dart'; import 'package:anytime/bloc/search/search_bloc.dart'; import 'package:anytime/bloc/settings/settings_bloc.dart'; import 'package:anytime/bloc/ui/pager_bloc.dart'; +import 'package:anytime/entities/episode.dart'; import 'package:anytime/repository/repository.dart'; import 'package:anytime/services/audio/audio_player_service.dart'; import 'package:anytime/services/audio/default_audio_player_service.dart'; @@ -24,10 +24,13 @@ import 'package:anytime/ui/themes.dart'; import 'package:breez/bloc/account/account_bloc.dart'; import 'package:breez/bloc/account/account_model.dart'; import 'package:breez/bloc/blocs_provider.dart'; +import 'package:breez/bloc/nostr/nostr_bloc.dart'; +import 'package:breez/bloc/nostr/nostr_comments/nostr_comments_bloc.dart'; import 'package:breez/bloc/podcast_payments/model.dart'; import 'package:breez/bloc/user_profile/breez_user_model.dart'; import 'package:breez/bloc/user_profile/user_profile_bloc.dart'; import 'package:breez/routes/podcast/add_funds_message.dart'; +import 'package:breez/routes/podcast/episode_comments.dart'; import 'package:breez/routes/podcast/episode_metadata_loader.dart'; import 'package:breez/routes/podcast/payment_adjustment.dart'; import 'package:breez/routes/podcast/podcast_index_api.dart'; @@ -84,11 +87,11 @@ class AnytimePodcastApp extends StatefulWidget { class AnytimePodcastAppState extends State { ThemeData theme; + NostrBloc nostrBloc; @override void initState() { super.initState(); - widget.settingsBloc.settings.listen((event) { setState(() { var newTheme = event.theme == 'dark' @@ -111,6 +114,8 @@ class AnytimePodcastAppState extends State { @override Widget build(BuildContext context) { + nostrBloc = AppBlocsProvider.of(context); + return MultiProvider( providers: [ Provider( @@ -184,7 +189,9 @@ class AnytimePodcastAppState extends State { ), Provider( create: (_) => NostrCommentBloc( - episodeStream: widget.audioPlayerService.episodeEvent), + episodeStream: widget.audioPlayerService.episodeEvent, + nostrBloc: nostrBloc, + ), dispose: (_, value) => value.dispose(), ), ], @@ -263,6 +270,11 @@ class NowPlayingTransportState extends State { } } +WidgetBuilder nostrCommentsBuilder(Episode episode) { + builder(BuildContext context) => EpisodeComments(episode: episode); + return builder; +} + WidgetBuilder playerBuilder(int duration) { builder(BuildContext context) => NowPlayingTransport(duration: duration); return builder; diff --git a/lib/widgets/comment_user_image.dart b/lib/widgets/comment_user_image.dart new file mode 100644 index 000000000..32ecf4409 --- /dev/null +++ b/lib/widgets/comment_user_image.dart @@ -0,0 +1,51 @@ +import 'package:flutter/material.dart'; + +class CommentUserImage extends StatefulWidget { + final String userImage; + CommentUserImage({Key key, this.userImage}) : super(key: key); + + @override + State createState() => _CommentUserImageState(); +} + +class _CommentUserImageState extends State { + bool _loadImageError = false; + ImageProvider commentImageParser({String imageURLorPath}) { + //check if imageURLorPath + try { + if (imageURLorPath is String) { + if (imageURLorPath.startsWith('http')) { + return NetworkImage(imageURLorPath); + } else { + return AssetImage(imageURLorPath); + } + } else { + return imageURLorPath as ImageProvider; + } + } catch (e) { + setState(() { + _loadImageError = true; + }); + return null; + } + } + + @override + Widget build(BuildContext context) { + final themeData = Theme.of(context); + + return CircleAvatar( + backgroundImage: widget.userImage != null + ? commentImageParser( + imageURLorPath: widget.userImage, + ) + : null, + child: widget.userImage == null || _loadImageError + ? Icon( + Icons.person, + color: themeData.iconTheme.color, + ) + : null, + ); + } +} From 40ed1d789fe34c2e47fd606d0a6c66dbdf0fab2a Mon Sep 17 00:00:00 2001 From: Sarthak Gupta Date: Wed, 6 Sep 2023 22:30:33 +0530 Subject: [PATCH 9/9] toggling comments added --- lib/main.dart | 1 + lib/routes/podcast/podcast_page.dart | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 119f77191..390f0105c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -51,6 +51,7 @@ void main() async { child: AnytimePodcastApp( mobileService, repository, + blocs.marketplaceBloc, Provider( lazy: false, create: (ctx) => PodcastPaymentsBloc( diff --git a/lib/routes/podcast/podcast_page.dart b/lib/routes/podcast/podcast_page.dart index 0c5821fbb..c3340db92 100644 --- a/lib/routes/podcast/podcast_page.dart +++ b/lib/routes/podcast/podcast_page.dart @@ -24,6 +24,7 @@ import 'package:anytime/ui/themes.dart'; import 'package:breez/bloc/account/account_bloc.dart'; import 'package:breez/bloc/account/account_model.dart'; import 'package:breez/bloc/blocs_provider.dart'; +import 'package:breez/bloc/marketplace/marketplace_bloc.dart'; import 'package:breez/bloc/nostr/nostr_bloc.dart'; import 'package:breez/bloc/nostr/nostr_comments/nostr_comments_bloc.dart'; import 'package:breez/bloc/podcast_payments/model.dart'; @@ -62,8 +63,10 @@ class AnytimePodcastApp extends StatefulWidget { SettingsBloc settingsBloc; MobileSettingsService mobileSettingsService; OPMLService opmlService; + MarketplaceBloc marketplaceBloc; - AnytimePodcastApp(this.mobileSettingsService, this.repository, this.child) + AnytimePodcastApp(this.mobileSettingsService, this.repository, + this.marketplaceBloc, this.child) : podcastApi = PodcastIndexAPI() { downloadService = MobileDownloadService( repository: repository, downloadManager: AnytimeDownloadManager()); @@ -88,6 +91,7 @@ class AnytimePodcastApp extends StatefulWidget { class AnytimePodcastAppState extends State { ThemeData theme; NostrBloc nostrBloc; + static bool showComments = false; @override void initState() { @@ -110,6 +114,16 @@ class AnytimePodcastAppState extends State { } else { theme = Themes.lightTheme().themeData; } + + _listenToggle(); + } + + void _listenToggle() { + widget.marketplaceBloc.nostrSettingsStream.listen((settings) { + setState(() { + showComments = !settings.enableNostr; + }); + }); } @override @@ -271,7 +285,12 @@ class NowPlayingTransportState extends State { } WidgetBuilder nostrCommentsBuilder(Episode episode) { - builder(BuildContext context) => EpisodeComments(episode: episode); + builder(BuildContext context) { + return AnytimePodcastAppState.showComments == true + ? EpisodeComments(episode: episode) + : null; + } + return builder; }