mirror of
https://github.com/nostrlabs-io/zap-stream-flutter.git
synced 2025-06-15 19:48:23 +00:00
Compare commits
29 Commits
Author | SHA1 | Date | |
---|---|---|---|
4ca9460a6c
|
|||
21f69e433e
|
|||
52953a4c16
|
|||
54a61322cf
|
|||
4c6d5b995f
|
|||
be66446e85
|
|||
787a848257
|
|||
2d855362e4
|
|||
5e28b40c5c
|
|||
12b4475c60
|
|||
e0e9175536
|
|||
465c6f222e
|
|||
eefbbc2f73
|
|||
f094569ed4
|
|||
f5a03d756b
|
|||
1f8124b708
|
|||
42d9293ecb
|
|||
e3dc985b0d
|
|||
9e5108930a
|
|||
0b83881a3d
|
|||
efd95837ea
|
|||
3e18f7544e
|
|||
f1e518a0d7
|
|||
1a912e88ce
|
|||
f8a2df0097
|
|||
fb32b1cfdb
|
|||
994b40dda9
|
|||
e6531bff7c
|
|||
3e672f9e28
|
BIN
assets/category/art.jpeg
Normal file
BIN
assets/category/art.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 660 KiB |
BIN
assets/category/gaming.jpeg
Normal file
BIN
assets/category/gaming.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 333 KiB |
BIN
assets/category/irl.jpeg
Normal file
BIN
assets/category/irl.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 521 KiB |
BIN
assets/category/music.jpeg
Normal file
BIN
assets/category/music.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 300 KiB |
BIN
assets/category/talk.jpeg
Normal file
BIN
assets/category/talk.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 402 KiB |
@ -12,8 +12,14 @@ class LoginAccount {
|
||||
final AccountType type;
|
||||
final String pubkey;
|
||||
final String? privateKey;
|
||||
final List<String>? signerRelays;
|
||||
|
||||
LoginAccount._({required this.type, required this.pubkey, this.privateKey});
|
||||
LoginAccount._({
|
||||
required this.type,
|
||||
required this.pubkey,
|
||||
this.privateKey,
|
||||
this.signerRelays,
|
||||
});
|
||||
|
||||
static LoginAccount nip19(String key) {
|
||||
final keyData = bech32ToHex(key);
|
||||
@ -42,6 +48,19 @@ class LoginAccount {
|
||||
return LoginAccount._(type: AccountType.externalSigner, pubkey: key);
|
||||
}
|
||||
|
||||
static LoginAccount bunker(
|
||||
String privateKey,
|
||||
String pubkey,
|
||||
List<String> relays,
|
||||
) {
|
||||
return LoginAccount._(
|
||||
type: AccountType.externalSigner,
|
||||
pubkey: pubkey,
|
||||
privateKey: privateKey,
|
||||
signerRelays: relays,
|
||||
);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toJson(LoginAccount? acc) => {
|
||||
"type": acc?.type.name,
|
||||
"pubKey": acc?.pubkey,
|
||||
@ -53,9 +72,11 @@ class LoginAccount {
|
||||
if ((json["pubKey"] as String).length != 64) {
|
||||
throw "Invalid pubkey, length != 64";
|
||||
}
|
||||
if (json.containsKey("privateKey") &&
|
||||
(json["privateKey"] as String).length != 64) {
|
||||
throw "Invalid privateKey, length != 64";
|
||||
if (json.containsKey("privateKey")) {
|
||||
final privKey = json["privateKey"] as String?;
|
||||
if (privKey != null && privKey.length != 64) {
|
||||
throw "Invalid privateKey, length != 64";
|
||||
}
|
||||
}
|
||||
return LoginAccount._(
|
||||
type: AccountType.values.firstWhere(
|
||||
@ -75,14 +96,17 @@ class LoginData extends ValueNotifier<LoginAccount?> {
|
||||
|
||||
LoginData() : super(null) {
|
||||
super.addListener(() async {
|
||||
final data = json.encode(LoginAccount.toJson(value));
|
||||
await _storage.write(key: _storageKey, value: data);
|
||||
if (value != null) {
|
||||
final data = json.encode(LoginAccount.toJson(value));
|
||||
await _storage.write(key: _storageKey, value: data);
|
||||
} else {
|
||||
await _storage.delete(key: _storageKey);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> logout() async {
|
||||
void logout() {
|
||||
super.value = null;
|
||||
await _storage.delete(key: _storageKey);
|
||||
}
|
||||
|
||||
Future<void> load() async {
|
||||
|
@ -6,6 +6,8 @@ import 'package:ndk/ndk.dart';
|
||||
import 'package:ndk_amber/ndk_amber.dart';
|
||||
import 'package:ndk_objectbox/ndk_objectbox.dart';
|
||||
import 'package:ndk_rust_verifier/ndk_rust_verifier.dart';
|
||||
import 'package:zap_stream_flutter/pages/category.dart';
|
||||
import 'package:zap_stream_flutter/pages/hashtag.dart';
|
||||
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';
|
||||
@ -27,14 +29,22 @@ class NoVerify extends EventVerifier {
|
||||
|
||||
final ndkCache = DbObjectBox();
|
||||
final eventVerifier = kDebugMode ? NoVerify() : RustEventVerifier();
|
||||
var ndk = Ndk(NdkConfig(eventVerifier: eventVerifier, cache: ndkCache, bootstrapRelays: defaultRelays));
|
||||
var ndk = Ndk(
|
||||
NdkConfig(
|
||||
eventVerifier: eventVerifier,
|
||||
cache: ndkCache,
|
||||
bootstrapRelays: defaultRelays,
|
||||
//engine: NdkEngine.JIT,
|
||||
),
|
||||
);
|
||||
|
||||
const userAgent = "zap.stream/1.0";
|
||||
const defaultRelays = [
|
||||
"wss://nos.lol",
|
||||
"wss://relay.damus.io",
|
||||
"wss://relay.primal.net",
|
||||
"wss://relay.snort.social"
|
||||
"wss://relay.snort.social",
|
||||
"wss://relay.fountain.fm",
|
||||
];
|
||||
const searchRelays = ["wss://relay.nostr.band", "wss://search.nos.today"];
|
||||
|
||||
@ -143,6 +153,21 @@ Future<void> main() async {
|
||||
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?,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
110
lib/pages/category.dart
Normal file
110
lib/pages/category.dart
Normal file
@ -0,0 +1,110 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:ndk/ndk.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/category_top_zapped.dart';
|
||||
import 'package:zap_stream_flutter/widgets/header.dart';
|
||||
import 'package:zap_stream_flutter/widgets/pill.dart';
|
||||
import 'package:zap_stream_flutter/widgets/stream_grid.dart';
|
||||
|
||||
class CategoryPage extends StatelessWidget {
|
||||
final String category;
|
||||
final GameInfo? info;
|
||||
|
||||
const CategoryPage({super.key, required this.category, required this.info});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SingleChildScrollView(
|
||||
child: Container(
|
||||
margin: EdgeInsets.all(5.0),
|
||||
child: Column(
|
||||
spacing: 16,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
HeaderWidget(),
|
||||
Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
if (info?.coverImage != null)
|
||||
Container(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
constraints: BoxConstraints(maxHeight: 200),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: DEFAULT_BR,
|
||||
color: LAYER_1,
|
||||
),
|
||||
child:
|
||||
info!.coverImage!.startsWith("assets/")
|
||||
? Image.asset(
|
||||
info!.coverImage!,
|
||||
fit: BoxFit.contain,
|
||||
)
|
||||
: CachedNetworkImage(
|
||||
imageUrl: proxyImg(context, info!.coverImage!),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: 8,
|
||||
children: [
|
||||
Text(
|
||||
info?.name ?? category,
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
if (info?.genres != null)
|
||||
Row(
|
||||
spacing: 4,
|
||||
children:
|
||||
info!.genres
|
||||
.map(
|
||||
(g) => PillWidget(
|
||||
color: LAYER_1,
|
||||
child: Text(
|
||||
g,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
CategoryTopZapped(tag: category),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
RxFilter<Nip01Event>(
|
||||
Key("category-page:$category"),
|
||||
filters: [
|
||||
Filter(
|
||||
kinds: [30_311],
|
||||
limit: 100,
|
||||
tTags: [category.toLowerCase()],
|
||||
),
|
||||
],
|
||||
builder: (ctx, state) {
|
||||
if (state == null) {
|
||||
return SizedBox.shrink();
|
||||
} else {
|
||||
return StreamGrid(events: state);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
45
lib/pages/hashtag.dart
Normal file
45
lib/pages/hashtag.dart
Normal file
@ -0,0 +1,45 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ndk/ndk.dart';
|
||||
import 'package:zap_stream_flutter/rx_filter.dart';
|
||||
import 'package:zap_stream_flutter/widgets/category_top_zapped.dart';
|
||||
import 'package:zap_stream_flutter/widgets/header.dart';
|
||||
import 'package:zap_stream_flutter/widgets/stream_grid.dart';
|
||||
|
||||
class HashtagPage extends StatelessWidget {
|
||||
final String tag;
|
||||
|
||||
const HashtagPage({super.key, required this.tag});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SingleChildScrollView(
|
||||
child: Container(
|
||||
margin: EdgeInsets.all(5.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
HeaderWidget(),
|
||||
Text(
|
||||
"#$tag",
|
||||
style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
|
||||
),
|
||||
CategoryTopZapped(tag: tag),
|
||||
RxFilter<Nip01Event>(
|
||||
Key("tags-page:$tag"),
|
||||
filters: [
|
||||
Filter(kinds: [30_311], limit: 50, tTags: [tag.toLowerCase()]),
|
||||
],
|
||||
builder: (ctx, state) {
|
||||
if (state == null) {
|
||||
return SizedBox.shrink();
|
||||
} else {
|
||||
return StreamGrid(events: state);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -13,9 +13,11 @@ class HomePage extends StatelessWidget {
|
||||
child: Container(
|
||||
margin: EdgeInsets.all(5.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
HeaderWidget(),
|
||||
RxFilter<Nip01Event>(
|
||||
Key("home-page"),
|
||||
filters: [
|
||||
Filter(kinds: [30_311], limit: 50),
|
||||
],
|
||||
@ -27,7 +29,6 @@ class HomePage extends StatelessWidget {
|
||||
}
|
||||
},
|
||||
),
|
||||
//other stuff..
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -1,3 +1,5 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:amberflutter/amberflutter.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
@ -14,27 +16,30 @@ class LoginPage extends StatelessWidget {
|
||||
return Column(
|
||||
spacing: 20,
|
||||
children: [
|
||||
FutureBuilder(
|
||||
future: Amberflutter().isAppInstalled(),
|
||||
builder: (ctx, state) {
|
||||
if (state.data ?? false) {
|
||||
return BasicButton.text(
|
||||
"Login with Amber",
|
||||
onTap: () async {
|
||||
final amber = Amberflutter();
|
||||
final result = await amber.getPublicKey();
|
||||
if (result['signature'] != null) {
|
||||
final key = bech32ToHex(result['signature']);
|
||||
loginData.value = LoginAccount.externalPublicKeyHex(key);
|
||||
ctx.go("/");
|
||||
}
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return SizedBox.shrink();
|
||||
}
|
||||
},
|
||||
),
|
||||
if (Platform.isAndroid)
|
||||
FutureBuilder(
|
||||
future: Amberflutter().isAppInstalled(),
|
||||
builder: (ctx, state) {
|
||||
if (state.data ?? false) {
|
||||
return BasicButton.text(
|
||||
"Login with Amber",
|
||||
onTap: () async {
|
||||
final amber = Amberflutter();
|
||||
final result = await amber.getPublicKey();
|
||||
if (result['signature'] != null) {
|
||||
final key = bech32ToHex(result['signature']);
|
||||
loginData.value = LoginAccount.externalPublicKeyHex(key);
|
||||
if (ctx.mounted) {
|
||||
ctx.go("/");
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return SizedBox.shrink();
|
||||
}
|
||||
},
|
||||
),
|
||||
BasicButton.text(
|
||||
"Login with Key",
|
||||
onTap: () => context.push("/login/key"),
|
||||
|
@ -30,6 +30,14 @@ class _LoginInputPage extends State<LoginInputPage> {
|
||||
"Login",
|
||||
onTap: () async {
|
||||
try {
|
||||
if (_controller.text.startsWith("bunker://")) {
|
||||
// not supported yet in ndk
|
||||
setState(() {
|
||||
_error = "Bunker login not supported yet";
|
||||
_controller.clear();
|
||||
});
|
||||
return;
|
||||
}
|
||||
final keyData = bech32ToHex(_controller.text);
|
||||
if (keyData.isNotEmpty) {
|
||||
loginData.value = LoginAccount.nip19(_controller.text);
|
||||
|
@ -99,7 +99,9 @@ class _NewAccountPage extends State<NewAccountPage> {
|
||||
loginData.value = LoginAccount.privateKeyHex(
|
||||
_privateKey.privateKey!,
|
||||
);
|
||||
context.go("/");
|
||||
if (context.mounted) {
|
||||
context.go("/");
|
||||
}
|
||||
})
|
||||
.catchError((e) {
|
||||
setState(() {
|
||||
|
@ -10,6 +10,7 @@ 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/header.dart';
|
||||
import 'package:zap_stream_flutter/widgets/nostr_text.dart';
|
||||
import 'package:zap_stream_flutter/widgets/profile.dart';
|
||||
import 'package:zap_stream_flutter/widgets/stream_grid.dart';
|
||||
|
||||
@ -53,9 +54,15 @@ class ProfilePage extends StatelessWidget {
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
profile.about ?? "",
|
||||
style: TextStyle(color: LAYER_5),
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
style: TextStyle(color: LAYER_5),
|
||||
children: textToSpans(
|
||||
profile.about ?? "",
|
||||
[],
|
||||
profile.pubKey,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -81,7 +88,7 @@ class ProfilePage extends StatelessWidget {
|
||||
),
|
||||
|
||||
RxFilter<Nip01Event>(
|
||||
key: Key("profile-streams:$hexPubkey"),
|
||||
Key("profile-streams:$hexPubkey"),
|
||||
relays: defaultRelays,
|
||||
filters: [
|
||||
Filter(kinds: [30_311], limit: 200, pTags: [hexPubkey]),
|
||||
|
@ -1,16 +1,19 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:chewie/chewie.dart';
|
||||
import 'package:flutter/material.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';
|
||||
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/button.dart';
|
||||
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/zap.dart';
|
||||
|
||||
class StreamPage extends StatefulWidget {
|
||||
@ -72,6 +75,24 @@ class _StreamPage extends State<StreamPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RxFilter<Nip01Event>(
|
||||
Key("stream:event:${widget.stream.aTag}"),
|
||||
relays: widget.stream.info.relays,
|
||||
filters: [
|
||||
Filter(
|
||||
kinds: [widget.stream.event.kind],
|
||||
authors: [widget.stream.event.pubKey],
|
||||
dTags: [widget.stream.event.getDtag()!],
|
||||
),
|
||||
],
|
||||
builder: (ctx, state) {
|
||||
final stream = StreamEvent(state?.firstOrNull ?? widget.stream.event);
|
||||
return _buildStream(context, stream);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStream(BuildContext context, StreamEvent stream) {
|
||||
return Column(
|
||||
spacing: 4,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@ -80,28 +101,28 @@ class _StreamPage extends State<StreamPage> {
|
||||
aspectRatio: 16 / 9,
|
||||
child:
|
||||
_chewieController != null
|
||||
? Chewie(controller: _chewieController!)
|
||||
? Chewie(
|
||||
key: Key("stream:player:${stream.aTag}"),
|
||||
controller: _chewieController!,
|
||||
)
|
||||
: Container(
|
||||
color: LAYER_1,
|
||||
child:
|
||||
(widget.stream.info.image?.isNotEmpty ?? false)
|
||||
(stream.info.image?.isNotEmpty ?? false)
|
||||
? CachedNetworkImage(
|
||||
imageUrl: proxyImg(
|
||||
context,
|
||||
widget.stream.info.image!,
|
||||
),
|
||||
imageUrl: proxyImg(context, stream.info.image!),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
widget.stream.info.title ?? "",
|
||||
stream.info.title ?? "",
|
||||
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 18),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
ProfileWidget.pubkey(widget.stream.info.host),
|
||||
ProfileWidget.pubkey(stream.info.host),
|
||||
Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
@ -118,29 +139,47 @@ class _StreamPage extends State<StreamPage> {
|
||||
constraints: BoxConstraints.expand(),
|
||||
builder: (ctx) {
|
||||
return ZapWidget(
|
||||
pubkey: widget.stream.info.host,
|
||||
target: widget.stream.event,
|
||||
pubkey: stream.info.host,
|
||||
target: stream.event,
|
||||
zapTags:
|
||||
// tag goal onto zap request
|
||||
stream.info.goal != null
|
||||
? [
|
||||
["e", stream.info.goal!],
|
||||
]
|
||||
: null,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
if (widget.stream.info.participants != null)
|
||||
if (stream.info.participants != null)
|
||||
PillWidget(
|
||||
color: LAYER_1,
|
||||
child: Text(
|
||||
"${widget.stream.info.participants} viewers",
|
||||
"${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),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(child: ChatWidget(stream: widget.stream)),
|
||||
Expanded(child: ChatWidget(stream: stream)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
import 'dart:developer' as developer;
|
||||
|
||||
@ -14,14 +15,14 @@ class RxFilter<T> extends StatefulWidget {
|
||||
final T Function(Nip01Event)? mapper;
|
||||
final List<String>? relays;
|
||||
|
||||
const RxFilter({
|
||||
super.key,
|
||||
const RxFilter(
|
||||
Key key, {
|
||||
required this.filters,
|
||||
required this.builder,
|
||||
this.mapper,
|
||||
this.leaveOpen = true,
|
||||
this.relays,
|
||||
});
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _RxFilter<T>();
|
||||
@ -29,6 +30,7 @@ class RxFilter<T> extends StatefulWidget {
|
||||
|
||||
class _RxFilter<T> extends State<RxFilter<T>> {
|
||||
late NdkResponse _response;
|
||||
late StreamSubscription _listener;
|
||||
HashMap<String, (int, T)>? _events;
|
||||
|
||||
@override
|
||||
@ -37,8 +39,6 @@ class _RxFilter<T> extends State<RxFilter<T>> {
|
||||
developer.log("RX:SEDNING ${widget.filters}");
|
||||
_response = ndk.requests.subscription(
|
||||
filters: widget.filters,
|
||||
cacheRead: true,
|
||||
cacheWrite: true,
|
||||
explicitRelays: widget.relays,
|
||||
);
|
||||
if (!widget.leaveOpen) {
|
||||
@ -47,28 +47,30 @@ class _RxFilter<T> extends State<RxFilter<T>> {
|
||||
ndk.requests.closeSubscription(_response.requestId);
|
||||
});
|
||||
}
|
||||
_response.stream
|
||||
_listener = _response.stream
|
||||
.bufferTime(const Duration(milliseconds: 500))
|
||||
.where((events) => events.isNotEmpty)
|
||||
.handleError((e) {
|
||||
developer.log("RX:ERROR $e");
|
||||
})
|
||||
.listen((events) {
|
||||
setState(() {
|
||||
_events ??= HashMap();
|
||||
developer.log(
|
||||
"RX:GOT ${events.length} events for ${widget.filters}",
|
||||
);
|
||||
events.forEach(_replaceInto);
|
||||
});
|
||||
if (context.mounted) {
|
||||
setState(() {
|
||||
developer.log(
|
||||
"RX:GOT ${events.length} events for ${widget.filters}",
|
||||
);
|
||||
events.forEach(_replaceInto);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _replaceInto(Nip01Event ev) {
|
||||
final evKey = _eventKey(ev);
|
||||
final existing = _events?[evKey];
|
||||
_events ??= HashMap();
|
||||
final existing = _events![evKey];
|
||||
if (existing == null || existing.$1 < ev.createdAt) {
|
||||
_events?[evKey] = (
|
||||
_events![evKey] = (
|
||||
ev.createdAt,
|
||||
widget.mapper != null ? widget.mapper!(ev) : ev as T,
|
||||
);
|
||||
@ -90,6 +92,7 @@ class _RxFilter<T> extends State<RxFilter<T>> {
|
||||
super.dispose();
|
||||
|
||||
developer.log("RX:CLOSING ${widget.filters}");
|
||||
_listener.cancel();
|
||||
ndk.requests.closeSubscription(_response.requestId);
|
||||
}
|
||||
|
||||
@ -107,14 +110,14 @@ class RxFutureFilter<T> extends StatelessWidget {
|
||||
final Widget? loadingWidget;
|
||||
final T Function(Nip01Event)? mapper;
|
||||
|
||||
const RxFutureFilter({
|
||||
super.key,
|
||||
const RxFutureFilter(
|
||||
Key key, {
|
||||
required this.filterBuilder,
|
||||
required this.builder,
|
||||
this.mapper,
|
||||
this.leaveOpen = true,
|
||||
this.loadingWidget,
|
||||
});
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -123,6 +126,7 @@ class RxFutureFilter<T> extends StatelessWidget {
|
||||
builder: (ctx, data) {
|
||||
if (data.hasData) {
|
||||
return RxFilter<T>(
|
||||
super.key!,
|
||||
filters: data.data!,
|
||||
mapper: mapper,
|
||||
builder: builder,
|
||||
|
224
lib/utils.dart
224
lib/utils.dart
@ -1,6 +1,10 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:bech32/bech32.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
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/nip19.dart';
|
||||
|
||||
@ -14,6 +18,23 @@ class StreamEvent {
|
||||
return "${event.kind}:${event.pubKey}:${info.id}";
|
||||
}
|
||||
|
||||
/// Get the naddr for this stream
|
||||
String get link {
|
||||
final k = event.kind & 0xFFFFFFFF;
|
||||
final idData = utf8.encode(info.id!);
|
||||
final tlv = [
|
||||
TLV(0, idData.length, idData),
|
||||
TLV(2, 32, hex.decode(event.pubKey)),
|
||||
TLV(3, 4, [
|
||||
(k >> 24) & 0xFF,
|
||||
(k >> 16) & 0xFF,
|
||||
(k >> 8) & 0xFF,
|
||||
k & 0xFF,
|
||||
]),
|
||||
];
|
||||
return encodeBech32TLV("naddr", tlv);
|
||||
}
|
||||
|
||||
StreamEvent(this.event) {
|
||||
info = extractStreamInfo(event);
|
||||
}
|
||||
@ -42,6 +63,7 @@ class StreamInfo {
|
||||
String? gameId;
|
||||
GameInfo? gameInfo;
|
||||
List<String> streams;
|
||||
List<String>? relays;
|
||||
|
||||
StreamInfo({
|
||||
this.id,
|
||||
@ -67,16 +89,16 @@ class StreamInfo {
|
||||
}
|
||||
|
||||
class GameInfo {
|
||||
String id;
|
||||
String name;
|
||||
List<String> genres;
|
||||
String className;
|
||||
final String id;
|
||||
final String name;
|
||||
final List<String> genres;
|
||||
final String? coverImage;
|
||||
|
||||
GameInfo({
|
||||
const GameInfo({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.genres,
|
||||
required this.className,
|
||||
required this.coverImage,
|
||||
});
|
||||
}
|
||||
|
||||
@ -126,6 +148,12 @@ StreamInfo extractStreamInfo(Nip01Event ev) {
|
||||
matchTag(t, 'starts', (v) => ret.starts = int.tryParse(v));
|
||||
matchTag(t, 'ends', (v) => ret.ends = int.tryParse(v));
|
||||
matchTag(t, 'service', (v) => ret.service = v);
|
||||
if (t[0] == "relays") {
|
||||
ret.relays = t.slice(1);
|
||||
if (ret.relays!.isEmpty) {
|
||||
ret.relays = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var sortedTags = sortStreamTags(ev.tags);
|
||||
@ -169,32 +197,32 @@ StreamInfo extractStreamInfo(Nip01Event ev) {
|
||||
({GameInfo? gameInfo, String? gameId}) extractGameTag(List<String> tags) {
|
||||
final gameId = tags.firstWhereOrNull((a) => gameTagFormat.hasMatch(a));
|
||||
|
||||
final internalGame = AllCategories.firstWhereOrNull(
|
||||
final internalGame = allCategories.firstWhereOrNull(
|
||||
(a) => gameId == 'internal:${a.id}',
|
||||
);
|
||||
if (internalGame != null) {
|
||||
return (
|
||||
gameInfo: GameInfo(
|
||||
id: internalGame.id,
|
||||
id: "internal:${internalGame.id}",
|
||||
name: internalGame.name,
|
||||
genres: internalGame.tags,
|
||||
className: internalGame.className,
|
||||
coverImage: internalGame.coverImage,
|
||||
),
|
||||
gameId: gameId,
|
||||
);
|
||||
}
|
||||
|
||||
final lowerTags = tags.map((t) => t.toLowerCase());
|
||||
final taggedCategory = AllCategories.firstWhereOrNull(
|
||||
final taggedCategory = allCategories.firstWhereOrNull(
|
||||
(a) => a.tags.any(lowerTags.contains),
|
||||
);
|
||||
if (taggedCategory != null) {
|
||||
return (
|
||||
gameInfo: GameInfo(
|
||||
id: taggedCategory.id,
|
||||
id: "internal:${taggedCategory.id}",
|
||||
name: taggedCategory.name,
|
||||
genres: taggedCategory.tags,
|
||||
className: taggedCategory.className,
|
||||
coverImage: taggedCategory.coverImage,
|
||||
),
|
||||
gameId: gameId,
|
||||
);
|
||||
@ -210,28 +238,89 @@ String getHost(Nip01Event ev) {
|
||||
}
|
||||
|
||||
class Category {
|
||||
String id;
|
||||
String name;
|
||||
List<String> tags;
|
||||
String className;
|
||||
final String id;
|
||||
final String name;
|
||||
final IconData icon;
|
||||
final List<String> tags;
|
||||
final int order;
|
||||
final String? coverImage;
|
||||
|
||||
Category({
|
||||
const Category({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.icon,
|
||||
required this.tags,
|
||||
required this.className,
|
||||
required this.order,
|
||||
this.coverImage,
|
||||
});
|
||||
}
|
||||
|
||||
List<Category> AllCategories = []; // Implement as needed
|
||||
const List<Category> allCategories = [
|
||||
Category(
|
||||
id: "irl",
|
||||
name: "IRL",
|
||||
icon: Icons.face,
|
||||
tags: ["irl"],
|
||||
order: 0,
|
||||
coverImage: "assets/category/irl.jpeg",
|
||||
),
|
||||
Category(
|
||||
id: "gaming",
|
||||
name: "Gaming",
|
||||
icon: Icons.gamepad,
|
||||
tags: ["gaming"],
|
||||
order: 0,
|
||||
coverImage: "assets/category/gaming.jpeg",
|
||||
),
|
||||
Category(
|
||||
id: "music",
|
||||
name: "Music",
|
||||
icon: Icons.note,
|
||||
tags: ["music", "raido"],
|
||||
order: 0,
|
||||
coverImage: "assets/category/music.jpeg",
|
||||
),
|
||||
Category(
|
||||
id: "talk",
|
||||
name: "Talk",
|
||||
icon: Icons.mic,
|
||||
tags: ["talk", "just-chatting"],
|
||||
order: 0,
|
||||
coverImage: "assets/category/talk.jpeg",
|
||||
),
|
||||
Category(
|
||||
id: "art",
|
||||
name: "Art",
|
||||
icon: Icons.brush,
|
||||
tags: ["art"],
|
||||
order: 0,
|
||||
coverImage: "assets/category/art.jpeg",
|
||||
),
|
||||
Category(
|
||||
id: "gambling",
|
||||
name: "Gambling",
|
||||
icon: Icons.casino,
|
||||
tags: ["gambling", "casino", "slots"],
|
||||
order: 1,
|
||||
),
|
||||
Category(
|
||||
id: "science-and-technology",
|
||||
name: "Science & Technology",
|
||||
icon: Icons.casino,
|
||||
tags: ["science", "tech", "technology"],
|
||||
order: 1,
|
||||
),
|
||||
];
|
||||
|
||||
String formatSats(int n) {
|
||||
String formatSats(int n, {int? maxDigits}) {
|
||||
final fmt = NumberFormat();
|
||||
fmt.maximumFractionDigits = maxDigits ?? 2;
|
||||
if (n >= 1000000) {
|
||||
return "${(n / 1000000).toStringAsFixed(1)}M";
|
||||
} else if (n >= 1000) {
|
||||
return "${(n / 1000).toStringAsFixed(1)}k";
|
||||
return "${fmt.format(n / 1000000)}M";
|
||||
} else if (n >= 1500) {
|
||||
return "${fmt.format(n / 1000)}K";
|
||||
} else {
|
||||
return "$n";
|
||||
return fmt.format(n);
|
||||
}
|
||||
}
|
||||
|
||||
@ -242,6 +331,49 @@ String zapSum(List<Nip01Event> zaps) {
|
||||
return formatSats(total);
|
||||
}
|
||||
|
||||
class TopZaps {
|
||||
final int sum;
|
||||
final List<ZapReceipt> zaps;
|
||||
|
||||
const TopZaps({required this.sum, required this.zaps});
|
||||
}
|
||||
|
||||
Map<String, TopZaps> topZapSender(Iterable<ZapReceipt> zaps) {
|
||||
return Map.fromEntries(
|
||||
zaps
|
||||
.where((e) => e.sender != null)
|
||||
.groupListsBy((v) => v.sender!)
|
||||
.entries
|
||||
.map(
|
||||
(v) => MapEntry(
|
||||
v.key,
|
||||
TopZaps(
|
||||
sum: v.value.fold(0, (acc, v) => acc + (v.amountSats ?? 0)),
|
||||
zaps: v.value,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, TopZaps> topZapReceiver(Iterable<ZapReceipt> zaps) {
|
||||
return Map.fromEntries(
|
||||
zaps
|
||||
.where((e) => e.recipient != null)
|
||||
.groupListsBy((v) => v.recipient!)
|
||||
.entries
|
||||
.map(
|
||||
(v) => MapEntry(
|
||||
v.key,
|
||||
TopZaps(
|
||||
sum: v.value.fold(0, (acc, v) => acc + (v.amountSats ?? 0)),
|
||||
zaps: v.value,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String bech32ToHex(String bech32) {
|
||||
final decoder = Bech32Decoder();
|
||||
final data = decoder.convert(bech32, 10_000);
|
||||
@ -260,6 +392,25 @@ class TLV {
|
||||
final List<int> value;
|
||||
|
||||
TLV(this.type, this.length, this.value);
|
||||
|
||||
void validate() {
|
||||
if (type < 0 || type > 255) {
|
||||
throw ArgumentError('Type must be 0-255 (1 byte)');
|
||||
}
|
||||
if (length < 0 || length > 255) {
|
||||
throw ArgumentError('Length must be 0-255 (1 byte)');
|
||||
}
|
||||
if (length != value.length) {
|
||||
throw ArgumentError(
|
||||
'Length ($length) does not match value length (${value.length})',
|
||||
);
|
||||
}
|
||||
for (var byte in value) {
|
||||
if (byte < 0 || byte > 255) {
|
||||
throw ArgumentError('Value bytes must be 0-255');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<TLV> parseTLV(List<int> data) {
|
||||
@ -294,3 +445,28 @@ List<TLV> parseTLV(List<int> data) {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
List<int> serializeTLV(List<TLV> tlvs) {
|
||||
List<int> result = [];
|
||||
|
||||
for (var tlv in tlvs) {
|
||||
tlv.validate();
|
||||
result.add(tlv.type);
|
||||
result.add(tlv.length);
|
||||
result.addAll(tlv.value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Encodes TLV data into a Bech32 string
|
||||
String encodeBech32TLV(String hrp, List<TLV> tlvs) {
|
||||
try {
|
||||
final data8bit = serializeTLV(tlvs);
|
||||
final data5bit = Nip19.convertBits(data8bit, 8, 5, true);
|
||||
final bech32Data = Bech32(hrp, data5bit);
|
||||
return bech32.encode(bech32Data, 10_000);
|
||||
} catch (e) {
|
||||
throw FormatException('Failed to encode Bech32 or TLV: $e');
|
||||
}
|
||||
}
|
||||
|
69
lib/widgets/button_follow.dart
Normal file
69
lib/widgets/button_follow.dart
Normal file
@ -0,0 +1,69 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:zap_stream_flutter/main.dart';
|
||||
import 'package:zap_stream_flutter/theme.dart';
|
||||
import 'package:zap_stream_flutter/widgets/button.dart';
|
||||
|
||||
class FollowButton extends StatelessWidget {
|
||||
final String pubkey;
|
||||
final void Function()? onTap;
|
||||
final void Function()? onFollow;
|
||||
final void Function()? onUnfollow;
|
||||
|
||||
const FollowButton({
|
||||
super.key,
|
||||
required this.pubkey,
|
||||
this.onTap,
|
||||
this.onFollow,
|
||||
this.onUnfollow,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final signer = ndk.accounts.getLoggedAccount()?.signer;
|
||||
if (signer == null || signer.getPublicKey() == pubkey) {
|
||||
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),
|
||||
),
|
||||
],
|
||||
),
|
||||
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!();
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
109
lib/widgets/category_top_zapped.dart
Normal file
109
lib/widgets/category_top_zapped.dart
Normal file
@ -0,0 +1,109 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ndk/ndk.dart';
|
||||
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/avatar.dart';
|
||||
import 'package:zap_stream_flutter/widgets/profile.dart';
|
||||
|
||||
class CategoryTopZapped extends StatelessWidget {
|
||||
final String tag;
|
||||
final int? limit;
|
||||
|
||||
const CategoryTopZapped({super.key, required this.tag, this.limit});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: 8,
|
||||
children: [
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
WidgetSpan(
|
||||
child: Icon(Icons.bolt, color: ZAP_1),
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
),
|
||||
TextSpan(
|
||||
text: " Most Zapped Streamers",
|
||||
style: TextStyle(color: LAYER_4, fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
primary: false,
|
||||
child: FutureBuilder(
|
||||
future:
|
||||
ndk.requests
|
||||
.query(
|
||||
filters: [
|
||||
Filter(
|
||||
kinds: [30_311],
|
||||
limit: 100,
|
||||
tTags: [tag.toLowerCase()],
|
||||
),
|
||||
],
|
||||
)
|
||||
.future,
|
||||
builder: (context, state) {
|
||||
final aTags =
|
||||
(state.data ?? [])
|
||||
.map((e) => "30311:${e.pubKey}:${e.getDtag()}")
|
||||
.toList();
|
||||
return RxFilter<Nip01Event>(
|
||||
Key("top-zapped:$tag:${aTags.length}"),
|
||||
filters: [
|
||||
Filter(kinds: [9735], aTags: aTags),
|
||||
],
|
||||
builder: (context, zaps) {
|
||||
final parsedZaps =
|
||||
zaps?.map((e) => ZapReceipt.fromEvent(e)) ?? [];
|
||||
final topZapped = topZapReceiver(parsedZaps).entries
|
||||
.sortedBy((e) => e.value.sum)
|
||||
.reversed
|
||||
.take(limit ?? 5);
|
||||
|
||||
return Row(
|
||||
spacing: 16,
|
||||
children:
|
||||
topZapped
|
||||
.map(
|
||||
(e) => Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
AvatarWidget.pubkey(e.key),
|
||||
Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
spacing: 2,
|
||||
children: [
|
||||
Text(
|
||||
formatSats(e.value.sum, maxDigits: 0),
|
||||
style: TextStyle(
|
||||
color: ZAP_1,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
ProfileNameWidget.pubkey(e.key),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
import 'dart:developer' as developer;
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ndk/ndk.dart';
|
||||
@ -7,16 +5,17 @@ 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/avatar.dart';
|
||||
import 'package:zap_stream_flutter/widgets/nostr_text.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_write.dart';
|
||||
import 'package:zap_stream_flutter/widgets/chat_zap.dart';
|
||||
import 'package:zap_stream_flutter/widgets/goal.dart';
|
||||
import 'package:zap_stream_flutter/widgets/profile.dart';
|
||||
import 'package:zap_stream_flutter/widgets/profile_modal.dart';
|
||||
|
||||
class ChatWidget extends StatelessWidget {
|
||||
final StreamEvent stream;
|
||||
|
||||
const ChatWidget({super.key, required this.stream});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var muteLists = [stream.info.host];
|
||||
@ -24,18 +23,24 @@ class ChatWidget extends StatelessWidget {
|
||||
muteLists.add(ndk.accounts.getPublicKey()!);
|
||||
}
|
||||
|
||||
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),
|
||||
];
|
||||
return RxFilter<Nip01Event>(
|
||||
filters: [
|
||||
Filter(kinds: [1311, 9735], limit: 200, aTags: [stream.aTag]),
|
||||
Filter(kinds: [Nip51List.kMute], authors: muteLists),
|
||||
],
|
||||
Key("stream:chat:${stream.aTag}"),
|
||||
relays: stream.info.relays,
|
||||
filters: filters,
|
||||
builder: (ctx, state) {
|
||||
final mutedPubkeys =
|
||||
(state ?? [])
|
||||
.where((e) => e.kind == Nip51List.kMute)
|
||||
.map((e) => e.tags)
|
||||
.expand((e) => e)
|
||||
.where((e) => e[0] == "p")
|
||||
.where(
|
||||
(e) => e[0] == "p" && e[1] != stream.info.host,
|
||||
) // cant mute host
|
||||
.map((e) => e[1])
|
||||
.toSet();
|
||||
|
||||
@ -52,52 +57,54 @@ class ChatWidget extends StatelessWidget {
|
||||
.reversed
|
||||
.toList();
|
||||
|
||||
final zaps =
|
||||
filteredChat
|
||||
.where((e) => e.kind == 9735)
|
||||
.map((e) => ZapReceipt.fromEvent(e))
|
||||
.toList();
|
||||
return Column(
|
||||
spacing: 8,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_TopZappersWidget(events: filteredChat),
|
||||
if (zaps.isNotEmpty) _TopZappersWidget(events: zaps),
|
||||
if (stream.info.goal != null) GoalWidget.id(stream.info.goal!),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
reverse: true,
|
||||
shrinkWrap: true,
|
||||
primary: true,
|
||||
itemCount: filteredChat.length,
|
||||
itemBuilder:
|
||||
(ctx, idx) => switch (filteredChat[idx].kind) {
|
||||
1311 => Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 2,
|
||||
vertical: 2,
|
||||
),
|
||||
child: _ChatMessageWidget(
|
||||
stream: stream,
|
||||
msg: filteredChat[idx],
|
||||
),
|
||||
1311 => ChatMessageWidget(
|
||||
key: Key("chat:${filteredChat[idx].id}"),
|
||||
stream: stream,
|
||||
msg: filteredChat[idx],
|
||||
),
|
||||
9735 => Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 2,
|
||||
vertical: 2,
|
||||
),
|
||||
child: _ChatZapWidget(
|
||||
stream: stream,
|
||||
zap: filteredChat[idx],
|
||||
),
|
||||
1312 => ChatRaidMessage(
|
||||
event: filteredChat[idx],
|
||||
stream: stream,
|
||||
),
|
||||
_ => SizedBox.shrink(),
|
||||
9735 => ChatZapWidget(
|
||||
key: Key("chat:${filteredChat[idx].id}"),
|
||||
stream: stream,
|
||||
zap: filteredChat[idx],
|
||||
),
|
||||
_ => SizedBox(),
|
||||
},
|
||||
),
|
||||
),
|
||||
if (stream.info.status == StreamStatus.live)
|
||||
_WriteMessageWidget(stream: stream),
|
||||
WriteMessageWidget(stream: stream),
|
||||
if (stream.info.status == StreamStatus.ended)
|
||||
Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
margin: EdgeInsets.symmetric(vertical: 8),
|
||||
margin: EdgeInsets.only(bottom: 8, top: 4),
|
||||
width: double.maxFinite,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(borderRadius: DEFAULT_BR),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: DEFAULT_BR,
|
||||
color: PRIMARY_1,
|
||||
),
|
||||
child: Text(
|
||||
"STREAM ENDED",
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
@ -111,7 +118,7 @@ class ChatWidget extends StatelessWidget {
|
||||
}
|
||||
|
||||
class _TopZappersWidget extends StatelessWidget {
|
||||
final List<Nip01Event> events;
|
||||
final List<ZapReceipt> events;
|
||||
|
||||
const _TopZappersWidget({required this.events});
|
||||
|
||||
@ -119,8 +126,6 @@ class _TopZappersWidget extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final topZaps =
|
||||
events
|
||||
.where((e) => e.kind == 9735)
|
||||
.map((e) => ZapReceipt.fromEvent(e))
|
||||
.fold(<String, int>{}, (acc, e) {
|
||||
if (e.sender != null) {
|
||||
acc[e.sender!] = (acc[e.sender!] ?? 0) + e.amountSats!;
|
||||
@ -164,270 +169,3 @@ class _TopZappersWidget extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ChatZapWidget extends StatelessWidget {
|
||||
final StreamEvent stream;
|
||||
final Nip01Event zap;
|
||||
|
||||
const _ChatZapWidget({required this.stream, required this.zap});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final parsed = ZapReceipt.fromEvent(zap);
|
||||
return Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: ZAP_1),
|
||||
borderRadius: DEFAULT_BR,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_zapperRowZap(parsed),
|
||||
if (parsed.comment?.isNotEmpty ?? false) Text(parsed.comment!),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _zapperRowZap(ZapReceipt parsed) {
|
||||
if (parsed.sender != null) {
|
||||
return ProfileLoaderWidget(parsed.sender!, (ctx, state) {
|
||||
final name = ProfileNameWidget.nameFromProfile(
|
||||
state.data ?? Metadata(pubKey: parsed.sender!),
|
||||
);
|
||||
return _zapperRow(name, parsed.amountSats ?? 0, state.data);
|
||||
});
|
||||
} else {
|
||||
return _zapperRow("Anon", parsed.amountSats ?? 0, null);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _zapperRow(String name, int amount, Metadata? profile) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(color: ZAP_1),
|
||||
children: [
|
||||
WidgetSpan(
|
||||
child: Icon(Icons.bolt, color: ZAP_1),
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
),
|
||||
if (profile != null)
|
||||
WidgetSpan(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(right: 8),
|
||||
child: AvatarWidget(profile: profile, size: 20),
|
||||
),
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
),
|
||||
TextSpan(text: name),
|
||||
TextSpan(text: " zapped ", style: TextStyle(color: FONT_COLOR)),
|
||||
TextSpan(text: formatSats(amount)),
|
||||
TextSpan(text: " sats", style: TextStyle(color: FONT_COLOR)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ChatMessageWidget extends StatelessWidget {
|
||||
final StreamEvent stream;
|
||||
final Nip01Event msg;
|
||||
|
||||
const _ChatMessageWidget({required this.stream, required this.msg});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ProfileLoaderWidget(msg.pubKey, (ctx, state) {
|
||||
final profile = state.data ?? Metadata(pubKey: msg.pubKey);
|
||||
return GestureDetector(
|
||||
onLongPress: () {
|
||||
if (ndk.accounts.canSign) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
constraints: BoxConstraints.expand(),
|
||||
builder:
|
||||
(ctx) => ProfileModalWidget(profile: profile, event: msg),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Column(
|
||||
spacing: 2,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_chatText(profile),
|
||||
RxFilter<Nip01Event>(
|
||||
filters: [
|
||||
Filter(kinds: [9735, 7], eTags: [msg.id]),
|
||||
],
|
||||
builder: (ctx, data) => _chatReactions(data),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _chatText(Metadata profile) {
|
||||
return RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
WidgetSpan(
|
||||
child: AvatarWidget(profile: profile, size: 24),
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
),
|
||||
TextSpan(text: " "),
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: ProfileNameWidget(
|
||||
profile: profile,
|
||||
style: TextStyle(
|
||||
color: msg.pubKey == stream.info.host ? PRIMARY_1 : SECONDARY_1,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextSpan(text: " "),
|
||||
...textToSpans(msg.content, msg.tags, msg.pubKey),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _chatReactions(List<Nip01Event>? events) {
|
||||
if ((events?.length ?? 0) == 0) return SizedBox.shrink();
|
||||
|
||||
final zaps = events!
|
||||
.where((e) => e.kind == 9735)
|
||||
.map((e) => ZapReceipt.fromEvent(e));
|
||||
final reactions = events.where((e) => e.kind == 7);
|
||||
|
||||
return Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
if (zaps.isNotEmpty)
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 4, vertical: 2),
|
||||
decoration: BoxDecoration(color: LAYER_2, borderRadius: DEFAULT_BR),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.bolt, color: ZAP_1, size: 16),
|
||||
Text(
|
||||
formatSats(
|
||||
zaps.fold(0, (acc, v) => acc + (v.amountSats ?? 0)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (reactions.isNotEmpty)
|
||||
...reactions
|
||||
.fold(<String, Set<String>>{}, (acc, v) {
|
||||
acc[v.content] ??= Set();
|
||||
acc[v.content]!.add(v.pubKey);
|
||||
return acc;
|
||||
})
|
||||
.entries
|
||||
.map(
|
||||
(v) => Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 4, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: LAYER_2,
|
||||
borderRadius: DEFAULT_BR,
|
||||
),
|
||||
child: Center(child: Text(v.key)),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _WriteMessageWidget extends StatefulWidget {
|
||||
final StreamEvent stream;
|
||||
|
||||
const _WriteMessageWidget({required this.stream});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => __WriteMessageWidget();
|
||||
}
|
||||
|
||||
class __WriteMessageWidget extends State<_WriteMessageWidget> {
|
||||
late final TextEditingController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = TextEditingController();
|
||||
}
|
||||
|
||||
Future<void> _sendMessage() async {
|
||||
final login = ndk.accounts.getLoggedAccount();
|
||||
if (login == null) return;
|
||||
|
||||
final chatMsg = Nip01Event(
|
||||
pubKey: login.pubkey,
|
||||
kind: 1311,
|
||||
content: _controller.text,
|
||||
tags: [
|
||||
["a", widget.stream.aTag],
|
||||
],
|
||||
);
|
||||
final res = ndk.broadcast.broadcast(nostrEvent: chatMsg);
|
||||
await res.broadcastDoneFuture;
|
||||
_controller.text = "";
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final canSign = ndk.accounts.canSign;
|
||||
final isLogin = ndk.accounts.isLoggedIn;
|
||||
|
||||
return Container(
|
||||
margin: EdgeInsets.fromLTRB(4, 8, 4, 0),
|
||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
||||
decoration: BoxDecoration(color: LAYER_2, borderRadius: DEFAULT_BR),
|
||||
child:
|
||||
canSign
|
||||
? Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _controller,
|
||||
onSubmitted: (_) => _sendMessage(),
|
||||
decoration: InputDecoration(
|
||||
labelText: "Write message",
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 4),
|
||||
labelStyle: TextStyle(color: LAYER_4, fontSize: 14),
|
||||
border: InputBorder.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
//IconButton(onPressed: () {}, icon: Icon(Icons.mood)),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
_sendMessage();
|
||||
},
|
||||
icon: Icon(Icons.send),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
isLogin
|
||||
? "Can't write messages with npub login"
|
||||
: "Please login to send messages",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
140
lib/widgets/chat_message.dart
Normal file
140
lib/widgets/chat_message.dart
Normal file
@ -0,0 +1,140 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ndk/ndk.dart';
|
||||
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/avatar.dart';
|
||||
import 'package:zap_stream_flutter/widgets/chat_modal.dart';
|
||||
import 'package:zap_stream_flutter/widgets/custom_emoji.dart';
|
||||
import 'package:zap_stream_flutter/widgets/nostr_text.dart';
|
||||
import 'package:zap_stream_flutter/widgets/profile.dart';
|
||||
|
||||
class ChatMessageWidget extends StatelessWidget {
|
||||
final StreamEvent stream;
|
||||
final Nip01Event msg;
|
||||
|
||||
const ChatMessageWidget({super.key, required this.stream, required this.msg});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ProfileLoaderWidget(msg.pubKey, (ctx, state) {
|
||||
final profile = state.data ?? Metadata(pubKey: msg.pubKey);
|
||||
return GestureDetector(
|
||||
onLongPress: () {
|
||||
if (ndk.accounts.canSign) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
constraints: BoxConstraints.expand(),
|
||||
builder: (ctx) => ChatModalWidget(profile: profile, event: msg),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 2, vertical: 4),
|
||||
child: Column(
|
||||
spacing: 2,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [_chatText(profile), ChatReactions(msg: msg)],
|
||||
),
|
||||
),
|
||||
);
|
||||
}, key: Key("chat:${msg.id}:profile"));
|
||||
}
|
||||
|
||||
Widget _chatText(Metadata profile) {
|
||||
return RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
WidgetSpan(
|
||||
child: AvatarWidget(profile: profile, size: 24),
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
),
|
||||
TextSpan(text: " "),
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: ProfileNameWidget(
|
||||
profile: profile,
|
||||
style: TextStyle(
|
||||
color: msg.pubKey == stream.info.host ? PRIMARY_1 : SECONDARY_1,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextSpan(text: " "),
|
||||
...textToSpans(msg.content, msg.tags, msg.pubKey),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ChatReactions extends StatelessWidget {
|
||||
final Nip01Event msg;
|
||||
|
||||
const ChatReactions({super.key, required this.msg});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RxFilter<Nip01Event>(
|
||||
Key("chat:${msg.id}:reactions"),
|
||||
filters: [
|
||||
Filter(kinds: [9735, 7], eTags: [msg.id]),
|
||||
],
|
||||
builder: (ctx, data) => _chatReactions(ctx, data),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _chatReactions(BuildContext context, List<Nip01Event>? events) {
|
||||
if ((events?.length ?? 0) == 0) return SizedBox.shrink();
|
||||
|
||||
// reactions must have e tag pointing to msg
|
||||
final filteredEvents = events!.where((e) => e.getEId() == msg.id);
|
||||
final zaps = filteredEvents
|
||||
.where((e) => e.kind == 9735)
|
||||
.map((e) => ZapReceipt.fromEvent(e));
|
||||
final reactions = filteredEvents.where((e) => e.kind == 7);
|
||||
|
||||
return Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
if (zaps.isNotEmpty)
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 4, vertical: 2),
|
||||
decoration: BoxDecoration(color: LAYER_2, borderRadius: DEFAULT_BR),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.bolt, color: ZAP_1, size: 16),
|
||||
Text(
|
||||
formatSats(
|
||||
zaps.fold(0, (acc, v) => acc + (v.amountSats ?? 0)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (reactions.isNotEmpty)
|
||||
...reactions
|
||||
.fold(<String, Set<Nip01Event>>{}, (acc, v) {
|
||||
// ignore: prefer_collection_literals
|
||||
acc[v.content] ??= Set();
|
||||
acc[v.content]!.add(v);
|
||||
return acc;
|
||||
})
|
||||
.entries
|
||||
.map(
|
||||
(v) => Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 4, vertical: 2),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: BoxDecoration(
|
||||
color: LAYER_2,
|
||||
borderRadius: DEFAULT_BR,
|
||||
),
|
||||
child: Center(
|
||||
child: CustomEmoji(emoji: v.key, tags: v.value.first.tags),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
95
lib/widgets/chat_modal.dart
Normal file
95
lib/widgets/chat_modal.dart
Normal file
@ -0,0 +1,95 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ndk/ndk.dart';
|
||||
import 'package:zap_stream_flutter/theme.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/profile.dart';
|
||||
import 'package:zap_stream_flutter/widgets/reaction.dart';
|
||||
import 'package:zap_stream_flutter/widgets/zap.dart';
|
||||
|
||||
class ChatModalWidget extends StatefulWidget {
|
||||
final Metadata profile;
|
||||
final Nip01Event event;
|
||||
|
||||
const ChatModalWidget({
|
||||
super.key,
|
||||
required this.profile,
|
||||
required this.event,
|
||||
});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _ChatModalWidget();
|
||||
}
|
||||
|
||||
class _ChatModalWidget extends State<ChatModalWidget> {
|
||||
bool _showEmojiPicker = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.fromLTRB(5, 10, 5, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: 10,
|
||||
children: [
|
||||
ProfileWidget(profile: widget.profile),
|
||||
Container(
|
||||
width: double.maxFinite,
|
||||
decoration: BoxDecoration(color: LAYER_2, borderRadius: DEFAULT_BR),
|
||||
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
||||
child: NoteText(event: widget.event),
|
||||
),
|
||||
Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
IconButton.filled(
|
||||
color: LAYER_5,
|
||||
style: ButtonStyle(
|
||||
backgroundColor: WidgetStateColor.resolveWith((_) => LAYER_3),
|
||||
),
|
||||
onPressed:
|
||||
() => setState(() {
|
||||
_showEmojiPicker = !_showEmojiPicker;
|
||||
}),
|
||||
icon: Icon(Icons.mood),
|
||||
),
|
||||
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 (_showEmojiPicker) ReactionWidget(event: widget.event),
|
||||
FollowButton(
|
||||
pubkey: widget.event.pubKey,
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
MuteButton(
|
||||
pubkey: widget.event.pubKey,
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
216
lib/widgets/chat_raid.dart
Normal file
216
lib/widgets/chat_raid.dart
Normal file
@ -0,0 +1,216 @@
|
||||
import 'package:collection/collection.dart';
|
||||
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/utils.dart';
|
||||
import 'package:zap_stream_flutter/widgets/profile.dart';
|
||||
|
||||
class ChatRaidMessage extends StatefulWidget {
|
||||
final StreamEvent stream;
|
||||
final Nip01Event event;
|
||||
|
||||
const ChatRaidMessage({super.key, required this.stream, required this.event});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => __ChatRaidMessage();
|
||||
}
|
||||
|
||||
class __ChatRaidMessage extends State<ChatRaidMessage>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final String? _from;
|
||||
late final String? _to;
|
||||
late final bool _isRaiding;
|
||||
|
||||
DateTime? _raidingAt;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_from =
|
||||
widget.event.tags.firstWhereOrNull(
|
||||
(t) => t[0] == "a" && (t[3] == "from" || t[3] == "root"),
|
||||
)?[1];
|
||||
_to =
|
||||
widget.event.tags.firstWhereOrNull(
|
||||
(t) => t[0] == "a" && (t[3] == "to" || t[3] == "mention"),
|
||||
)?[1];
|
||||
_isRaiding = _from == widget.stream.aTag;
|
||||
final isAutoRaid =
|
||||
((DateTime.now().millisecondsSinceEpoch / 1000) -
|
||||
widget.event.createdAt)
|
||||
.abs() <
|
||||
60;
|
||||
if (isAutoRaid) {
|
||||
final autoRaidDelay = Duration(seconds: 5);
|
||||
_raidingAt = DateTime.now().add(autoRaidDelay);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
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]],
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
return Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
margin: EdgeInsets.symmetric(vertical: 4),
|
||||
width: double.maxFinite,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(borderRadius: DEFAULT_BR, color: PRIMARY_1),
|
||||
child: FutureBuilder(
|
||||
future: otherEvent.future,
|
||||
builder: (ctx, state) {
|
||||
final otherStream = state.data?.firstWhereOrNull(
|
||||
(e) => e.getDtag() == otherLink[2] && e.pubKey == otherLink[1],
|
||||
);
|
||||
if (otherStream == null) return SizedBox.shrink();
|
||||
final otherStreamEvent = StreamEvent(otherStream);
|
||||
return Column(
|
||||
children: [
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
children: [
|
||||
TextSpan(text: _isRaiding ? "RAIDING " : "RAID FROM "),
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: ProfileLoaderWidget(otherStreamEvent.info.host, (
|
||||
ctx,
|
||||
profile,
|
||||
) {
|
||||
return Text(
|
||||
ProfileNameWidget.nameFromProfile(
|
||||
profile.data ??
|
||||
Metadata(pubKey: otherStreamEvent.info.host),
|
||||
).toUpperCase(),
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
);
|
||||
}),
|
||||
),
|
||||
if (_raidingAt == null)
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
context.go(
|
||||
"/e/${otherStreamEvent.link}",
|
||||
extra: otherStreamEvent,
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Icon(Icons.open_in_new, size: 15),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (_raidingAt != null)
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
TextSpan(text: "Raiding in "),
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: CountdownTimer(
|
||||
triggerAt: _raidingAt!,
|
||||
onTrigger: () {
|
||||
context.go(
|
||||
"/e/${otherStreamEvent.link}",
|
||||
extra: otherStreamEvent,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CountdownTimer extends StatefulWidget {
|
||||
final void Function() onTrigger;
|
||||
final TextStyle? style;
|
||||
final DateTime triggerAt;
|
||||
|
||||
const CountdownTimer({
|
||||
super.key,
|
||||
required this.onTrigger,
|
||||
this.style,
|
||||
required this.triggerAt,
|
||||
});
|
||||
|
||||
@override
|
||||
createState() => _CountdownTimerState();
|
||||
}
|
||||
|
||||
class _CountdownTimerState extends State<CountdownTimer>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController _controller;
|
||||
late Animation<double> _animation;
|
||||
bool _actionTriggered = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final now = DateTime.now();
|
||||
final countdown =
|
||||
widget.triggerAt.isBefore(now)
|
||||
? Duration()
|
||||
: widget.triggerAt.difference(now);
|
||||
|
||||
_controller = AnimationController(vsync: this, duration: countdown);
|
||||
|
||||
// Create animation to track progress from 5 to 0
|
||||
_animation = Tween<double>(
|
||||
begin: countdown.inSeconds.toDouble(),
|
||||
end: 0,
|
||||
).animate(_controller)..addStatusListener((status) {
|
||||
if (status == AnimationStatus.completed && !_actionTriggered) {
|
||||
setState(() {
|
||||
_actionTriggered = true;
|
||||
widget.onTrigger();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Start the countdown immediately when widget is mounted
|
||||
_controller.forward();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose(); // Clean up the controller
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: _animation,
|
||||
builder: (context, child) {
|
||||
final secondsLeft = _animation.value.ceil();
|
||||
return Text(secondsLeft.toString(), style: widget.style);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
263
lib/widgets/chat_write.dart
Normal file
263
lib/widgets/chat_write.dart
Normal file
@ -0,0 +1,263 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ndk/ndk.dart';
|
||||
import 'package:ndk/shared/nips/nip19/nip19.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/avatar.dart';
|
||||
import 'package:zap_stream_flutter/widgets/profile.dart';
|
||||
import 'package:zap_stream_flutter/widgets/reaction.dart';
|
||||
|
||||
class WriteMessageWidget extends StatefulWidget {
|
||||
final StreamEvent stream;
|
||||
|
||||
const WriteMessageWidget({super.key, required this.stream});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => __WriteMessageWidget();
|
||||
}
|
||||
|
||||
class __WriteMessageWidget extends State<WriteMessageWidget> {
|
||||
late final TextEditingController _controller;
|
||||
OverlayEntry? _entry;
|
||||
late FocusNode _focusNode;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_focusNode = FocusNode();
|
||||
_focusNode.addListener(() {
|
||||
if (!_focusNode.hasFocus && _entry != null) {
|
||||
_entry!.remove();
|
||||
_entry = null;
|
||||
}
|
||||
});
|
||||
_controller = TextEditingController();
|
||||
_controller.addListener(() {
|
||||
if (_controller.text.endsWith("@")) {
|
||||
// start auto-complete
|
||||
_showAutoComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (_entry != null) {
|
||||
_entry!.remove();
|
||||
}
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _showAutoComplete() {
|
||||
if (_entry != null) {
|
||||
_entry!.remove();
|
||||
_entry = null;
|
||||
}
|
||||
|
||||
final pos = context.findRenderObject() as RenderBox?;
|
||||
_entry = OverlayEntry(
|
||||
builder: (context) {
|
||||
return ValueListenableBuilder(
|
||||
valueListenable: _controller,
|
||||
builder: (context, v, _) {
|
||||
final selectionStart = v.text.lastIndexOf("@");
|
||||
if (selectionStart == -1) {
|
||||
_entry!.remove();
|
||||
_entry = null;
|
||||
return SizedBox();
|
||||
}
|
||||
final search = v.text.substring(selectionStart + 1, v.text.length);
|
||||
if (search.isEmpty) {
|
||||
return SizedBox();
|
||||
}
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned(
|
||||
left: 0,
|
||||
bottom: (pos?.paintBounds.bottom ?? 0),
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 4, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: LAYER_2,
|
||||
borderRadius: DEFAULT_BR,
|
||||
),
|
||||
child: FutureBuilder(
|
||||
future: ndkCache.searchMetadatas(search, 5),
|
||||
builder: (context, state) {
|
||||
if (state.data?.isEmpty ?? true) {
|
||||
return Text("No user found");
|
||||
}
|
||||
|
||||
return Column(
|
||||
spacing: 4,
|
||||
children:
|
||||
(state.data ?? [])
|
||||
.groupListsBy((m) => m.pubKey)
|
||||
.entries
|
||||
.map(
|
||||
(m) => GestureDetector(
|
||||
onTap: () {
|
||||
// replace search string with npub
|
||||
_controller
|
||||
.text = _controller.text.replaceRange(
|
||||
selectionStart,
|
||||
_controller.text.length,
|
||||
"nostr:${Nip19.encodePubKey(m.value.first.pubKey)}",
|
||||
);
|
||||
_entry!.remove();
|
||||
_entry = null;
|
||||
},
|
||||
child: Row(
|
||||
spacing: 4,
|
||||
children: [
|
||||
AvatarWidget(
|
||||
profile: m.value.first,
|
||||
size: 30,
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
ProfileNameWidget.nameFromProfile(
|
||||
m.value.first,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
Overlay.of(context).insert(_entry!);
|
||||
}
|
||||
|
||||
void _showEmojiPicker() {
|
||||
if (_entry != null) {
|
||||
_entry!.remove();
|
||||
_entry = null;
|
||||
}
|
||||
|
||||
final pos = context.findRenderObject() as RenderBox?;
|
||||
_entry = OverlayEntry(
|
||||
builder: (context) {
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned(
|
||||
left: 0,
|
||||
bottom: (pos?.paintBounds.bottom ?? 0),
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 4, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: LAYER_2,
|
||||
borderRadius: DEFAULT_BR,
|
||||
),
|
||||
child: EmojiPicker(
|
||||
onEmojiSelected: (category, emoji) {
|
||||
_controller.text = _controller.text + emoji.emoji;
|
||||
},
|
||||
config: emojiPickerConfig,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
Overlay.of(context).insert(_entry!);
|
||||
}
|
||||
|
||||
Future<void> _sendMessage(BuildContext context) async {
|
||||
final login = ndk.accounts.getLoggedAccount();
|
||||
if (login == null || _controller.text.isEmpty) return;
|
||||
|
||||
final chatMsg = Nip01Event(
|
||||
pubKey: login.pubkey,
|
||||
kind: 1311,
|
||||
content: _controller.text.toString(),
|
||||
tags: [
|
||||
["a", widget.stream.aTag],
|
||||
],
|
||||
);
|
||||
_controller.clear();
|
||||
_focusNode.unfocus();
|
||||
final res = ndk.broadcast.broadcast(nostrEvent: chatMsg);
|
||||
await res.broadcastDoneFuture;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final canSign = ndk.accounts.canSign;
|
||||
final isLogin = ndk.accounts.isLoggedIn;
|
||||
|
||||
return Container(
|
||||
margin: EdgeInsets.fromLTRB(4, 8, 4, 0),
|
||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
||||
decoration: BoxDecoration(color: LAYER_2, borderRadius: DEFAULT_BR),
|
||||
child:
|
||||
canSign
|
||||
? Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
maxLines: 3,
|
||||
minLines: 1,
|
||||
focusNode: _focusNode,
|
||||
controller: _controller,
|
||||
onSubmitted: (_) => _sendMessage(context),
|
||||
decoration: InputDecoration(
|
||||
labelText: "Write message",
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 4),
|
||||
labelStyle: TextStyle(color: LAYER_4, fontSize: 14),
|
||||
border: InputBorder.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
if (_entry != null) {
|
||||
_entry!.remove();
|
||||
_entry = null;
|
||||
} else {
|
||||
_showEmojiPicker();
|
||||
}
|
||||
},
|
||||
icon: Icon(Icons.mood),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
_sendMessage(context);
|
||||
},
|
||||
icon: Icon(Icons.send),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
isLogin
|
||||
? "Can't write messages with npub login"
|
||||
: "Please login to send messages",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
77
lib/widgets/chat_zap.dart
Normal file
77
lib/widgets/chat_zap.dart
Normal file
@ -0,0 +1,77 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ndk/ndk.dart';
|
||||
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/profile.dart';
|
||||
|
||||
class ChatZapWidget extends StatelessWidget {
|
||||
final StreamEvent stream;
|
||||
final Nip01Event zap;
|
||||
|
||||
const ChatZapWidget({required this.stream, required this.zap, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final parsed = ZapReceipt.fromEvent(zap);
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(vertical: 4),
|
||||
padding: EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: ZAP_1),
|
||||
borderRadius: DEFAULT_BR,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_zapperRowZap(parsed),
|
||||
if (parsed.comment?.isNotEmpty ?? false) Text(parsed.comment!),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _zapperRowZap(ZapReceipt parsed) {
|
||||
if (parsed.sender != null) {
|
||||
return ProfileLoaderWidget(parsed.sender!, (ctx, state) {
|
||||
final name = ProfileNameWidget.nameFromProfile(
|
||||
state.data ?? Metadata(pubKey: parsed.sender!),
|
||||
);
|
||||
return _zapperRow(name, parsed.amountSats ?? 0, state.data);
|
||||
});
|
||||
} else {
|
||||
return _zapperRow("Anon", parsed.amountSats ?? 0, null);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _zapperRow(String name, int amount, Metadata? profile) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(color: ZAP_1),
|
||||
children: [
|
||||
WidgetSpan(
|
||||
child: Icon(Icons.bolt, color: ZAP_1),
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
),
|
||||
if (profile != null)
|
||||
WidgetSpan(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(right: 8),
|
||||
child: AvatarWidget(profile: profile, size: 20),
|
||||
),
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
),
|
||||
TextSpan(text: name),
|
||||
TextSpan(text: " zapped ", style: TextStyle(color: FONT_COLOR)),
|
||||
TextSpan(text: formatSats(amount)),
|
||||
TextSpan(text: " sats", style: TextStyle(color: FONT_COLOR)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
39
lib/widgets/custom_emoji.dart
Normal file
39
lib/widgets/custom_emoji.dart
Normal file
@ -0,0 +1,39 @@
|
||||
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';
|
||||
|
||||
class CustomEmoji extends StatelessWidget {
|
||||
final List<List<String>> tags;
|
||||
final String emoji;
|
||||
final double? size;
|
||||
|
||||
const CustomEmoji({
|
||||
super.key,
|
||||
required this.tags,
|
||||
required this.emoji,
|
||||
this.size,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cleanedEmojiName =
|
||||
emoji.startsWith(":") && emoji.endsWith(":")
|
||||
? emoji.substring(1, emoji.length - 1)
|
||||
: emoji;
|
||||
|
||||
final customEmoji =
|
||||
tags.firstWhereOrNull(
|
||||
(t) => t[0] == "emoji" && t[1] == cleanedEmojiName,
|
||||
)?[2];
|
||||
if (customEmoji != null) {
|
||||
return CachedNetworkImage(
|
||||
imageUrl: proxyImg(context, customEmoji),
|
||||
height: size ?? 16,
|
||||
width: size ?? 16,
|
||||
);
|
||||
} else {
|
||||
return Text(emoji);
|
||||
}
|
||||
}
|
||||
}
|
25
lib/widgets/game_info.dart
Normal file
25
lib/widgets/game_info.dart
Normal file
@ -0,0 +1,25 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:zap_stream_flutter/theme.dart';
|
||||
import 'package:zap_stream_flutter/utils.dart';
|
||||
import 'package:zap_stream_flutter/widgets/pill.dart';
|
||||
|
||||
class GameInfoWidget extends StatelessWidget {
|
||||
final GameInfo info;
|
||||
|
||||
const GameInfoWidget({super.key, required this.info});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PillWidget(
|
||||
color: LAYER_2,
|
||||
onTap: () {
|
||||
context.push("/category/${Uri.encodeComponent(info.id)}", extra: info);
|
||||
},
|
||||
child: Text(
|
||||
info.name,
|
||||
style: TextStyle(color: PRIMARY_1, fontWeight: FontWeight.bold),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
105
lib/widgets/goal.dart
Normal file
105
lib/widgets/goal.dart
Normal file
@ -0,0 +1,105 @@
|
||||
import 'package:flutter/material.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';
|
||||
|
||||
class GoalWidget extends StatelessWidget {
|
||||
final Nip01Event goal;
|
||||
|
||||
const GoalWidget({super.key, required this.goal});
|
||||
|
||||
static Widget id(String id) {
|
||||
return RxFilter<Nip01Event>(
|
||||
Key("stream:goal:$id"),
|
||||
leaveOpen: false,
|
||||
filters: [
|
||||
Filter(kinds: [9041], ids: [id]),
|
||||
],
|
||||
builder: (ctx, state) {
|
||||
final goal = state?.firstOrNull;
|
||||
return goal != null ? GoalWidget(goal: goal) : SizedBox.shrink();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final max = int.parse(goal.getFirstTag("amount") ?? "1");
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 4, vertical: 4),
|
||||
child: RxFilter<Nip01Event>(
|
||||
Key("goal:$id:zaps"),
|
||||
filters: [
|
||||
Filter(kinds: [9735], eTags: [goal.id]),
|
||||
],
|
||||
builder: (ctx, state) {
|
||||
final zaps = (state ?? []).map((e) => ZapReceipt.fromEvent(e));
|
||||
final totalZaps =
|
||||
zaps.fold(0, (acc, v) => acc + (v.amountSats ?? 0)) * 1000;
|
||||
final progress = totalZaps / max;
|
||||
final remaining = ((max - totalZaps).clamp(0, max) / 1000).toInt();
|
||||
|
||||
final q = MediaQuery.of(ctx);
|
||||
return Column(
|
||||
spacing: 4,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: Text(goal.content)),
|
||||
if (remaining > 0)
|
||||
Text(
|
||||
"Remaining: ${formatSats(remaining)}",
|
||||
style: TextStyle(fontSize: 10, color: LAYER_5),
|
||||
),
|
||||
],
|
||||
),
|
||||
Stack(
|
||||
children: [
|
||||
Container(
|
||||
height: 10,
|
||||
decoration: BoxDecoration(
|
||||
color: LAYER_2,
|
||||
borderRadius: DEFAULT_BR,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
height: 10,
|
||||
width: (q.size.width * progress).clamp(1, q.size.width),
|
||||
decoration: BoxDecoration(
|
||||
color: ZAP_1,
|
||||
borderRadius: DEFAULT_BR,
|
||||
),
|
||||
),
|
||||
if (remaining > 0)
|
||||
Positioned(
|
||||
right: 2,
|
||||
child: Text(
|
||||
"Goal: ${formatSats((max / 1000).toInt())}",
|
||||
style: TextStyle(
|
||||
fontSize: 8,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (remaining == 0)
|
||||
Center(
|
||||
child: Text(
|
||||
"COMPLETE",
|
||||
style: TextStyle(
|
||||
color: LAYER_0,
|
||||
fontSize: 8,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -6,8 +6,17 @@ import 'package:zap_stream_flutter/widgets/button.dart';
|
||||
|
||||
class MuteButton extends StatelessWidget {
|
||||
final String pubkey;
|
||||
final void Function()? onTap;
|
||||
final void Function()? onMute;
|
||||
final void Function()? onUnmute;
|
||||
|
||||
const MuteButton({super.key, required this.pubkey});
|
||||
const MuteButton({
|
||||
super.key,
|
||||
required this.pubkey,
|
||||
this.onTap,
|
||||
this.onMute,
|
||||
this.onUnmute,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -30,8 +39,14 @@ class MuteButton extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 12),
|
||||
decoration: BoxDecoration(color: WARNING, borderRadius: DEFAULT_BR),
|
||||
decoration: BoxDecoration(
|
||||
color: isMuted ? LAYER_2 : WARNING,
|
||||
borderRadius: DEFAULT_BR,
|
||||
),
|
||||
onTap: () async {
|
||||
if (onTap != null) {
|
||||
onTap!();
|
||||
}
|
||||
if (isMuted) {
|
||||
await ndk.lists.broadcastRemoveNip51ListElement(
|
||||
Nip51List.kMute,
|
||||
@ -39,6 +54,9 @@ class MuteButton extends StatelessWidget {
|
||||
pubkey,
|
||||
null,
|
||||
);
|
||||
if (onUnmute != null) {
|
||||
onUnmute!();
|
||||
}
|
||||
} else {
|
||||
await ndk.lists.broadcastAddNip51ListElement(
|
||||
Nip51List.kMute,
|
||||
@ -46,9 +64,10 @@ class MuteButton extends StatelessWidget {
|
||||
pubkey,
|
||||
null,
|
||||
);
|
||||
}
|
||||
if (ctx.mounted) {
|
||||
Navigator.pop(ctx);
|
||||
|
||||
if (onMute != null) {
|
||||
onMute!();
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -6,8 +6,24 @@ import 'package:ndk/shared/nips/nip19/nip19.dart';
|
||||
import 'package:url_launcher/url_launcher.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/profile.dart';
|
||||
|
||||
class NoteText extends StatelessWidget {
|
||||
final Nip01Event event;
|
||||
|
||||
const NoteText({super.key, required this.event});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RichText(
|
||||
text: TextSpan(
|
||||
children: textToSpans(event.content, event.tags, event.pubKey),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a nostr note text containing links
|
||||
/// and mentions into multiple spans for rendering
|
||||
List<InlineSpan> textToSpans(
|
||||
@ -15,12 +31,12 @@ List<InlineSpan> textToSpans(
|
||||
List<List<String>> tags,
|
||||
String pubkey,
|
||||
) {
|
||||
return _buildContentSpans(content);
|
||||
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<InlineSpan> _buildContentSpans(String content, List<List<String>> tags) {
|
||||
List<InlineSpan> spans = [];
|
||||
RegExp exp = RegExp(
|
||||
r'nostr:(nprofile|npub)[a-zA-Z0-9]+|'
|
||||
@ -47,7 +63,23 @@ List<InlineSpan> _buildContentSpans(String content) {
|
||||
return '';
|
||||
},
|
||||
onNonMatch: (String text) {
|
||||
spans.add(TextSpan(text: text));
|
||||
final textTrim = text.trim();
|
||||
if (textTrim.startsWith(":") &&
|
||||
textTrim.endsWith(":") &&
|
||||
tags.any(
|
||||
(t) =>
|
||||
t[0] == "emoji" &&
|
||||
t[1] == textTrim.substring(1, textTrim.length - 1),
|
||||
)) {
|
||||
spans.add(
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: CustomEmoji(emoji: textTrim, tags: tags, size: 24),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
spans.add(TextSpan(text: text));
|
||||
}
|
||||
return '';
|
||||
},
|
||||
);
|
||||
|
@ -3,12 +3,18 @@ import 'package:flutter/material.dart';
|
||||
class PillWidget extends StatelessWidget {
|
||||
final Widget child;
|
||||
final Color? color;
|
||||
final void Function()? onTap;
|
||||
|
||||
const PillWidget({super.key, required this.child, required this.color});
|
||||
const PillWidget({
|
||||
super.key,
|
||||
required this.child,
|
||||
required this.color,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
final inner = Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.all(Radius.circular(8)),
|
||||
@ -16,5 +22,6 @@ class PillWidget extends StatelessWidget {
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
return onTap != null ? GestureDetector(onTap: onTap, child: inner) : inner;
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ class ProfileLoaderWidget extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder(
|
||||
key: super.key ?? Key("profile-loader:$pubkey"),
|
||||
future: ndk.metadata.loadMetadata(pubkey),
|
||||
builder: builder,
|
||||
);
|
||||
@ -26,18 +27,18 @@ class ProfileNameWidget extends StatelessWidget {
|
||||
|
||||
const ProfileNameWidget({super.key, required this.profile, this.style});
|
||||
|
||||
static Widget pubkey(String pubkey, {TextStyle? style}) {
|
||||
return FutureBuilder(
|
||||
future: ndk.metadata.loadMetadata(pubkey),
|
||||
builder:
|
||||
(ctx, data) => ProfileNameWidget(
|
||||
profile: data.data ?? Metadata(pubKey: pubkey),
|
||||
style: style,
|
||||
),
|
||||
static Widget pubkey(String pubkey, {Key? key, TextStyle? style}) {
|
||||
return ProfileLoaderWidget(
|
||||
pubkey,
|
||||
(ctx, data) => ProfileNameWidget(
|
||||
profile: data.data ?? Metadata(pubKey: pubkey),
|
||||
style: style,
|
||||
),
|
||||
key: key,
|
||||
);
|
||||
}
|
||||
|
||||
static nameFromProfile(Metadata profile) {
|
||||
static String nameFromProfile(Metadata profile) {
|
||||
if ((profile.displayName?.length ?? 0) > 0) {
|
||||
return profile.displayName!;
|
||||
}
|
||||
@ -84,6 +85,7 @@ class ProfileWidget extends StatelessWidget {
|
||||
List<Widget>? children,
|
||||
bool? showName,
|
||||
double? spacing,
|
||||
Key? key,
|
||||
}) {
|
||||
return ProfileLoaderWidget(pubkey, (ctx, state) {
|
||||
return ProfileWidget(
|
||||
@ -91,6 +93,7 @@ class ProfileWidget extends StatelessWidget {
|
||||
size: size,
|
||||
showName: showName,
|
||||
spacing: spacing,
|
||||
key: key,
|
||||
children: children,
|
||||
);
|
||||
});
|
||||
@ -102,7 +105,7 @@ class ProfileWidget extends StatelessWidget {
|
||||
spacing: spacing ?? 8,
|
||||
children: [
|
||||
AvatarWidget(profile: profile, size: size),
|
||||
if (showName ?? true) ProfileNameWidget(profile: profile),
|
||||
if (showName ?? true) ProfileNameWidget(profile: profile, key: key),
|
||||
...(children ?? []),
|
||||
],
|
||||
);
|
||||
|
@ -1,85 +0,0 @@
|
||||
import 'dart:developer' as developer;
|
||||
|
||||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/foundation.dart' as foundation;
|
||||
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/widgets/button.dart';
|
||||
import 'package:zap_stream_flutter/widgets/mute_button.dart';
|
||||
import 'package:zap_stream_flutter/widgets/profile.dart';
|
||||
import 'package:zap_stream_flutter/widgets/zap.dart';
|
||||
|
||||
class ProfileModalWidget extends StatelessWidget {
|
||||
final Metadata profile;
|
||||
final Nip01Event event;
|
||||
|
||||
const ProfileModalWidget({
|
||||
super.key,
|
||||
required this.profile,
|
||||
required this.event,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.fromLTRB(5, 10, 5, 0),
|
||||
child: Column(
|
||||
spacing: 10,
|
||||
children: [
|
||||
ProfileWidget(profile: profile),
|
||||
EmojiPicker(
|
||||
onEmojiSelected: (category, emoji) {
|
||||
developer.log(emoji.emoji);
|
||||
ndk.broadcast.broadcastReaction(
|
||||
eventId: event.id,
|
||||
reaction: emoji.emoji,
|
||||
);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
config: Config(
|
||||
height: 256,
|
||||
checkPlatformCompatibility: true,
|
||||
emojiViewConfig: EmojiViewConfig(
|
||||
emojiSizeMax:
|
||||
28 *
|
||||
(foundation.defaultTargetPlatform == TargetPlatform.iOS
|
||||
? 1.20
|
||||
: 1.0),
|
||||
backgroundColor: LAYER_1,
|
||||
),
|
||||
viewOrderConfig: const ViewOrderConfig(
|
||||
top: EmojiPickerItem.categoryBar,
|
||||
middle: EmojiPickerItem.emojiView,
|
||||
bottom: EmojiPickerItem.searchBar,
|
||||
),
|
||||
bottomActionBarConfig: BottomActionBarConfig(
|
||||
backgroundColor: LAYER_2,
|
||||
buttonColor: PRIMARY_1,
|
||||
),
|
||||
categoryViewConfig: CategoryViewConfig(backgroundColor: LAYER_2),
|
||||
searchViewConfig: SearchViewConfig(
|
||||
backgroundColor: LAYER_2,
|
||||
buttonIconColor: PRIMARY_1,
|
||||
),
|
||||
),
|
||||
),
|
||||
BasicButton.text(
|
||||
"Zap",
|
||||
onTap: () {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
constraints: BoxConstraints.expand(),
|
||||
builder: (ctx) {
|
||||
return ZapWidget(pubkey: event.pubKey, target: event);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
MuteButton(pubkey: event.pubKey),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
52
lib/widgets/reaction.dart
Normal file
52
lib/widgets/reaction.dart
Normal file
@ -0,0 +1,52 @@
|
||||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:flutter/foundation.dart' as foundation;
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:ndk/entities.dart';
|
||||
import 'package:zap_stream_flutter/main.dart';
|
||||
import 'package:zap_stream_flutter/theme.dart';
|
||||
|
||||
final emojiPickerConfig = Config(
|
||||
height: 256,
|
||||
checkPlatformCompatibility: true,
|
||||
emojiViewConfig: EmojiViewConfig(
|
||||
emojiSizeMax:
|
||||
28 *
|
||||
(foundation.defaultTargetPlatform == TargetPlatform.iOS ? 1.20 : 1.0),
|
||||
backgroundColor: LAYER_1,
|
||||
),
|
||||
viewOrderConfig: const ViewOrderConfig(
|
||||
top: EmojiPickerItem.categoryBar,
|
||||
middle: EmojiPickerItem.emojiView,
|
||||
bottom: EmojiPickerItem.searchBar,
|
||||
),
|
||||
bottomActionBarConfig: BottomActionBarConfig(
|
||||
backgroundColor: LAYER_2,
|
||||
buttonColor: PRIMARY_1,
|
||||
showBackspaceButton: false,
|
||||
),
|
||||
categoryViewConfig: CategoryViewConfig(backgroundColor: LAYER_2),
|
||||
searchViewConfig: SearchViewConfig(
|
||||
backgroundColor: LAYER_2,
|
||||
buttonIconColor: PRIMARY_1,
|
||||
),
|
||||
);
|
||||
|
||||
class ReactionWidget extends StatelessWidget {
|
||||
final Nip01Event event;
|
||||
|
||||
const ReactionWidget({super.key, required this.event});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return EmojiPicker(
|
||||
onEmojiSelected: (category, emoji) {
|
||||
ndk.broadcast.broadcastReaction(
|
||||
eventId: event.id,
|
||||
reaction: emoji.emoji,
|
||||
);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
config: emojiPickerConfig,
|
||||
);
|
||||
}
|
||||
}
|
103
lib/widgets/stream_cards.dart
Normal file
103
lib/widgets/stream_cards.dart
Normal file
@ -0,0 +1,103 @@
|
||||
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;
|
||||
|
||||
const StreamCardsWidget({super.key, required this.stream});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RxFilter<Nip01Event>(
|
||||
Key("stream:cards:${stream.aTag}"),
|
||||
filters: [
|
||||
Filter(kinds: [17_777], authors: [stream.info.host], limit: 1),
|
||||
],
|
||||
builder: (context, state) {
|
||||
final cardList = state?.firstOrNull;
|
||||
if (cardList == null) return SizedBox();
|
||||
|
||||
final cardIds = cardList.getTags("a");
|
||||
return RxFilter<Nip01Event>(
|
||||
Key("stream:cards:${stream.aTag}:cards"),
|
||||
filters: [
|
||||
Filter(
|
||||
kinds: [37_777],
|
||||
authors: [stream.info.host],
|
||||
dTags: cardIds.map((i) => i.split(":").last).toList(),
|
||||
),
|
||||
],
|
||||
builder: (context, state) {
|
||||
final cards = state ?? [];
|
||||
|
||||
return Column(
|
||||
spacing: 8,
|
||||
children: cards.map((c) => _streamCard(context, c)).toList(),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _streamCard(BuildContext context, Nip01Event card) {
|
||||
final title = card.getFirstTag("title") ?? card.getFirstTag("subject");
|
||||
final image = card.getFirstTag("image");
|
||||
final link = card.getFirstTag("r");
|
||||
|
||||
return Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
width: double.maxFinite,
|
||||
decoration: BoxDecoration(color: LAYER_2, borderRadius: DEFAULT_BR),
|
||||
child: Column(
|
||||
spacing: 8,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (title?.isNotEmpty ?? false)
|
||||
Center(
|
||||
child: Text(
|
||||
title!,
|
||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
if (image?.isNotEmpty ?? false)
|
||||
Center(
|
||||
child:
|
||||
link != null
|
||||
? GestureDetector(
|
||||
onTap: () {
|
||||
launchUrl(Uri.parse(link));
|
||||
},
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: proxyImg(context, image!),
|
||||
errorWidget:
|
||||
(_, _, _) => SvgPicture.asset(
|
||||
"assets/svg/logo.svg",
|
||||
height: 40,
|
||||
),
|
||||
),
|
||||
)
|
||||
: CachedNetworkImage(imageUrl: proxyImg(context, image!)),
|
||||
),
|
||||
MarkdownBody(
|
||||
data: card.content,
|
||||
onTapLink: (text, href, title) {
|
||||
if (href != null) {
|
||||
launchUrl(Uri.parse(href));
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -21,45 +21,74 @@ class StreamGrid extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final streams = events
|
||||
.map((e) => StreamEvent(e))
|
||||
.sortedBy((a) => a.info.starts ?? a.event.createdAt)
|
||||
.reversed;
|
||||
final streams =
|
||||
events
|
||||
.map((e) => StreamEvent(e))
|
||||
.where((e) => e.info.stream?.contains(".m3u8") ?? false)
|
||||
.where(
|
||||
(e) =>
|
||||
(e.info.starts ?? e.event.createdAt) <=
|
||||
(DateTime.now().millisecondsSinceEpoch / 1000),
|
||||
)
|
||||
.sortedBy((a) => a.info.starts ?? a.event.createdAt)
|
||||
.reversed;
|
||||
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("Live", live),
|
||||
if (showPlanned && planned.isNotEmpty) _streamGroup("Planned", planned),
|
||||
if (showEnded && ended.isNotEmpty) _streamGroup("Ended", ended),
|
||||
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()),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _streamGroup(String title, Iterable<StreamEvent> events) {
|
||||
Widget _streamTitle(String title) {
|
||||
return Row(
|
||||
spacing: 16,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(fontSize: 21, fontWeight: FontWeight.w500),
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
height: 1,
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: LAYER_2)),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _streamGroup(
|
||||
BuildContext context,
|
||||
String title,
|
||||
List<StreamEvent> events,
|
||||
) {
|
||||
return Column(
|
||||
spacing: 16,
|
||||
children: [
|
||||
Row(
|
||||
spacing: 16,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(fontSize: 21, fontWeight: FontWeight.w500),
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
height: 1,
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: LAYER_2)),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
_streamTitle(title),
|
||||
ListView.builder(
|
||||
itemCount: events.length,
|
||||
primary: false,
|
||||
shrinkWrap: true,
|
||||
itemBuilder: (ctx, idx) {
|
||||
final stream = events[idx];
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 8),
|
||||
child: StreamTileWidget(stream),
|
||||
);
|
||||
},
|
||||
),
|
||||
...events.map((e) => StreamTileWidget(e)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
87
lib/widgets/stream_info.dart
Normal file
87
lib/widgets/stream_info.dart
Normal file
@ -0,0 +1,87 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/intl.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/game_info.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/stream_cards.dart';
|
||||
|
||||
class StreamInfoWidget extends StatelessWidget {
|
||||
final StreamEvent stream;
|
||||
|
||||
const StreamInfoWidget({super.key, required this.stream});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final startedDate =
|
||||
stream.info.starts != null
|
||||
? DateTime.fromMillisecondsSinceEpoch(stream.info.starts! * 1000)
|
||||
: null;
|
||||
return Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Column(
|
||||
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)),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (stream.info.summary?.isNotEmpty ?? false)
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
children: textToSpans(
|
||||
stream.info.summary!,
|
||||
[],
|
||||
stream.info.host,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
if (stream.info.tags.isNotEmpty || stream.info.gameInfo != null)
|
||||
Row(
|
||||
spacing: 2,
|
||||
children: [
|
||||
if (stream.info.gameInfo != null)
|
||||
GameInfoWidget(info: stream.info.gameInfo!),
|
||||
...stream.info.tags.map(
|
||||
(t) => PillWidget(
|
||||
color: LAYER_2,
|
||||
onTap: () {
|
||||
context.push("/t/${Uri.encodeComponent(t)}");
|
||||
},
|
||||
child: Text(
|
||||
t,
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
StreamCardsWidget(stream: stream),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:ndk/shared/nips/nip19/nip19.dart';
|
||||
import 'package:zap_stream_flutter/imgproxy.dart';
|
||||
import 'package:zap_stream_flutter/theme.dart';
|
||||
import 'package:zap_stream_flutter/utils.dart';
|
||||
@ -19,10 +18,7 @@ class StreamTileWidget extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
context.push(
|
||||
"/e/${Nip19.encodeNoteId(stream.event.id)}",
|
||||
extra: stream,
|
||||
);
|
||||
context.push("/e/${stream.link}", extra: stream);
|
||||
},
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:clipboard/clipboard.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ndk/domain_layer/usecases/lnurl/lnurl.dart';
|
||||
import 'package:ndk/ndk.dart';
|
||||
@ -13,8 +14,16 @@ import 'package:zap_stream_flutter/widgets/profile.dart';
|
||||
class ZapWidget extends StatefulWidget {
|
||||
final String pubkey;
|
||||
final Nip01Event? target;
|
||||
final List<Nip01Event>? otherTargets;
|
||||
final List<List<String>>? zapTags;
|
||||
|
||||
const ZapWidget({super.key, required this.pubkey, this.target});
|
||||
const ZapWidget({
|
||||
super.key,
|
||||
required this.pubkey,
|
||||
this.target,
|
||||
this.zapTags,
|
||||
this.otherTargets,
|
||||
});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _ZapWidget();
|
||||
@ -84,6 +93,7 @@ class _ZapWidget extends State<ZapWidget> {
|
||||
),
|
||||
BasicButton.text(
|
||||
"Zap",
|
||||
decoration: BoxDecoration(color: LAYER_3, borderRadius: DEFAULT_BR),
|
||||
onTap: () {
|
||||
try {
|
||||
_loadZap();
|
||||
@ -132,29 +142,53 @@ class _ZapWidget extends State<ZapWidget> {
|
||||
];
|
||||
}
|
||||
|
||||
Future<ZapRequest?> _makeZap() async {
|
||||
final signer = ndk.accounts.getLoggedAccount()?.signer;
|
||||
if (signer == null) return null;
|
||||
|
||||
var relays = defaultRelays;
|
||||
// if target event has relays tag, use that for zap
|
||||
if (widget.target?.tags.any((t) => t[0] == "relays") ?? false) {
|
||||
relays = widget.target!.tags.firstWhere((t) => t[0] == "relays").slice(1);
|
||||
}
|
||||
final amount = _amount! * 1000;
|
||||
|
||||
var tags = [
|
||||
["relays", ...relays],
|
||||
["amount", amount.toString()],
|
||||
["p", widget.pubkey],
|
||||
];
|
||||
|
||||
// tag targets for zap request
|
||||
for (final t in [
|
||||
...(widget.target != null ? [widget.target!] : []),
|
||||
...(widget.otherTargets != null ? widget.otherTargets! : []),
|
||||
]) {
|
||||
if (t.kind >= 30_000 && t.kind < 40_000) {
|
||||
tags.add(["a", "${t.kind}:${t.pubKey}:${t.getDtag()!}"]);
|
||||
} else {
|
||||
tags.add(["e", t.id]);
|
||||
}
|
||||
}
|
||||
if (widget.zapTags != null) {
|
||||
tags.addAll(widget.zapTags!);
|
||||
}
|
||||
var event = ZapRequest(
|
||||
pubKey: signer.getPublicKey(),
|
||||
tags: tags,
|
||||
content: _comment.text,
|
||||
);
|
||||
await signer.sign(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
Future<void> _loadZap() async {
|
||||
final profile = await ndk.metadata.loadMetadata(widget.pubkey);
|
||||
if (profile?.lud16 == null) {
|
||||
throw "No lightning address found";
|
||||
}
|
||||
final signer = ndk.accounts.getLoggedAccount()?.signer;
|
||||
|
||||
final zapRequest =
|
||||
signer != null
|
||||
? await ndk.zaps.createZapRequest(
|
||||
amountSats: _amount!,
|
||||
signer: signer,
|
||||
pubKey: widget.pubkey,
|
||||
eventId: widget.target?.id,
|
||||
addressableId:
|
||||
widget.target != null && widget.target!.kind >= 30_000 && widget.target!.kind < 40_000
|
||||
? "${widget.target!.kind}:${widget.target!.pubKey}:${widget.target!.getDtag()!}"
|
||||
: null,
|
||||
relays: defaultRelays,
|
||||
comment: _comment.text.isNotEmpty ? _comment.text : null,
|
||||
)
|
||||
: null;
|
||||
|
||||
final zapRequest = await _makeZap();
|
||||
final invoice = await ndk.zaps.fetchInvoice(
|
||||
lud16Link: Lnurl.getLud16LinkFromLud16(profile!.lud16!)!,
|
||||
amountSats: _amount!,
|
||||
@ -174,7 +208,7 @@ class _ZapWidget extends State<ZapWidget> {
|
||||
}),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: n == _amount ? LAYER_2 : LAYER_1,
|
||||
color: n == _amount ? LAYER_4 : LAYER_3,
|
||||
borderRadius: DEFAULT_BR,
|
||||
),
|
||||
alignment: AlignmentDirectional.center,
|
||||
|
56
pubspec.lock
56
pubspec.lock
@ -294,6 +294,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.0.0"
|
||||
flutter_markdown_plus:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_markdown_plus
|
||||
sha256: fe74214c5ac2f850d93efda290dcde3f18006e90a87caa9e3e6c13222a5db4de
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.3"
|
||||
flutter_plugin_android_lifecycle:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -480,6 +488,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.2.1+1"
|
||||
intl:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: intl
|
||||
sha256: "3df61194eb431efc39c4ceba583b95633a403f46c9fd341e550ce0bfa50e9aa5"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.20.2"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -536,6 +552,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
markdown:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: markdown
|
||||
sha256: "935e23e1ff3bc02d390bad4d4be001208ee92cc217cb5b5a6c19bc14aaa318c1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "7.3.0"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -572,26 +596,28 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "packages/ndk"
|
||||
ref: bbf2aa9c2468b2301de65734199649d56bb0fd74
|
||||
resolved-ref: bbf2aa9c2468b2301de65734199649d56bb0fd74
|
||||
ref: "919f35866f4b9d84565f7f08ebbbcd5fd0ef0b6a"
|
||||
resolved-ref: "919f35866f4b9d84565f7f08ebbbcd5fd0ef0b6a"
|
||||
url: "https://github.com/relaystr/ndk"
|
||||
source: git
|
||||
version: "0.3.2"
|
||||
ndk_amber:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: ndk_amber
|
||||
sha256: "6f525e2bcdea08ecdd1815e2fdfc6e53c4bb86335927d8c333c1f4513dc1c099"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
path: "packages/amber"
|
||||
ref: "919f35866f4b9d84565f7f08ebbbcd5fd0ef0b6a"
|
||||
resolved-ref: "919f35866f4b9d84565f7f08ebbbcd5fd0ef0b6a"
|
||||
url: "https://github.com/relaystr/ndk"
|
||||
source: git
|
||||
version: "0.3.0"
|
||||
ndk_objectbox:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: ndk_objectbox
|
||||
sha256: f2bd04299ed34b99a01957c46eb6ff495c0bdcde068d382cbb8b8a222f67e132
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
path: "packages/objectbox"
|
||||
ref: "919f35866f4b9d84565f7f08ebbbcd5fd0ef0b6a"
|
||||
resolved-ref: "919f35866f4b9d84565f7f08ebbbcd5fd0ef0b6a"
|
||||
url: "https://github.com/relaystr/ndk"
|
||||
source: git
|
||||
version: "0.2.3"
|
||||
ndk_rust_verifier:
|
||||
dependency: "direct main"
|
||||
@ -1190,6 +1216,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.5.0"
|
||||
xxh3:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: xxh3
|
||||
sha256: "399a0438f5d426785723c99da6b16e136f4953fb1e9db0bf270bd41dd4619916"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
sdks:
|
||||
dart: ">=3.7.2 <4.0.0"
|
||||
flutter: ">=3.27.0"
|
||||
flutter: ">=3.27.1"
|
||||
|
19
pubspec.yaml
19
pubspec.yaml
@ -1,7 +1,7 @@
|
||||
name: zap_stream_flutter
|
||||
description: "zap.stream"
|
||||
publish_to: 'none'
|
||||
version: 0.2.2+4
|
||||
version: 0.5.0+7
|
||||
|
||||
environment:
|
||||
sdk: ^3.7.2
|
||||
@ -31,13 +31,25 @@ dependencies:
|
||||
image_picker: ^1.1.2
|
||||
emoji_picker_flutter: ^4.3.0
|
||||
bech32: ^0.2.2
|
||||
intl: ^0.20.2
|
||||
flutter_markdown_plus: ^1.0.3
|
||||
|
||||
dependency_overrides:
|
||||
ndk:
|
||||
git:
|
||||
url: https://github.com/relaystr/ndk
|
||||
path: packages/ndk
|
||||
ref: bbf2aa9c2468b2301de65734199649d56bb0fd74
|
||||
ref: 919f35866f4b9d84565f7f08ebbbcd5fd0ef0b6a
|
||||
ndk_objectbox:
|
||||
git:
|
||||
url: https://github.com/relaystr/ndk
|
||||
path: packages/objectbox
|
||||
ref: 919f35866f4b9d84565f7f08ebbbcd5fd0ef0b6a
|
||||
ndk_amber:
|
||||
git:
|
||||
url: https://github.com/relaystr/ndk
|
||||
path: packages/amber
|
||||
ref: 919f35866f4b9d84565f7f08ebbbcd5fd0ef0b6a
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
@ -48,4 +60,5 @@ flutter:
|
||||
uses-material-design: true
|
||||
assets:
|
||||
- "assets/svg/"
|
||||
- "assets/logo.png"
|
||||
- "assets/logo.png"
|
||||
- "assets/category/"
|
Reference in New Issue
Block a user