26 Commits

Author SHA1 Message Date
182f34ff71 chore: bump version 2025-05-19 16:45:06 +01:00
57a67106fd refactor: rename var for people allowed to mute 2025-05-19 16:44:44 +01:00
b1a1e4131b refactor: replace spacer with spacer widget 2025-05-19 16:42:43 +01:00
9f91135572 fix: hide events from before start of stream 2025-05-19 16:41:26 +01:00
a5736aa3d3 feat: timeouts
closes #13
2025-05-19 16:32:21 +01:00
c865f24b2c fix: badge match event 2025-05-19 14:02:24 +01:00
f8f5860b64 chore: setup for deep linking 2025-05-19 12:48:23 +01:00
a500e0b3da feat: share stream
closes #33
2025-05-19 12:42:35 +01:00
86a8181aea feat: chat badges
closes #15
2025-05-19 11:44:13 +01:00
cb1c995023 fix: send chat to stream relays 2025-05-19 11:14:46 +01:00
46d60994a8 feat: badge awards 2025-05-19 11:11:12 +01:00
3eac1c4bfa feat: show copied to clipboard message on ios
closes #28
2025-05-19 10:47:57 +01:00
e6bad40608 fix: always show open in wallet button 2025-05-19 10:43:13 +01:00
e332dc9c6c fix: auto-raid loop
closes #31
2025-05-19 10:41:49 +01:00
a870aa0888 chore: bump version 2025-05-16 16:56:28 +01:00
8173eab05d fix: stop player when navigating away
closes #24
2025-05-16 16:55:44 +01:00
e91807e80e fix: url parser 2025-05-16 14:28:33 +01:00
c79ea1b872 feat: chat embeds
closes #18
2025-05-16 14:25:16 +01:00
b630b59e53 chore: placeholder fade off / write to cache always 2025-05-16 12:58:45 +01:00
c7435d5772 feat: following section on stream grid
closes #26
2025-05-16 12:46:53 +01:00
b5e0822d6c feat: live timer
closes #23
2025-05-16 12:33:34 +01:00
dcf42e7a78 refactor: use ProxyImg widget 2025-05-16 12:22:31 +01:00
244a0aad38 fix: trim content before converting to spans 2025-05-16 12:07:53 +01:00
556377263d fix: hide zap button for profiles with no lud16 2025-05-16 12:07:02 +01:00
7c3e9afc3e feat: profile editor
closes #5
2025-05-16 12:03:59 +01:00
d85c93b7ed feat: custom amount
chore: improve zap dialog ux
closes #25
2025-05-16 11:04:18 +01:00
40 changed files with 1663 additions and 496 deletions

View File

@ -24,6 +24,13 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="zap.stream" />
<data android:scheme="https" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->

View File

@ -1,7 +1,10 @@
import 'dart:convert';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:convert/convert.dart';
import 'package:crypto/crypto.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_svg/svg.dart';
import 'package:zap_stream_flutter/theme.dart';
class ImgProxySettings {
final String url;
@ -12,11 +15,12 @@ class ImgProxySettings {
static ImgProxySettings static() {
return ImgProxySettings(
url: "https://imgproxy.v0l.io",
key:
"a82fcf26aa0ccb55dfc6b4bd6a1c90744d3be0f38429f21a8828b43449ce7cebe6bdc2b09a827311bef37b18ce35cb1e6b1c60387a254541afa9e5b4264ae942",
salt:
"a897770d9abf163de055e9617891214e75a9016d748f8ef865e6ffbcb9ed932295659549773a22a019a5f06d0b440c320be411e3fddfe784e199e4f03d74bd9b");
url: "https://imgproxy.v0l.io",
key:
"a82fcf26aa0ccb55dfc6b4bd6a1c90744d3be0f38429f21a8828b43449ce7cebe6bdc2b09a827311bef37b18ce35cb1e6b1c60387a254541afa9e5b4264ae942",
salt:
"a897770d9abf163de055e9617891214e75a9016d748f8ef865e6ffbcb9ed932295659549773a22a019a5f06d0b440c320be411e3fddfe784e199e4f03d74bd9b",
);
}
}
@ -35,8 +39,14 @@ String signUrl(String u, ImgProxySettings settings) {
return urlSafe(base64.encode(result.bytes));
}
String proxyImg(BuildContext context, String url,
{ImgProxySettings? settings, int? resize, String? sha256, double? dpr}) {
String proxyImg(
BuildContext context,
String url, {
ImgProxySettings? settings,
int? resize,
String? sha256,
double? dpr,
}) {
final s = settings ?? ImgProxySettings.static();
if (url.startsWith("data:") || url.startsWith("blob:") || url.isEmpty) {
@ -63,4 +73,47 @@ String proxyImg(BuildContext context, String url,
final sig = signUrl(path, s);
return '${s.url}/$sig$path';
}
}
class ProxyImg extends StatelessWidget {
final String? url;
/// Size of the placeholder & error images
final double? placeholderSize;
/// request imgproxy to resize the image
final int? resize;
final double? width;
final double? height;
const ProxyImg({
super.key,
required this.url,
this.placeholderSize,
this.resize,
this.width,
this.height,
});
@override
Widget build(BuildContext context) {
return CachedNetworkImage(
imageUrl: proxyImg(context, url ?? "", resize: resize),
width: width,
height: height,
fit: BoxFit.cover,
placeholderFadeInDuration: Duration.zero,
fadeOutDuration: Duration.zero,
placeholder:
(ctx, url) =>
SvgPicture.asset("assets/svg/logo.svg", height: placeholderSize),
errorWidget:
(context, url, error) => SvgPicture.asset(
"assets/svg/logo.svg",
height: placeholderSize,
colorFilter: ColorFilter.mode(WARNING, BlendMode.srcATop),
),
);
}
}

View File

@ -12,13 +12,14 @@ import 'package:zap_stream_flutter/pages/login.dart';
import 'package:zap_stream_flutter/pages/login_input.dart';
import 'package:zap_stream_flutter/pages/new_account.dart';
import 'package:zap_stream_flutter/pages/profile.dart';
import 'package:zap_stream_flutter/pages/settings_profile.dart';
import 'package:zap_stream_flutter/pages/stream.dart';
import 'package:zap_stream_flutter/theme.dart';
import 'package:zap_stream_flutter/utils.dart';
import 'package:zap_stream_flutter/widgets/header.dart';
import 'login.dart';
import 'pages/home.dart';
import 'pages/layout.dart';
class NoVerify extends EventVerifier {
@override
@ -49,6 +50,8 @@ const defaultRelays = [
const searchRelays = ["wss://relay.nostr.band", "wss://search.nos.today"];
final loginData = LoginData();
final RouteObserver<ModalRoute<void>> routeObserver =
RouteObserver<ModalRoute<void>>();
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
@ -92,81 +95,95 @@ Future<void> main() async {
),
routerConfig: GoRouter(
routes: [
StatefulShellRoute.indexedStack(
ShellRoute(
observers: [routeObserver],
builder:
(context, state, navigationShell) =>
SafeArea(child: LayoutScreen(navigationShell)),
branches: [
StatefulShellBranch(
routes: [
GoRoute(path: "/", builder: (ctx, state) => HomePage()),
ShellRoute(
builder: (context, state, child) {
return Container(
margin: EdgeInsets.only(top: 50),
padding: EdgeInsets.symmetric(horizontal: 5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 20,
children: [
Center(
child: Image.asset(
"assets/logo.png",
height: 150,
),
),
child,
],
(context, state, child) => SafeArea(
child: Scaffold(body: child, backgroundColor: Colors.black),
),
routes: [
GoRoute(path: "/", builder: (ctx, state) => HomePage()),
ShellRoute(
observers: [routeObserver],
builder: (context, state, child) {
return Container(
margin: EdgeInsets.only(top: 50),
padding: EdgeInsets.symmetric(horizontal: 5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 20,
children: [
Center(
child: Image.asset("assets/logo.png", height: 150),
),
);
},
child,
],
),
);
},
routes: [
GoRoute(
path: "/login",
builder: (ctx, state) => LoginPage(),
routes: [
GoRoute(
path: "/login",
builder: (ctx, state) => LoginPage(),
routes: [
GoRoute(
path: "key",
builder: (ctx, state) => LoginInputPage(),
),
GoRoute(
path: "new",
builder: (context, state) => NewAccountPage(),
),
],
path: "key",
builder: (ctx, state) => LoginInputPage(),
),
GoRoute(
path: "new",
builder: (context, state) => NewAccountPage(),
),
],
),
],
),
GoRoute(
path: StreamPage.path,
builder: (ctx, state) {
if (state.extra is StreamEvent) {
return StreamPage(stream: state.extra as StreamEvent);
} else {
throw UnimplementedError();
}
},
),
GoRoute(
path: "/p/:id",
builder: (ctx, state) {
return ProfilePage(pubkey: state.pathParameters["id"]!);
},
),
GoRoute(
path: "/t/:id",
builder: (context, state) {
return HashtagPage(tag: state.pathParameters["id"]!);
},
),
GoRoute(
path: "/category/:id",
builder: (context, state) {
return CategoryPage(
category: state.pathParameters["id"]!,
info: state.extra as GameInfo?,
);
},
),
ShellRoute(
observers: [routeObserver],
builder:
(context, state, child) =>
Column(children: [HeaderWidget(), child]),
routes: [
GoRoute(
path: "/e/:id",
builder: (ctx, state) {
if (state.extra is StreamEvent) {
return StreamPage(stream: state.extra as StreamEvent);
} else {
throw UnimplementedError();
}
},
),
GoRoute(
path: "/p/:id",
builder: (ctx, state) {
return ProfilePage(pubkey: state.pathParameters["id"]!);
},
),
GoRoute(
path: "/t/:id",
builder: (context, state) {
return HashtagPage(tag: state.pathParameters["id"]!);
},
),
GoRoute(
path: "/category/:id",
builder: (context, state) {
return CategoryPage(
category: state.pathParameters["id"]!,
info: state.extra as GameInfo?,
);
},
path: "/settings",
builder: (context, state) => SizedBox(),
routes: [
GoRoute(
path: "profile",
builder: (context, state) => SettingsProfilePage(),
),
],
),
],
),

View File

@ -44,10 +44,7 @@ class CategoryPage extends StatelessWidget {
info!.coverImage!,
fit: BoxFit.contain,
)
: CachedNetworkImage(
imageUrl: proxyImg(context, info!.coverImage!),
fit: BoxFit.cover,
),
: ProxyImg(url: info!.coverImage!),
),
Expanded(
child: Column(

View File

@ -27,7 +27,7 @@ class HashtagPage extends StatelessWidget {
RxFilter<Nip01Event>(
Key("tags-page:$tag"),
filters: [
Filter(kinds: [30_311], limit: 50, tTags: [tag.toLowerCase()]),
Filter(kinds: [30_311], limit: 100, tTags: [tag.toLowerCase()]),
],
builder: (ctx, state) {
if (state == null) {

View File

@ -19,7 +19,7 @@ class HomePage extends StatelessWidget {
RxFilter<Nip01Event>(
Key("home-page"),
filters: [
Filter(kinds: [30_311], limit: 50),
Filter(kinds: [30_311], limit: 100),
],
builder: (ctx, state) {
if (state == null) {

View File

@ -1,16 +0,0 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
class LayoutScreen extends StatelessWidget {
final StatefulNavigationShell navigationShell;
const LayoutScreen(this.navigationShell, {super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: navigationShell,
backgroundColor: Colors.black,
);
}
}

View File

@ -1,13 +1,12 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:image_picker/image_picker.dart';
import 'package:ndk/ndk.dart';
import 'package:ndk/shared/nips/nip01/bip340.dart';
import 'package:ndk/shared/nips/nip01/key_pair.dart';
import 'package:zap_stream_flutter/login.dart';
import 'package:zap_stream_flutter/main.dart';
import 'package:zap_stream_flutter/theme.dart';
import 'package:zap_stream_flutter/widgets/avatar_upload.dart';
import 'package:zap_stream_flutter/widgets/button.dart';
class NewAccountPage extends StatefulWidget {
@ -19,28 +18,12 @@ class NewAccountPage extends StatefulWidget {
class _NewAccountPage extends State<NewAccountPage> {
final TextEditingController _name = TextEditingController();
final FocusNode _nameFocus = FocusNode();
String? _avatar;
String? _error;
bool _loading = false;
final KeyPair _privateKey = Bip340.generatePrivateKey();
Future<void> _uploadAvatar() async {
ndk.accounts.loginPrivateKey(
pubkey: _privateKey.publicKey,
privkey: _privateKey.privateKey!,
);
final file = await ImagePicker().pickImage(source: ImageSource.gallery);
if (file != null) {
final upload = await ndk.blossom.uploadBlob(
serverUrls: ["https://nostr.download"],
data: await file.readAsBytes(),
);
setState(() {
_avatar = upload.first.descriptor!.url;
});
}
}
Future<void> _login() async {
if (ndk.accounts.isNotLoggedIn) {
ndk.accounts.loginPrivateKey(
@ -63,55 +46,58 @@ class _NewAccountPage extends State<NewAccountPage> {
return Column(
spacing: 20,
children: [
GestureDetector(
onTap: () {
_uploadAvatar().catchError((e) {
setState(() {
if (e is String) {
_error = e;
}
});
AvatarUpload(
onUploadStart: () async {
if (ndk.accounts.isNotLoggedIn) {
ndk.accounts.loginPrivateKey(
pubkey: _privateKey.publicKey,
privkey: _privateKey.privateKey!,
);
}
},
onUpload: (i) {
setState(() {
_avatar = i;
});
},
child: Container(
width: 200,
height: 200,
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(200)),
color: Color.fromARGB(100, 50, 50, 50),
),
child:
_avatar == null
? Center(child: Text("Upload Avatar"))
: CachedNetworkImage(imageUrl: _avatar!),
),
),
TextField(
controller: _name,
readOnly: _loading,
focusNode: _nameFocus,
decoration: InputDecoration(labelText: "Username"),
),
BasicButton.text(
"Login",
onTap: () {
_login()
.then((_) {
loginData.value = LoginAccount.privateKeyHex(
_privateKey.privateKey!,
);
if (context.mounted) {
context.go("/");
}
})
.catchError((e) {
setState(() {
if (e is String) {
_error = e;
}
});
ValueListenableBuilder(
valueListenable: _name,
builder: (context, value, child) {
return BasicButton.text(
"Login",
disabled: _loading || value.text.isEmpty,
onTap: () {
setState(() {
_loading = true;
_nameFocus.unfocus();
});
_login()
.then((_) {
loginData.value = LoginAccount.privateKeyHex(
_privateKey.privateKey!,
);
if (context.mounted) {
context.go("/");
}
})
.catchError((e) {
setState(() {
_loading = false;
_error = e is String ? e : e.toString();
});
});
},
);
},
),
if (_loading) CircularProgressIndicator(),
if (_error != null)
Text(
_error!,

View File

@ -1,4 +1,3 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:ndk/ndk.dart';
@ -9,6 +8,7 @@ import 'package:zap_stream_flutter/theme.dart';
import 'package:zap_stream_flutter/utils.dart';
import 'package:zap_stream_flutter/widgets/avatar.dart';
import 'package:zap_stream_flutter/widgets/button.dart';
import 'package:zap_stream_flutter/widgets/button_follow.dart';
import 'package:zap_stream_flutter/widgets/header.dart';
import 'package:zap_stream_flutter/widgets/nostr_text.dart';
import 'package:zap_stream_flutter/widgets/profile.dart';
@ -22,6 +22,8 @@ class ProfilePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final hexPubkey = bech32ToHex(pubkey);
final isMe = ndk.accounts.getPublicKey() == hexPubkey;
return ProfileLoaderWidget(hexPubkey, (ctx, state) {
final profile = state.data ?? Metadata(pubKey: hexPubkey);
return SingleChildScrollView(
@ -34,10 +36,7 @@ class ProfilePage extends StatelessWidget {
SizedBox(
height: 140,
width: double.maxFinite,
child: CachedNetworkImage(
imageUrl: proxyImg(context, profile.banner!),
fit: BoxFit.cover,
),
child: ProxyImg(url: profile.banner!),
),
Row(
spacing: 8,
@ -70,18 +69,27 @@ class ProfilePage extends StatelessWidget {
],
),
if (ndk.accounts.getPublicKey() == hexPubkey)
if (isMe)
Row(
spacing: 8,
children: [
BasicButton.text(
"Logout",
onTap: () {
loginData.logout();
ndk.accounts.logout();
context.go("/");
},
),
BasicButton.text(
"Edit Profile",
onTap: () {
context.push("/settings/profile");
},
),
],
),
if (!isMe) FollowButton(pubkey: hexPubkey),
Text(
"Past Streams",
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600),
@ -89,10 +97,9 @@ class ProfilePage extends StatelessWidget {
RxFilter<Nip01Event>(
Key("profile-streams:$hexPubkey"),
relays: defaultRelays,
filters: [
Filter(kinds: [30_311], limit: 200, pTags: [hexPubkey]),
Filter(kinds: [30_311], limit: 200, authors: [hexPubkey]),
Filter(kinds: [30_311], limit: 100, pTags: [hexPubkey]),
Filter(kinds: [30_311], limit: 100, authors: [hexPubkey]),
],
builder: (ctx, state) {
return StreamGrid(

View File

@ -0,0 +1,117 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:ndk/ndk.dart';
import 'package:zap_stream_flutter/main.dart';
import 'package:zap_stream_flutter/theme.dart';
import 'package:zap_stream_flutter/widgets/avatar_upload.dart';
import 'package:zap_stream_flutter/widgets/button.dart';
class SettingsProfilePage extends StatelessWidget {
final TextEditingController _picture = TextEditingController();
final TextEditingController _name = TextEditingController();
final TextEditingController _about = TextEditingController();
final TextEditingController _nip5 = TextEditingController();
final TextEditingController _lud16 = TextEditingController();
final ValueNotifier<bool> _loading = ValueNotifier(false);
SettingsProfilePage({super.key});
@override
Widget build(BuildContext context) {
final pubkey = ndk.accounts.getPublicKey();
if (pubkey == null) return Text("Cant edit profile when logged out");
return FutureBuilder(
future: ndk.metadata.loadMetadata(pubkey),
builder: (context, state) {
if (state.hasData) {
_name.text = state.data!.name ?? "";
_about.text = state.data!.about ?? "";
_nip5.text = state.data!.nip05 ?? "";
_lud16.text = state.data!.lud16 ?? "";
_picture.text = state.data!.picture ?? "";
}
return ValueListenableBuilder(
valueListenable: _loading,
builder: (context, v, _) {
return Column(
spacing: 16,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: AvatarUpload(
key: Key("avatar:${_picture.text}"),
avatar: _picture.text.isEmpty ? null : _picture.text,
onUpload: (i) {
_picture.text = i;
},
),
),
TextField(
controller: _name,
readOnly: v,
decoration: InputDecoration(
labelText: "Display Name",
fillColor: LAYER_1,
filled: true,
),
),
TextField(
controller: _about,
readOnly: v,
decoration: InputDecoration(
labelText: "About",
fillColor: LAYER_1,
filled: true,
),
),
TextField(
controller: _nip5,
readOnly: v,
decoration: InputDecoration(
labelText: "Nostr Address",
fillColor: LAYER_1,
filled: true,
),
),
TextField(
controller: _lud16,
readOnly: v,
decoration: InputDecoration(
labelText: "Lightning Address",
fillColor: LAYER_1,
filled: true,
),
),
BasicButton.text(
"Save",
disabled: v,
onTap: () async {
_loading.value = true;
try {
final newMeta = Metadata(
pubKey: pubkey,
name: _name.text.isEmpty ? null : _name.text,
about: _about.text.isEmpty ? null : _about.text,
picture: _picture.text.isEmpty ? null : _picture.text,
nip05: _nip5.text.isEmpty ? null : _nip5.text,
lud16: _lud16.text.isEmpty ? null : _lud16.text,
);
await ndk.metadata.broadcastMetadata(newMeta);
if (context.mounted) {
context.pop();
}
} finally {
_loading.value = false;
}
},
),
if (v) Center(child: CircularProgressIndicator()),
],
);
},
);
},
);
}
}

View File

@ -1,8 +1,8 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:chewie/chewie.dart';
import 'dart:developer' as developer;
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:ndk/ndk.dart';
import 'package:video_player/video_player.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
import 'package:zap_stream_flutter/imgproxy.dart';
import 'package:zap_stream_flutter/main.dart';
@ -14,9 +14,11 @@ import 'package:zap_stream_flutter/widgets/chat.dart';
import 'package:zap_stream_flutter/widgets/pill.dart';
import 'package:zap_stream_flutter/widgets/profile.dart';
import 'package:zap_stream_flutter/widgets/stream_info.dart';
import 'package:zap_stream_flutter/widgets/video_player.dart';
import 'package:zap_stream_flutter/widgets/zap.dart';
class StreamPage extends StatefulWidget {
static const String path = "/e/:id";
final StreamEvent stream;
const StreamPage({super.key, required this.stream});
@ -25,51 +27,62 @@ class StreamPage extends StatefulWidget {
State<StatefulWidget> createState() => _StreamPage();
}
class _StreamPage extends State<StreamPage> {
VideoPlayerController? _controller;
ChewieController? _chewieController;
class _StreamPage extends State<StreamPage> with RouteAware {
bool _offScreen = false;
bool isWidgetVisible(BuildContext context) {
final router = GoRouter.of(context);
final currentConfiguration = router.routerDelegate.currentConfiguration;
final match = currentConfiguration.matches.lastOrNull;
final lastMatch =
match is ShellRouteMatch ? match.matches.lastOrNull : match;
return lastMatch != null &&
(lastMatch.route is GoRoute &&
(lastMatch.route as GoRoute).path == StreamPage.path);
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
routeObserver.subscribe(this, ModalRoute.of(context)!);
}
@override
void initState() {
super.initState();
WakelockPlus.enable();
final url = widget.stream.info.stream;
if (url != null) {
if (_controller != null) {
_controller!.dispose();
}
_controller = VideoPlayerController.networkUrl(
Uri.parse(url),
httpHeaders: Map.from({"user-agent": userAgent}),
);
() async {
await _controller!.initialize();
setState(() {
_chewieController = ChewieController(
videoPlayerController: _controller!,
aspectRatio: 16 / 9,
autoPlay: true,
placeholder:
(widget.stream.info.image?.isNotEmpty ?? false)
? CachedNetworkImage(
imageUrl: proxyImg(context, widget.stream.info.image!),
)
: null,
);
});
}();
}
super.initState();
}
@override
void dispose() {
super.dispose();
WakelockPlus.disable();
if (_controller != null) {
_controller!.dispose();
_controller = null;
routeObserver.unsubscribe(this);
super.dispose();
}
@override
void didPush() {
setState(() {
developer.log("STREAM: ON SCREEN");
_offScreen = false;
});
}
@override
void didPopNext() {
setState(() {
developer.log("STREAM: ON SCREEN");
_offScreen = false;
});
}
@override
void didPushNext() {
if (!isWidgetVisible(context)) {
setState(() {
developer.log("STREAM: OFF SCREEN");
_offScreen = true;
});
}
}
@ -100,82 +113,73 @@ class _StreamPage extends State<StreamPage> {
AspectRatio(
aspectRatio: 16 / 9,
child:
_chewieController != null
? Chewie(
key: Key("stream:player:${stream.aTag}"),
controller: _chewieController!,
(stream.info.stream != null && !_offScreen)
? VideoPlayerWidget(
url: stream.info.stream!,
placeholder: stream.info.image,
aspectRatio: 16 / 9,
)
: Container(
color: LAYER_1,
child:
(stream.info.image?.isNotEmpty ?? false)
? CachedNetworkImage(
imageUrl: proxyImg(context, stream.info.image!),
)
: null,
),
: (stream.info.image?.isNotEmpty ?? false)
? ProxyImg(url: stream.info.image)
: Container(decoration: BoxDecoration(color: LAYER_1)),
),
Text(
stream.info.title ?? "",
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 18),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
if (stream.info.title?.isNotEmpty ?? false)
Text(
stream.info.title!,
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 18),
),
ProfileWidget.pubkey(
stream.info.host,
children: [
ProfileWidget.pubkey(stream.info.host),
Row(
spacing: 8,
children: [
BasicButton(
Row(children: [Icon(Icons.bolt, size: 14), Text("Zap")]),
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 2),
decoration: BoxDecoration(
color: PRIMARY_1,
borderRadius: DEFAULT_BR,
),
onTap: () {
showModalBottomSheet(
context: context,
constraints: BoxConstraints.expand(),
builder: (ctx) {
return ZapWidget(
pubkey: stream.info.host,
target: stream.event,
zapTags:
// tag goal onto zap request
stream.info.goal != null
? [
["e", stream.info.goal!],
]
: null,
);
},
);
},
),
if (stream.info.participants != null)
PillWidget(
color: LAYER_1,
child: Text(
"${stream.info.participants} viewers",
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
Spacer(),
BasicButton(
Row(children: [Icon(Icons.bolt, size: 14), Text("Zap")]),
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 2),
decoration: BoxDecoration(
color: PRIMARY_1,
borderRadius: DEFAULT_BR,
),
onTap: () {
showModalBottomSheet(
context: context,
constraints: BoxConstraints.expand(),
builder: (ctx) {
return SingleChildScrollView(
primary: false,
child: ZapWidget(
pubkey: stream.info.host,
target: stream.event,
zapTags:
// tag goal onto zap request
stream.info.goal != null
? [
["e", stream.info.goal!],
]
: null,
),
),
),
GestureDetector(
onTap: () {
showModalBottomSheet(
context: context,
constraints: BoxConstraints.expand(),
isScrollControlled: true,
builder: (context) => StreamInfoWidget(stream: stream),
);
},
child: Icon(Icons.info),
);
},
),
if (stream.info.participants != null)
PillWidget(
color: LAYER_1,
child: Text(
"${stream.info.participants} viewers",
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w500),
),
],
),
GestureDetector(
onTap: () {
showModalBottomSheet(
context: context,
constraints: BoxConstraints.expand(),
isScrollControlled: true,
builder: (context) => StreamInfoWidget(stream: stream),
);
},
child: Icon(Icons.info),
),
],
),

View File

@ -40,6 +40,7 @@ class _RxFilter<T> extends State<RxFilter<T>> {
_response = ndk.requests.subscription(
filters: widget.filters,
explicitRelays: widget.relays,
cacheWrite: true
);
if (!widget.leaveOpen) {
_response.future.then((_) {

View File

@ -6,6 +6,7 @@ import 'package:convert/convert.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:ndk/ndk.dart';
import 'package:ndk/shared/nips/nip19/hrps.dart';
import 'package:ndk/shared/nips/nip19/nip19.dart';
/// Container class over event and stream info
@ -374,6 +375,14 @@ Map<String, TopZaps> topZapReceiver(Iterable<ZapReceipt> zaps) {
);
}
String formatSecondsToHHMMSS(int seconds) {
int hours = seconds ~/ 3600;
int minutes = (seconds % 3600) ~/ 60;
int remainingSeconds = seconds % 60;
return '${hours.toString().padLeft(2, '0')}:${minutes.toString().padLeft(2, '0')}:${remainingSeconds.toString().padLeft(2, '0')}';
}
String bech32ToHex(String bech32) {
final decoder = Bech32Decoder();
final data = decoder.convert(bech32, 10_000);
@ -386,6 +395,95 @@ String bech32ToHex(String bech32) {
}
}
// https://github.com/nostr-protocol/nips/blob/master/19.md
class TLVTypes {
static const int kSpecial = 0;
static const int kRelay = 1;
static const int kAuthor = 2;
static const int kKind = 3;
}
class TLVEntity {
final String hrp;
final List<TLV> data;
const TLVEntity(this.hrp, this.data);
TLV? get special {
return data.firstWhereOrNull((e) => e.type == TLVTypes.kSpecial);
}
/// return the special entry as hex
String? get specialHex {
final r = special;
return r != null ? hex.encode(r.value) : null;
}
/// return the special entry as utf8 string
String? get specialUtf8 {
final r = special;
return r != null ? utf8.decode(r.value) : null;
}
int? get kind {
final k = data.firstWhereOrNull((e) => e.type == TLVTypes.kKind);
return k != null
? k.value[0] << 24 | k.value[1] << 16 | k.value[2] << 8 | k.value[3]
: null;
}
String? get author {
final a = data.firstWhereOrNull((e) => e.type == TLVTypes.kAuthor);
return a != null ? hex.encode(a.value) : null;
}
List<String>? get relays {
final r = data.where((r) => r.type == TLVTypes.kRelay);
if (r.isNotEmpty) {
return r.map((e) => utf8.decode(e.value)).toList();
}
return null;
}
Filter toFilter() {
var ret = <String, dynamic>{};
if (hrp == Hrps.kNaddr) {
final dTag = specialUtf8;
final kindValue = kind;
final authorValue = author;
if (dTag == null || kindValue == null || authorValue == null) {
throw "Invalid naddr entity, special, kind and author must be set";
}
ret["#d"] = [dTag];
ret["authors"] = [authorValue];
ret["kinds"] = [kindValue];
} else if (hrp == Hrps.kNevent) {
final idValue = specialHex;
if (idValue == null) {
throw "Invalid nevent, special entry is invalid or missing";
}
ret["ids"] = [idValue];
final kindValue = kind;
if (kindValue != null) {
ret["kinds"] = [kindValue];
}
final authorValue = author;
if (authorValue != null) {
ret["authors"] = [authorValue];
}
} else if (hrp == Hrps.kNoteId) {
final idValue = specialHex;
if (idValue == null) {
throw "Invalid nevent, special entry is invalid or missing";
}
ret["ids"] = [idValue];
} else {
throw "Cant convert $hrp to a filter";
}
return Filter.fromMap(ret);
}
}
class TLV {
final int type;
final int length;
@ -470,3 +568,20 @@ String encodeBech32TLV(String hrp, List<TLV> tlvs) {
throw FormatException('Failed to encode Bech32 or TLV: $e');
}
}
TLVEntity decodeBech32ToTLVEntity(String input) {
final decoder = Bech32Decoder();
final data = decoder.convert(input, 10_000);
final data8bit = Nip19.convertBits(data.data, 5, 8, false);
if (data.hrp != "npub" || data.hrp != "nsec" || data.hrp != "note") {
return TLVEntity(data.hrp, parseTLV(data8bit));
} else {
// convert to basic type using special entry only
return TLVEntity(data.hrp, [TLV(0, data8bit.length, data8bit)]);
}
}
Filter aTagToFilter(String tag) {
final ts = tag.split(":");
return Filter(kinds: [int.parse(ts[0])], authors: [ts[1]], dTags: [ts[2]]);
}

View File

@ -23,17 +23,13 @@ class AvatarWidget extends StatelessWidget {
Widget build(BuildContext context) {
final thisSize = size ?? 40;
return ClipOval(
child: CachedNetworkImage(
fit: BoxFit.cover,
imageUrl: proxyImg(
context,
profile.picture ??
"https://nostr.api.v0l.io/api/v1/avatar/cyberpunks/${profile.pubKey}",
resize: thisSize.ceil(),
),
height: thisSize,
child: ProxyImg(
url:
profile.picture ??
"https://nostr.api.v0l.io/api/v1/avatar/cyberpunks/${profile.pubKey}",
resize: thisSize.ceil(),
width: thisSize,
errorWidget: (context, url, error) => Icon(Icons.error),
height: thisSize,
),
);
}

View File

@ -0,0 +1,106 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:zap_stream_flutter/main.dart';
import 'package:zap_stream_flutter/theme.dart';
class AvatarUpload extends StatefulWidget {
final String? avatar;
final Future<void> Function()? onUploadStart;
final void Function(String)? onUpload;
const AvatarUpload({
super.key,
this.onUpload,
this.onUploadStart,
this.avatar,
});
@override
State<StatefulWidget> createState() => _AvatarUpload();
}
class _AvatarUpload extends State<AvatarUpload> {
String? _avatar;
String? _error;
bool _loading = false;
@override
void initState() {
_avatar = widget.avatar;
super.initState();
}
Future<String?> _uploadAvatar() async {
if (widget.onUploadStart != null) {
await widget.onUploadStart!();
}
final file = await ImagePicker().pickImage(source: ImageSource.gallery);
if (file != null) {
final upload = await ndk.blossom.uploadBlob(
serverUrls: ["https://nostr.download"],
data: await file.readAsBytes(),
);
final imgUrl = upload.first.descriptor!.url;
setState(() {
_avatar = imgUrl;
});
return imgUrl;
}
return null;
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
setState(() {
_loading = true;
});
_uploadAvatar()
.then((u) {
setState(() {
_loading = false;
});
if (widget.onUpload != null && u != null) {
widget.onUpload!(u);
}
})
.catchError((e) {
setState(() {
_error = e is String ? e : e.toString();
_loading = false;
});
});
},
child: Column(
spacing: 8,
children: [
Container(
width: 200,
height: 200,
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(200)),
color: Color.fromARGB(100, 50, 50, 50),
),
child:
_avatar == null
? Center(
child:
_loading
? CircularProgressIndicator()
: Text("Upload Avatar"),
)
: CachedNetworkImage(imageUrl: _avatar!),
),
if (_error != null)
Text(
_error!,
style: TextStyle(color: WARNING, fontWeight: FontWeight.bold),
),
],
),
);
}
}

View File

@ -7,6 +7,7 @@ class BasicButton extends StatelessWidget {
final EdgeInsetsGeometry? padding;
final EdgeInsetsGeometry? margin;
final void Function()? onTap;
final bool? disabled;
const BasicButton(
this.child, {
@ -15,25 +16,36 @@ class BasicButton extends StatelessWidget {
this.padding,
this.margin,
this.onTap,
this.disabled,
});
static text(
static Widget text(
String text, {
BoxDecoration? decoration,
EdgeInsetsGeometry? padding,
EdgeInsetsGeometry? margin,
void Function()? onTap,
double? fontSize,
bool? disabled,
Icon? icon,
}) {
return BasicButton(
Text(
text,
style: TextStyle(
color: Color.fromARGB(255, 255, 255, 255),
fontSize: fontSize,
fontWeight: FontWeight.bold,
Text.rich(
TextSpan(
style: TextStyle(
color: Color.fromARGB(255, 255, 255, 255),
fontSize: fontSize,
fontWeight: FontWeight.bold,
),
children: [
if (icon != null)
WidgetSpan(child: icon, alignment: PlaceholderAlignment.middle),
if (icon != null) TextSpan(text: " "),
TextSpan(text: text),
],
),
),
disabled: disabled,
decoration: decoration,
padding: padding ?? EdgeInsets.symmetric(vertical: 4, horizontal: 12),
margin: margin,
@ -44,16 +56,20 @@ class BasicButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
final defaultBr = BorderRadius.all(Radius.circular(100));
final inner = Container(
padding: padding,
margin: margin,
decoration:
decoration ?? BoxDecoration(color: LAYER_2, borderRadius: defaultBr),
child: Center(child: child),
);
return GestureDetector(
onTap: onTap,
child: Container(
padding: padding,
margin: margin,
decoration:
decoration ??
BoxDecoration(color: LAYER_2, borderRadius: defaultBr),
child: Center(child: child),
),
onTap: () {
if (!(disabled ?? false) && onTap != null) {
onTap!();
}
},
child: (disabled ?? false) ? Opacity(opacity: 0.5, child: inner) : inner,
);
}
}

View File

@ -8,8 +8,9 @@ class FollowButton extends StatelessWidget {
final void Function()? onTap;
final void Function()? onFollow;
final void Function()? onUnfollow;
final ValueNotifier<bool> _loading = ValueNotifier(false);
const FollowButton({
FollowButton({
super.key,
required this.pubkey,
this.onTap,
@ -24,43 +25,63 @@ class FollowButton extends StatelessWidget {
return SizedBox.shrink();
}
return FutureBuilder(
future: ndk.follows.getContactList(signer.getPublicKey()),
builder: (context, state) {
final follows = state.data?.contacts ?? [];
final isFollowing = follows.contains(pubkey);
return BasicButton(
Row(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 4,
children: [
Icon(isFollowing ? Icons.person_remove : Icons.person_add, size: 16),
Text(
isFollowing ? "Unfollow" : "Follow",
style: TextStyle(fontWeight: FontWeight.bold),
return ValueListenableBuilder(
valueListenable: _loading,
builder: (context, loading, _) {
return FutureBuilder(
future: ndk.follows.getContactList(signer.getPublicKey()),
builder: (context, state) {
final follows = state.data?.contacts ?? [];
final isFollowing = follows.contains(pubkey);
return BasicButton(
Row(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 8,
children: [
loading
? SizedBox(
height: 16,
width: 16,
child: CircularProgressIndicator(),
)
: Icon(
isFollowing ? Icons.person_remove : Icons.person_add,
size: 16,
),
Text(
isFollowing ? "Unfollow" : "Follow",
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
],
),
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 12),
decoration: BoxDecoration(
borderRadius: DEFAULT_BR,
color: LAYER_2,
),
onTap: () async {
if (onTap != null) {
onTap!();
}
if (isFollowing) {
await ndk.follows.broadcastRemoveContact(pubkey);
if (onUnfollow != null) {
onUnfollow!();
}
} else {
await ndk.follows.broadcastAddContact(pubkey);
if (onFollow != null) {
onFollow!();
}
}
disabled: loading,
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 12),
decoration: BoxDecoration(
borderRadius: DEFAULT_BR,
color: LAYER_2,
),
onTap: () async {
_loading.value = true;
try {
if (onTap != null) {
onTap!();
}
if (isFollowing) {
await ndk.follows.broadcastRemoveContact(pubkey);
if (onUnfollow != null) {
onUnfollow!();
}
} else {
await ndk.follows.broadcastAddContact(pubkey);
if (onFollow != null) {
onFollow!();
}
}
} finally {
_loading.value = false;
}
},
);
},
);
},

View File

@ -5,8 +5,10 @@ import 'package:zap_stream_flutter/main.dart';
import 'package:zap_stream_flutter/rx_filter.dart';
import 'package:zap_stream_flutter/theme.dart';
import 'package:zap_stream_flutter/utils.dart';
import 'package:zap_stream_flutter/widgets/chat_badge.dart';
import 'package:zap_stream_flutter/widgets/chat_message.dart';
import 'package:zap_stream_flutter/widgets/chat_raid.dart';
import 'package:zap_stream_flutter/widgets/chat_timeout.dart';
import 'package:zap_stream_flutter/widgets/chat_write.dart';
import 'package:zap_stream_flutter/widgets/chat_zap.dart';
import 'package:zap_stream_flutter/widgets/goal.dart';
@ -18,41 +20,66 @@ class ChatWidget extends StatelessWidget {
const ChatWidget({super.key, required this.stream});
@override
Widget build(BuildContext context) {
var muteLists = [stream.info.host];
if (ndk.accounts.getPublicKey() != null) {
muteLists.add(ndk.accounts.getPublicKey()!);
var moderators = [stream.info.host];
final myKey = ndk.accounts.getPublicKey();
if (myKey != null) {
moderators.add(myKey);
}
var filters = [
Filter(kinds: [1311, 9735], limit: 200, aTags: [stream.aTag]),
Filter(kinds: [1312], limit: 200, aTags: [stream.aTag]),
Filter(kinds: [Nip51List.kMute], authors: muteLists),
Filter(kinds: [1312, 1313], limit: 200, aTags: [stream.aTag]),
Filter(kinds: [Nip51List.kMute], authors: moderators),
Filter(kinds: [1314], authors: moderators),
Filter(kinds: [8], authors: [stream.info.host]),
];
return RxFilter<Nip01Event>(
Key("stream:chat:${stream.aTag}"),
relays: stream.info.relays,
filters: filters,
builder: (ctx, state) {
final mutedPubkeys =
final now = DateTime.now().millisecondsSinceEpoch / 1000;
final firstPassEvents =
(state ?? [])
.where((e) => e.kind == Nip51List.kMute)
.where(
(e) => switch (e.kind) {
1314 =>
moderators.contains(e.pubKey) &&
double.parse(e.getFirstTag("expiration")!) >
now, // filter timeouts to only people allowed to mute
// TODO: check other kinds are valid for this stream
_ => true,
},
)
.toList();
final mutedPubkeys =
firstPassEvents
.where(
(e) =>
e.kind == Nip51List.kMute ||
(e.kind == 1314 &&
e.createdAt < now &&
double.parse(e.getFirstTag("expiration")!) > now),
)
.map((e) => e.tags)
.expand((e) => e)
.where(
(e) => e[0] == "p" && e[1] != stream.info.host,
) // cant mute host
.where((e) => e[0] == "p")
.map((e) => e[1])
.toSet();
final isChatDisabled = mutedPubkeys.contains(myKey);
final filteredChat =
(state ?? [])
.where(
(e) =>
!mutedPubkeys.contains(switch (e.kind) {
9735 => ZapReceipt.fromEvent(e).sender ?? e.pubKey,
_ => e.pubKey,
}),
)
firstPassEvents
.where((e) {
final author = switch (e.kind) {
9735 => ZapReceipt.fromEvent(e).sender ?? e.pubKey,
_ => e.pubKey,
};
return moderators.contains(author) || // cant mute self or host
!mutedPubkeys.contains(author);
})
// filter events that are created before stream start time
.where((e) => e.createdAt >= (stream.info.starts ?? 0))
.sortedBy((e) => e.createdAt)
.reversed
.toList();
@ -62,6 +89,16 @@ class ChatWidget extends StatelessWidget {
.where((e) => e.kind == 9735)
.map((e) => ZapReceipt.fromEvent(e))
.toList();
// pubkey -> Set<badge a tag>
final badgeAwards = filteredChat
.where((e) => e.kind == 8)
.map((e) => e.getTags("p").map((p) => (p, e.getFirstTag("a")!)))
.expand((v) => v)
.groupFoldBy(
(e) => e.$1,
(Set<String>? acc, v) => (acc ?? {})..add(v.$2),
);
return Column(
spacing: 8,
crossAxisAlignment: CrossAxisAlignment.start,
@ -79,22 +116,38 @@ class ChatWidget extends StatelessWidget {
key: Key("chat:${filteredChat[idx].id}"),
stream: stream,
msg: filteredChat[idx],
badges:
badgeAwards[filteredChat[idx].pubKey]
?.map(
(a) => ChatBadgeWidget.fromATag(
a,
key: Key("${filteredChat[idx].pubKey}:$a"),
),
)
.toList(),
),
1312 => ChatRaidMessage(
event: filteredChat[idx],
stream: stream,
),
1314 => ChatTimeoutWidget(timeout: filteredChat[idx]),
9735 => ChatZapWidget(
key: Key("chat:${filteredChat[idx].id}"),
stream: stream,
zap: filteredChat[idx],
),
8 => ChatBadgeAwardWidget(
event: filteredChat[idx],
stream: stream,
),
_ => SizedBox(),
},
),
),
if (stream.info.status == StreamStatus.live)
if (stream.info.status == StreamStatus.live && !isChatDisabled)
WriteMessageWidget(stream: stream),
if (stream.info.status == StreamStatus.live && isChatDisabled)
_chatDisabled(firstPassEvents),
if (stream.info.status == StreamStatus.ended)
Container(
padding: EdgeInsets.all(8),
@ -115,6 +168,37 @@ class ChatWidget extends StatelessWidget {
},
);
}
Widget _chatDisabled(List<Nip01Event> events) {
final myKey = ndk.accounts.getPublicKey();
final timeoutEvent = events.firstWhereOrNull(
(e) => e.kind == 1314 && e.pTags.contains(myKey),
);
return Container(
padding: EdgeInsets.all(12),
width: double.maxFinite,
alignment: Alignment.center,
decoration: BoxDecoration(color: WARNING),
child: Column(
children: [
Text("CHAT DISABLED", style: TextStyle(fontWeight: FontWeight.bold)),
if (timeoutEvent != null)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Timeout expires: "),
CountdownTimer(
onTrigger: () => {},
triggerAt: DateTime.fromMillisecondsSinceEpoch(
int.parse(timeoutEvent.getFirstTag("expiration")!) * 1000,
),
),
],
),
],
),
);
}
}
class _TopZappersWidget extends StatelessWidget {

102
lib/widgets/chat_badge.dart Normal file
View File

@ -0,0 +1,102 @@
import 'package:collection/collection.dart';
import 'package:flutter/widgets.dart';
import 'package:ndk/entities.dart';
import 'package:zap_stream_flutter/imgproxy.dart';
import 'package:zap_stream_flutter/main.dart';
import 'package:zap_stream_flutter/theme.dart';
import 'package:zap_stream_flutter/utils.dart';
import 'package:zap_stream_flutter/widgets/profile.dart';
class ChatBadgeAwardWidget extends StatelessWidget {
final Nip01Event event;
final StreamEvent stream;
const ChatBadgeAwardWidget({
super.key,
required this.event,
required this.stream,
});
@override
Widget build(BuildContext context) {
final aTag = event.getFirstTag("a");
if (aTag == null) return SizedBox();
return Container(
margin: EdgeInsets.symmetric(horizontal: 2, vertical: 4),
padding: EdgeInsets.all(5),
decoration: BoxDecoration(color: LAYER_1, borderRadius: DEFAULT_BR),
child: FutureBuilder(
future: ndk.requests.query(filters: [aTagToFilter(aTag)]).future,
builder: (context, state) {
final badge = state.data?.firstOrNull;
final image = badge?.getFirstTag("image");
final name = badge?.getFirstTag("name");
final title = badge?.getFirstTag("description");
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 8,
children: [
Column(
spacing: 8,
children: [
if (image?.isNotEmpty ?? false)
ProxyImg(url: image, width: 64),
if (name?.isNotEmpty ?? false)
Text(
name!,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
if (title?.isNotEmpty ?? false)
Text(
title!,
style: TextStyle(color: LAYER_5),
textAlign: TextAlign.center,
),
],
),
Text(
"Awarded to: ",
style: TextStyle(fontWeight: FontWeight.w500),
),
...event
.getTags("p")
.map((e) => ProfileWidget.pubkey(e, size: 20)),
],
);
},
),
);
}
}
class ChatBadgeWidget extends StatelessWidget {
final Nip01Event badge;
const ChatBadgeWidget({super.key, required this.badge});
static Widget fromATag(String aTag, {Key? key}) {
return FutureBuilder(
future: ndk.requests.query(filters: [aTagToFilter(aTag)]).future,
builder: (context, state) {
final ev = state.data?.firstWhereOrNull(
(e) => "${e.kind}:${e.pubKey}:${e.getDtag()}" == aTag,
);
if (ev == null) return SizedBox();
return ChatBadgeWidget(badge: ev, key: key);
},
);
}
@override
Widget build(BuildContext context) {
final image = badge.getFirstTag("image");
if (image?.isEmpty ?? true) return SizedBox();
return ProxyImg(url: image, resize: 24, height: 24);
}
}

View File

@ -13,8 +13,14 @@ import 'package:zap_stream_flutter/widgets/profile.dart';
class ChatMessageWidget extends StatelessWidget {
final StreamEvent stream;
final Nip01Event msg;
final List<Widget>? badges;
const ChatMessageWidget({super.key, required this.stream, required this.msg});
const ChatMessageWidget({
super.key,
required this.stream,
required this.msg,
this.badges,
});
@override
Widget build(BuildContext context) {
@ -26,7 +32,12 @@ class ChatMessageWidget extends StatelessWidget {
showModalBottomSheet(
context: context,
constraints: BoxConstraints.expand(),
builder: (ctx) => ChatModalWidget(profile: profile, event: msg),
builder:
(ctx) => ChatModalWidget(
profile: profile,
event: msg,
stream: stream,
),
);
}
},
@ -60,6 +71,16 @@ class ChatMessageWidget extends StatelessWidget {
),
),
),
if (badges?.isNotEmpty ?? false) TextSpan(text: " "),
if (badges?.isNotEmpty ?? false)
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Row(
spacing: 4,
mainAxisSize: MainAxisSize.min,
children: badges!,
),
),
TextSpan(text: " "),
...textToSpans(msg.content, msg.tags, msg.pubKey),
],

View File

@ -1,9 +1,13 @@
import 'package:duration/duration.dart';
import 'package:flutter/material.dart';
import 'package:ndk/ndk.dart';
import 'package:zap_stream_flutter/main.dart';
import 'package:zap_stream_flutter/theme.dart';
import 'package:zap_stream_flutter/utils.dart';
import 'package:zap_stream_flutter/widgets/button_follow.dart';
import 'package:zap_stream_flutter/widgets/mute_button.dart';
import 'package:zap_stream_flutter/widgets/nostr_text.dart';
import 'package:zap_stream_flutter/widgets/pill.dart';
import 'package:zap_stream_flutter/widgets/profile.dart';
import 'package:zap_stream_flutter/widgets/reaction.dart';
import 'package:zap_stream_flutter/widgets/zap.dart';
@ -11,11 +15,13 @@ import 'package:zap_stream_flutter/widgets/zap.dart';
class ChatModalWidget extends StatefulWidget {
final Metadata profile;
final Nip01Event event;
final StreamEvent stream;
const ChatModalWidget({
super.key,
required this.profile,
required this.event,
required this.stream,
});
@override
@ -24,9 +30,13 @@ class ChatModalWidget extends StatefulWidget {
class _ChatModalWidget extends State<ChatModalWidget> {
bool _showEmojiPicker = false;
bool _showTimeoutOptions = false;
@override
Widget build(BuildContext context) {
final isModerator =
widget.stream.info.host == ndk.accounts.getPublicKey();
return Container(
padding: EdgeInsets.fromLTRB(5, 10, 5, 0),
child: Column(
@ -38,7 +48,7 @@ class _ChatModalWidget extends State<ChatModalWidget> {
width: double.maxFinite,
decoration: BoxDecoration(color: LAYER_2, borderRadius: DEFAULT_BR),
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 8),
child: NoteText(event: widget.event),
child: NoteText(event: widget.event, showEmbeds: false),
),
Row(
spacing: 8,
@ -50,32 +60,105 @@ class _ChatModalWidget extends State<ChatModalWidget> {
),
onPressed:
() => setState(() {
_showTimeoutOptions = false;
_showEmojiPicker = !_showEmojiPicker;
}),
icon: Icon(Icons.mood),
),
IconButton.filled(
color: ZAP_1,
style: ButtonStyle(
backgroundColor: WidgetStateColor.resolveWith((_) => LAYER_3),
if (widget.profile.lud16?.isNotEmpty ?? false)
IconButton.filled(
color: ZAP_1,
style: ButtonStyle(
backgroundColor: WidgetStateColor.resolveWith(
(_) => LAYER_3,
),
),
onPressed: () {
Navigator.pop(context);
showModalBottomSheet(
context: context,
builder: (ctx) {
return ZapWidget(
pubkey: widget.event.pubKey,
target: widget.event,
);
},
);
},
icon: Icon(Icons.bolt),
),
if (isModerator)
IconButton(
color: WARNING,
style: ButtonStyle(
backgroundColor: WidgetStateColor.resolveWith(
(_) => LAYER_3,
),
),
onPressed:
() => setState(() {
_showEmojiPicker = false;
_showTimeoutOptions = !_showTimeoutOptions;
}),
icon: Icon(Icons.timer_outlined),
),
onPressed: () {
Navigator.pop(context);
showModalBottomSheet(
context: context,
builder: (ctx) {
return ZapWidget(
pubkey: widget.event.pubKey,
target: widget.event,
);
},
);
},
icon: Icon(Icons.bolt),
),
],
),
if (_showEmojiPicker) ReactionWidget(event: widget.event),
if (_showTimeoutOptions)
GridView.count(
shrinkWrap: true,
crossAxisCount: 5,
childAspectRatio: 3,
mainAxisSpacing: 4,
crossAxisSpacing: 4,
children:
[
10,
30,
60,
300,
60 * 10,
60 * 30,
60 * 60,
60 * 60 * 6,
60 * 60 * 12,
60 * 60 * 24,
60 * 60 * 24 * 2,
60 * 60 * 24 * 7,
60 * 60 * 24 * 7 * 2,
60 * 60 * 24 * 7 * 3,
60 * 60 * 24 * 7 * 4,
]
.map(
(v) => PillWidget(
color: LAYER_2,
onTap: () {
final now =
(DateTime.now().millisecondsSinceEpoch / 1000)
.ceil();
final timeout = Nip01Event(
pubKey: ndk.accounts.getPublicKey()!,
kind: 1314,
createdAt: now,
tags: [
["p", widget.event.pubKey],
["expiration", (now + v).toString()],
],
content: "",
);
ndk.broadcast.broadcast(nostrEvent: timeout);
Navigator.pop(context);
},
child: Text(
Duration(seconds: v).pretty(abbreviated: true),
textAlign: TextAlign.center,
),
),
)
.toList(),
),
FollowButton(
pubkey: widget.event.pubKey,
onTap: () {

View File

@ -1,4 +1,5 @@
import 'package:collection/collection.dart';
import 'package:duration/duration.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:ndk/ndk.dart';
@ -43,7 +44,7 @@ class __ChatRaidMessage extends State<ChatRaidMessage>
widget.event.createdAt)
.abs() <
60;
if (isAutoRaid) {
if (isAutoRaid && _isRaiding) {
final autoRaidDelay = Duration(seconds: 5);
_raidingAt = DateTime.now().add(autoRaidDelay);
}
@ -53,16 +54,9 @@ class __ChatRaidMessage extends State<ChatRaidMessage>
Widget build(BuildContext context) {
if (_from == null || _to == null) return SizedBox.shrink();
final otherLink = (_isRaiding ? _to : _from).split(":");
final otherEvent = ndk.requests.query(
filters: [
Filter(
kinds: [int.parse(otherLink[0])],
authors: [otherLink[1]],
dTags: [otherLink[2]],
),
],
);
final otherTag = _isRaiding ? _to : _from;
final otherLink = otherTag.split(":");
final otherEvent = ndk.requests.query(filters: [aTagToFilter(otherTag)]);
return Container(
padding: EdgeInsets.all(8),
@ -209,7 +203,10 @@ class _CountdownTimerState extends State<CountdownTimer>
animation: _animation,
builder: (context, child) {
final secondsLeft = _animation.value.ceil();
return Text(secondsLeft.toString(), style: widget.style);
return Text(
Duration(seconds: secondsLeft).pretty(abbreviated: true),
style: widget.style,
);
},
);
}

View File

@ -0,0 +1,43 @@
import 'package:duration/duration.dart';
import 'package:flutter/widgets.dart';
import 'package:ndk/ndk.dart';
import 'package:zap_stream_flutter/theme.dart';
import 'package:zap_stream_flutter/widgets/profile.dart';
class ChatTimeoutWidget extends StatelessWidget {
final Nip01Event timeout;
const ChatTimeoutWidget({super.key, required this.timeout});
@override
Widget build(BuildContext context) {
final pTags = timeout.pTags;
final duration =
double.parse(timeout.getFirstTag("expiration")!) - timeout.createdAt;
return Container(
padding: EdgeInsets.symmetric(horizontal: 2, vertical: 4),
child: RichText(
text: TextSpan(
style: TextStyle(color: LAYER_5),
children: [
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: ProfileNameWidget.pubkey(timeout.pubKey),
),
TextSpan(text: " timed out "),
...pTags.map(
(p) => WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: ProfileNameWidget.pubkey(p),
),
),
TextSpan(
text: " for ${Duration(seconds: duration.toInt()).pretty()}",
),
],
),
),
);
}
}

View File

@ -195,7 +195,10 @@ class __WriteMessageWidget extends State<WriteMessageWidget> {
);
_controller.clear();
_focusNode.unfocus();
final res = ndk.broadcast.broadcast(nostrEvent: chatMsg);
final res = ndk.broadcast.broadcast(
nostrEvent: chatMsg,
specificRelays: widget.stream.info.relays,
);
await res.broadcastDoneFuture;
}

View File

@ -1,4 +1,3 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:collection/collection.dart';
import 'package:flutter/widgets.dart';
import 'package:zap_stream_flutter/imgproxy.dart';
@ -27,11 +26,7 @@ class CustomEmoji extends StatelessWidget {
(t) => t[0] == "emoji" && t[1] == cleanedEmojiName,
)?[2];
if (customEmoji != null) {
return CachedNetworkImage(
imageUrl: proxyImg(context, customEmoji),
height: size ?? 16,
width: size ?? 16,
);
return ProxyImg(url: customEmoji, width: size ?? 16, height: size ?? 16);
} else {
return Text(emoji);
}

View File

@ -0,0 +1,49 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:zap_stream_flutter/theme.dart';
import 'package:zap_stream_flutter/utils.dart';
import 'package:zap_stream_flutter/widgets/pill.dart';
class LiveTimerWidget extends StatefulWidget {
final DateTime started;
const LiveTimerWidget({super.key, required this.started});
@override
createState() => _LiveTimerWidget();
}
class _LiveTimerWidget extends State<LiveTimerWidget> {
late Timer _timer;
@override
void initState() {
super.initState();
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
setState(() {
// tick
});
});
}
@override
void dispose() {
_timer.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return PillWidget(
color: LAYER_2,
child: Text(
formatSecondsToHHMMSS(
((DateTime.now().millisecondsSinceEpoch -
widget.started.millisecondsSinceEpoch) /
1000)
.toInt(),
),
),
);
}
}

View File

@ -1,24 +1,45 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
import 'package:go_router/go_router.dart';
import 'package:ndk/ndk.dart';
import 'package:ndk/shared/nips/nip19/nip19.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:zap_stream_flutter/imgproxy.dart';
import 'package:zap_stream_flutter/theme.dart';
import 'package:zap_stream_flutter/utils.dart';
import 'package:zap_stream_flutter/widgets/custom_emoji.dart';
import 'package:zap_stream_flutter/widgets/note_embed.dart';
import 'package:zap_stream_flutter/widgets/profile.dart';
import 'package:zap_stream_flutter/widgets/video_player.dart';
class NoteText extends StatelessWidget {
final Nip01Event event;
final bool? embedMedia;
final bool? showEmbeds;
const NoteText({super.key, required this.event});
const NoteText({
super.key,
required this.event,
this.embedMedia,
this.showEmbeds,
});
@override
Widget build(BuildContext context) {
// use markdown rendering for articles
if (event.kind == 30_023) {
return MarkdownBody(data: event.content);
}
return RichText(
text: TextSpan(
children: textToSpans(event.content, event.tags, event.pubKey),
children: textToSpans(
event.content,
event.tags,
event.pubKey,
showEmbeds: showEmbeds,
embedMedia: embedMedia,
),
),
);
}
@ -26,24 +47,21 @@ class NoteText extends StatelessWidget {
/// Converts a nostr note text containing links
/// and mentions into multiple spans for rendering
/// /// https://github.com/leo-lox/camelus/blob/f58455a0ac07fcc780bdc69b8f4544fd5ea4a46d/lib/presentation_layer/components/note_card/note_card_build_split_content.dart#L262
List<InlineSpan> textToSpans(
String content,
List<List<String>> tags,
String pubkey,
) {
return _buildContentSpans(content, tags);
}
/// Content parser from camelus
/// https://github.com/leo-lox/camelus/blob/f58455a0ac07fcc780bdc69b8f4544fd5ea4a46d/lib/presentation_layer/components/note_card/note_card_build_split_content.dart#L262
List<InlineSpan> _buildContentSpans(String content, List<List<String>> tags) {
String pubkey, {
bool? showEmbeds,
bool? embedMedia,
}) {
List<InlineSpan> spans = [];
RegExp exp = RegExp(
r'nostr:(nprofile|npub)[a-zA-Z0-9]+|'
r'nostr:(note|nevent)[a-zA-Z0-9]+|'
r'nostr:(note|nevent|naddr)[a-zA-Z0-9]+|'
r'(#\$\$\s*[0-9]+\s*\$\$)|'
r'(#\w+)|' // Hashtags
r'(https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*))', // URLs
r'(https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,10}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*))', // URLs
caseSensitive: false,
);
@ -53,11 +71,11 @@ List<InlineSpan> _buildContentSpans(String content, List<List<String>> tags) {
String? matched = match.group(0);
if (matched != null) {
if (matched.startsWith('nostr:')) {
spans.add(_buildProfileOrNoteSpan(matched));
spans.add(_buildProfileOrNoteSpan(matched, showEmbeds ?? true));
} else if (matched.startsWith('#')) {
spans.add(_buildHashtagSpan(matched));
} else if (matched.startsWith('http')) {
spans.add(_buildUrlSpan(matched));
spans.add(_buildUrlSpan(matched, embedMedia ?? false));
}
}
return '';
@ -87,12 +105,14 @@ List<InlineSpan> _buildContentSpans(String content, List<List<String>> tags) {
return spans;
}
InlineSpan _buildProfileOrNoteSpan(String word) {
InlineSpan _buildProfileOrNoteSpan(String word, bool showEmbeds) {
final cleanedWord = word.replaceAll('nostr:', '');
final isProfile =
cleanedWord.startsWith('nprofile') || cleanedWord.startsWith('npub');
final isNote =
cleanedWord.startsWith('note') || cleanedWord.startsWith('nevent');
cleanedWord.startsWith('note') ||
cleanedWord.startsWith('nevent') ||
cleanedWord.startsWith("naddr");
if (isProfile) {
final hexKey = bech32ToHex(cleanedWord);
@ -102,11 +122,13 @@ InlineSpan _buildProfileOrNoteSpan(String word) {
return TextSpan(text: "@$cleanedWord");
}
}
if (isNote) {
final eventId = bech32ToHex(cleanedWord);
return TextSpan(text: eventId, style: TextStyle(color: PRIMARY_1));
if (isNote && showEmbeds) {
return WidgetSpan(
child: NoteEmbedWidget(link: cleanedWord),
alignment: PlaceholderAlignment.middle,
);
} else {
return TextSpan(text: word);
return TextSpan(text: word, style: TextStyle(color: PRIMARY_1));
}
}
@ -114,7 +136,29 @@ InlineSpan _buildHashtagSpan(String word) {
return TextSpan(text: word, style: TextStyle(color: PRIMARY_1));
}
InlineSpan _buildUrlSpan(String url) {
InlineSpan _buildUrlSpan(String url, bool embedMedia) {
if (embedMedia &&
(url.endsWith(".jpg") ||
url.endsWith(".gif") ||
url.endsWith(".jpeg") ||
url.endsWith(".webp") ||
url.endsWith(".png") ||
url.endsWith(".bmp"))) {
return WidgetSpan(child: ProxyImg(url: url));
}
if (embedMedia &&
(url.endsWith(".mp4") ||
url.endsWith(".mov") ||
url.endsWith(".webm") ||
url.endsWith(".mkv") ||
url.endsWith(".m3u8"))) {
return WidgetSpan(
child: AspectRatio(
aspectRatio: 16 / 9,
child: Center(child: VideoPlayerWidget(url: url, autoPlay: false)),
),
);
}
return TextSpan(
text: url,
style: TextStyle(color: PRIMARY_1),

View File

@ -0,0 +1,89 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:ndk/ndk.dart';
import 'package:zap_stream_flutter/rx_filter.dart';
import 'package:zap_stream_flutter/theme.dart';
import 'package:zap_stream_flutter/utils.dart';
import 'package:zap_stream_flutter/widgets/nostr_text.dart';
import 'package:zap_stream_flutter/widgets/pill.dart';
import 'package:zap_stream_flutter/widgets/profile.dart';
class NoteEmbedWidget extends StatelessWidget {
final String link;
const NoteEmbedWidget({super.key, required this.link});
@override
Widget build(BuildContext context) {
final entity = decodeBech32ToTLVEntity(link);
return RxFilter<Nip01Event>(
Key("embeded-note:$link"),
filters: [entity.toFilter()],
builder: (context, data) {
final note = data != null && data.isNotEmpty ? data.first : null;
return PillWidget(
onTap: () {
if (note != null) {
// redirect to the stream if its a live stream link
if (note.kind == 30_311) {
context.push("/e/$link", extra: StreamEvent(note));
return;
}
showModalBottomSheet(
context: context,
builder: (context) {
return SingleChildScrollView(child: _NotePreview(note: note));
},
);
}
},
color: LAYER_3,
child: RichText(
text: TextSpan(
children: [
WidgetSpan(child: Icon(Icons.link, size: 16)),
TextSpan(
text: switch (entity.kind) {
30_023 => " Article by ",
30_311 => " Live Stream by ",
_ => " Note by ",
},
),
if (note?.pubKey != null)
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: ProfileNameWidget.pubkey(switch (note!.kind) {
30_311 => StreamEvent(note).info.host,
_ => note.pubKey,
}, linkToProfile: false),
),
],
),
),
);
},
);
}
}
class _NotePreview extends StatelessWidget {
final Nip01Event note;
const _NotePreview({required this.note});
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(color: LAYER_1, borderRadius: DEFAULT_BR),
child: Column(
spacing: 8,
children: [
ProfileWidget.pubkey(note.pubKey),
NoteText(event: note, embedMedia: true),
],
),
);
}
}

View File

@ -24,15 +24,27 @@ class ProfileLoaderWidget extends StatelessWidget {
class ProfileNameWidget extends StatelessWidget {
final Metadata profile;
final TextStyle? style;
final bool? linkToProfile;
const ProfileNameWidget({super.key, required this.profile, this.style});
const ProfileNameWidget({
super.key,
required this.profile,
this.style,
this.linkToProfile,
});
static Widget pubkey(String pubkey, {Key? key, TextStyle? style}) {
static Widget pubkey(
String pubkey, {
Key? key,
TextStyle? style,
bool? linkToProfile,
}) {
return ProfileLoaderWidget(
pubkey,
(ctx, data) => ProfileNameWidget(
profile: data.data ?? Metadata(pubKey: pubkey),
style: style,
linkToProfile: linkToProfile,
),
key: key,
);
@ -50,14 +62,22 @@ class ProfileNameWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap:
() => context.push(
"/p/${Nip19.encodePubKey(profile.pubKey)}",
extra: profile,
),
child: Text(ProfileNameWidget.nameFromProfile(profile), style: style),
final inner = Text(
ProfileNameWidget.nameFromProfile(profile),
style: style,
);
if (linkToProfile ?? true) {
return GestureDetector(
onTap:
() => context.push(
"/p/${Nip19.encodePubKey(profile.pubKey)}",
extra: profile,
),
child: inner,
);
} else {
return inner;
}
}
}
@ -68,6 +88,7 @@ class ProfileWidget extends StatelessWidget {
final List<Widget>? children;
final bool? showName;
final double? spacing;
final bool? linkToProfile;
const ProfileWidget({
super.key,
@ -77,6 +98,7 @@ class ProfileWidget extends StatelessWidget {
this.children,
this.showName,
this.spacing,
this.linkToProfile,
});
static Widget pubkey(
@ -86,6 +108,7 @@ class ProfileWidget extends StatelessWidget {
bool? showName,
double? spacing,
Key? key,
bool? linkToProfile,
}) {
return ProfileLoaderWidget(pubkey, (ctx, state) {
return ProfileWidget(
@ -94,6 +117,7 @@ class ProfileWidget extends StatelessWidget {
showName: showName,
spacing: spacing,
key: key,
linkToProfile: linkToProfile,
children: children,
);
});
@ -105,7 +129,12 @@ class ProfileWidget extends StatelessWidget {
spacing: spacing ?? 8,
children: [
AvatarWidget(profile: profile, size: size),
if (showName ?? true) ProfileNameWidget(profile: profile, key: key),
if (showName ?? true)
ProfileNameWidget(
profile: profile,
key: key,
linkToProfile: linkToProfile,
),
...(children ?? []),
],
);

View File

@ -1,14 +1,11 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
import 'package:flutter_svg/svg.dart';
import 'package:ndk/ndk.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:zap_stream_flutter/imgproxy.dart';
import 'package:zap_stream_flutter/rx_filter.dart';
import 'package:zap_stream_flutter/theme.dart';
import 'package:zap_stream_flutter/utils.dart';
import 'package:zap_stream_flutter/widgets/nostr_text.dart';
class StreamCardsWidget extends StatelessWidget {
final StreamEvent stream;
@ -77,16 +74,9 @@ class StreamCardsWidget extends StatelessWidget {
onTap: () {
launchUrl(Uri.parse(link));
},
child: CachedNetworkImage(
imageUrl: proxyImg(context, image!),
errorWidget:
(_, _, _) => SvgPicture.asset(
"assets/svg/logo.svg",
height: 40,
),
),
child: ProxyImg(url: link, placeholderSize: 40),
)
: CachedNetworkImage(imageUrl: proxyImg(context, image!)),
: ProxyImg(url: link, placeholderSize: 40),
),
MarkdownBody(
data: card.content,

View File

@ -1,6 +1,7 @@
import 'package:collection/collection.dart';
import 'package:flutter/widgets.dart';
import 'package:ndk/ndk.dart';
import 'package:zap_stream_flutter/main.dart';
import 'package:zap_stream_flutter/theme.dart';
import 'package:zap_stream_flutter/utils.dart';
import 'package:zap_stream_flutter/widgets/stream_tile.dart';
@ -35,16 +36,34 @@ class StreamGrid extends StatelessWidget {
final live = streams.where((s) => s.info.status == StreamStatus.live);
final ended = streams.where((s) => s.info.status == StreamStatus.ended);
final planned = streams.where((s) => s.info.status == StreamStatus.planned);
return Column(
spacing: 16,
children: [
if (showLive && live.isNotEmpty)
_streamGroup(context, "Live", live.toList()),
if (showPlanned && planned.isNotEmpty)
_streamGroup(context, "Planned", planned.toList()),
if (showEnded && ended.isNotEmpty)
_streamGroup(context, "Ended", ended.toList()),
],
final followList =
ndk.accounts.isLoggedIn
? ndk.follows.getContactList(ndk.accounts.getPublicKey()!)
: Future.value(null);
return FutureBuilder(
future: followList,
builder: (context, state) {
final follows = state.data?.contacts ?? [];
final followsLive = live.where((e) => follows.contains(e.info.host));
final liveNotFollowing = live.where(
(e) => !follows.contains(e.info.host),
);
return Column(
spacing: 16,
children: [
if (followsLive.isNotEmpty)
_streamGroup(context, "Following", followsLive.toList()),
if (showLive && liveNotFollowing.isNotEmpty)
_streamGroup(context, "Live", liveNotFollowing.toList()),
if (showPlanned && planned.isNotEmpty)
_streamGroup(context, "Planned", planned.toList()),
if (showEnded && ended.isNotEmpty)
_streamGroup(context, "Ended", ended.toList()),
],
);
},
);
}

View File

@ -1,10 +1,14 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:intl/intl.dart';
import 'package:share_plus/share_plus.dart';
import 'package:zap_stream_flutter/main.dart';
import 'package:zap_stream_flutter/theme.dart';
import 'package:zap_stream_flutter/utils.dart';
import 'package:zap_stream_flutter/widgets/button.dart';
import 'package:zap_stream_flutter/widgets/button_follow.dart';
import 'package:zap_stream_flutter/widgets/game_info.dart';
import 'package:zap_stream_flutter/widgets/live_timer.dart';
import 'package:zap_stream_flutter/widgets/nostr_text.dart';
import 'package:zap_stream_flutter/widgets/pill.dart';
import 'package:zap_stream_flutter/widgets/profile.dart';
@ -17,6 +21,8 @@ class StreamInfoWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final isMe = ndk.accounts.getPublicKey() == stream.info.host;
final startedDate =
stream.info.starts != null
? DateTime.fromMillisecondsSinceEpoch(stream.info.starts! * 1000)
@ -27,26 +33,51 @@ class StreamInfoWidget extends StatelessWidget {
spacing: 8,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ProfileWidget.pubkey(stream.info.host),
FollowButton(
pubkey: stream.info.host,
onTap: () {
Navigator.pop(context);
},
),
Text(
stream.info.title ?? "",
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
if (startedDate != null)
RichText(
text: TextSpan(
style: TextStyle(color: LAYER_5, fontSize: 14),
children: [
TextSpan(text: "Started "),
TextSpan(text: DateFormat().format(startedDate)),
],
ProfileWidget.pubkey(stream.info.host, linkToProfile: false),
Row(
spacing: 8,
children: [
if (!isMe)
FollowButton(
pubkey: stream.info.host,
onTap: () {
Navigator.pop(context);
},
),
BasicButton.text(
"Share",
icon: Icon(Icons.share, size: 16),
onTap: () {
SharePlus.instance.share(
ShareParams(
title: stream.info.title,
uri: Uri.parse("https://zap.stream/${stream.link}"),
),
);
},
),
],
),
if (stream.info.title?.isNotEmpty ?? false)
Text(
stream.info.title!,
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
if (startedDate != null)
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
RichText(
text: TextSpan(
style: TextStyle(color: LAYER_5, fontSize: 14),
children: [
TextSpan(text: "Started "),
TextSpan(text: DateFormat().format(startedDate)),
],
),
),
LiveTimerWidget(started: startedDate),
],
),
if (stream.info.summary?.isNotEmpty ?? false)
Text.rich(

View File

@ -31,22 +31,7 @@ class StreamTileWidget extends StatelessWidget {
aspectRatio: 16 / 9,
child: Stack(
children: [
Center(
child: CachedNetworkImage(
imageUrl: proxyImg(context, stream.info.image ?? ""),
fit: BoxFit.cover,
placeholder:
(ctx, url) => SvgPicture.asset(
"assets/svg/logo.svg",
height: 100,
),
errorWidget:
(context, url, error) => SvgPicture.asset(
"assets/svg/logo.svg",
height: 100,
),
),
),
Center(child: ProxyImg(url: stream.info.image ?? "", placeholderSize: 100,)),
if (stream.info.status != null)
Positioned(
right: 8,

View File

@ -0,0 +1,60 @@
import 'package:chewie/chewie.dart';
import 'package:flutter/widgets.dart';
import 'package:video_player/video_player.dart';
import 'package:zap_stream_flutter/imgproxy.dart';
import 'package:zap_stream_flutter/main.dart';
class VideoPlayerWidget extends StatefulWidget {
final String url;
final String? placeholder;
final double? aspectRatio;
final bool? autoPlay;
const VideoPlayerWidget({
super.key,
required this.url,
this.placeholder,
this.aspectRatio,
this.autoPlay,
});
@override
State<StatefulWidget> createState() => _VideoPlayerWidget();
}
class _VideoPlayerWidget extends State<VideoPlayerWidget> {
late final VideoPlayerController _controller;
late final ChewieController _chewieController;
@override
void initState() {
super.initState();
_controller = VideoPlayerController.networkUrl(
Uri.parse(widget.url),
httpHeaders: Map.from({"user-agent": userAgent}),
);
_chewieController = ChewieController(
videoPlayerController: _controller,
autoPlay: widget.autoPlay ?? true,
aspectRatio: widget.aspectRatio,
autoInitialize: true,
placeholder:
(widget.placeholder?.isNotEmpty ?? false)
? ProxyImg(url: widget.placeholder!)
: null,
);
}
@override
void dispose() {
_controller.dispose();
_chewieController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Chewie(controller: _chewieController);
}
}

View File

@ -1,6 +1,9 @@
import 'dart:io';
import 'package:clipboard/clipboard.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:ndk/domain_layer/usecases/lnurl/lnurl.dart';
import 'package:ndk/ndk.dart';
import 'package:qr_flutter/qr_flutter.dart';
@ -31,6 +34,9 @@ class ZapWidget extends StatefulWidget {
class _ZapWidget extends State<ZapWidget> {
final TextEditingController _comment = TextEditingController();
final TextEditingController _customAmount = TextEditingController();
final FocusNode _customAmountFocus = FocusNode();
bool _loading = false;
String? _error;
String? _pr;
int? _amount;
@ -67,8 +73,9 @@ class _ZapWidget extends State<ZapWidget> {
),
],
),
if (_pr == null) ..._inputs(),
if (_pr != null) ..._invoice(),
if (_pr == null && !_loading) ..._inputs(),
if (_pr != null) ..._invoice(context),
if (_loading) CircularProgressIndicator(),
],
),
);
@ -83,32 +90,78 @@ class _ZapWidget extends State<ZapWidget> {
crossAxisCount: 5,
mainAxisSpacing: 5,
crossAxisSpacing: 5,
childAspectRatio: 1.5,
childAspectRatio: 1.9,
),
itemBuilder: (ctx, idx) => _zapAmount(_zapAmounts[idx]),
),
Row(
spacing: 8,
children: [
Expanded(
child: TextFormField(
controller: _customAmount,
focusNode: _customAmountFocus,
keyboardType: TextInputType.number,
decoration: InputDecoration(labelText: "Custom Amount"),
),
),
BasicButton.text(
"Confirm",
onTap: () {
final newAmount = int.tryParse(_customAmount.text);
if (newAmount != null) {
setState(() {
_error = null;
_amount = newAmount;
_customAmountFocus.unfocus();
});
} else {
setState(() {
_error = "Invalid custom amount";
_amount = null;
});
}
},
),
],
),
TextFormField(
controller: _comment,
decoration: InputDecoration(labelText: "Comment"),
),
BasicButton.text(
"Zap",
_amount != null ? "Zap ${formatSats(_amount!)} sats" : "Zap",
disabled: _amount == null,
decoration: BoxDecoration(color: LAYER_3, borderRadius: DEFAULT_BR),
onTap: () {
onTap: () async {
try {
_loadZap();
setState(() {
_error = null;
_loading = true;
});
await _loadZap();
} catch (e) {
setState(() {
_error = e.toString();
});
} finally {
setState(() {
_loading = false;
});
}
},
),
if (_error != null) Text(_error!),
if (_error != null)
Text(
_error!,
style: TextStyle(color: WARNING, fontWeight: FontWeight.bold),
),
];
}
List<Widget> _invoice() {
List<Widget> _invoice(BuildContext context) {
final prLink = "lightning:${_pr!}";
return [
QrImageView(
data: _pr!,
@ -123,22 +176,50 @@ class _ZapWidget extends State<ZapWidget> {
GestureDetector(
onTap: () async {
await FlutterClipboard.copy(_pr!);
if (Platform.isIOS && context.mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text("Copied to clipboard")));
}
},
child: Text(_pr!, overflow: TextOverflow.ellipsis),
child: Container(
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(borderRadius: DEFAULT_BR, color: LAYER_2),
child: Row(
spacing: 4,
children: [
Icon(Icons.copy, size: 16),
Expanded(child: Text(_pr!, overflow: TextOverflow.ellipsis)),
],
),
),
),
BasicButton.text(
"Open in Wallet",
onTap: () async {
try {
await launchUrlString("lightning:${_pr!}");
await launchUrlString(prLink);
} catch (e) {
if (e is PlatformException) {
if (e.code == "ACTIVITY_NOT_FOUND") {
setState(() {
_error = "No lightning wallet installed";
});
return;
}
}
setState(() {
_error = e is String ? e : e.toString();
});
}
},
),
if (_error != null) Text(_error!),
if (_error != null)
Text(
_error!,
style: TextStyle(color: WARNING, fontWeight: FontWeight.bold),
),
];
}
@ -204,6 +285,9 @@ class _ZapWidget extends State<ZapWidget> {
return GestureDetector(
onTap:
() => setState(() {
_error = null;
_customAmount.clear();
_customAmountFocus.unfocus();
_amount = n;
}),
child: Container(

View File

@ -11,6 +11,7 @@ import flutter_secure_storage_macos
import objectbox_flutter_libs
import package_info_plus
import path_provider_foundation
import share_plus
import shared_preferences_foundation
import sqflite_darwin
import url_launcher_macos
@ -24,6 +25,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ObjectboxFlutterLibsPlugin.register(with: registry.registrar(forPlugin: "ObjectboxFlutterLibsPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))

View File

@ -177,6 +177,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.11"
duration:
dependency: "direct main"
description:
name: duration
sha256: "13e5d20723c9c1dde8fb318cf86716d10ce294734e81e44ae1a817f3ae714501"
url: "https://pub.dev"
source: hosted
version: "4.0.3"
elliptic:
dependency: transitive
description:
@ -811,6 +819,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.28.0"
share_plus:
dependency: "direct main"
description:
name: share_plus
sha256: b2961506569e28948d75ec346c28775bb111986bb69dc6a20754a457e3d97fa0
url: "https://pub.dev"
source: hosted
version: "11.0.0"
share_plus_platform_interface:
dependency: transitive
description:
name: share_plus_platform_interface
sha256: "1032d392bc5d2095a77447a805aa3f804d2ae6a4d5eef5e6ebb3bd94c1bc19ef"
url: "https://pub.dev"
source: hosted
version: "6.0.0"
shared_preferences:
dependency: transitive
description:

View File

@ -1,7 +1,7 @@
name: zap_stream_flutter
description: "zap.stream"
publish_to: 'none'
version: 0.5.0+7
version: 0.7.0+9
environment:
sdk: ^3.7.2
@ -33,6 +33,8 @@ dependencies:
bech32: ^0.2.2
intl: ^0.20.2
flutter_markdown_plus: ^1.0.3
share_plus: ^11.0.0
duration: ^4.0.3
dependency_overrides:
ndk:

View File

@ -10,6 +10,7 @@
#include <file_selector_windows/file_selector_windows.h>
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <objectbox_flutter_libs/objectbox_flutter_libs_plugin.h>
#include <share_plus/share_plus_windows_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
@ -21,6 +22,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
ObjectboxFlutterLibsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ObjectboxFlutterLibsPlugin"));
SharePlusWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}

View File

@ -7,6 +7,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
file_selector_windows
flutter_secure_storage_windows
objectbox_flutter_libs
share_plus
url_launcher_windows
)