mirror of
https://github.com/nostrlabs-io/zap-stream-flutter.git
synced 2025-06-16 20:08:50 +00:00
@ -1,6 +1,9 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:duration/duration.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:ndk/ndk.dart';
|
||||
import 'package:zap_stream_flutter/i18n/strings.g.dart';
|
||||
import 'package:zap_stream_flutter/main.dart';
|
||||
import 'package:zap_stream_flutter/theme.dart';
|
||||
import 'package:zap_stream_flutter/widgets/profile.dart';
|
||||
|
||||
@ -11,32 +14,43 @@ class ChatTimeoutWidget extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final pTags = timeout.pTags;
|
||||
final duration =
|
||||
double.parse(timeout.getFirstTag("expiration")!) - timeout.createdAt;
|
||||
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 2, vertical: 4),
|
||||
child: RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(color: LAYER_5),
|
||||
children: [
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: ProfileNameWidget.pubkey(timeout.pubKey),
|
||||
),
|
||||
TextSpan(text: " timed out "),
|
||||
...pTags.map(
|
||||
(p) => WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: ProfileNameWidget.pubkey(p),
|
||||
child: FutureBuilder(
|
||||
future: ndk.metadata.loadMetadatas([
|
||||
timeout.pubKey,
|
||||
...timeout.pTags,
|
||||
], null),
|
||||
builder: (context, state) {
|
||||
final modProfile =
|
||||
state.data?.firstWhereOrNull((p) => p.pubKey == timeout.pubKey) ??
|
||||
Metadata(pubKey: timeout.pubKey);
|
||||
final userProfiles = timeout.pTags.map(
|
||||
(p) =>
|
||||
state.data?.firstWhereOrNull((x) => x.pubKey == p) ??
|
||||
Metadata(pubKey: p),
|
||||
);
|
||||
|
||||
return Text.rich(
|
||||
style: TextStyle(color: LAYER_5),
|
||||
t.stream.chat.timeout(
|
||||
mod: TextSpan(
|
||||
text: ProfileNameWidget.nameFromProfile(modProfile),
|
||||
),
|
||||
user: TextSpan(
|
||||
text: userProfiles
|
||||
.map((p) => ProfileNameWidget.nameFromProfile(p))
|
||||
.join(", "),
|
||||
),
|
||||
time: TextSpan(
|
||||
text: Duration(seconds: duration.floor()).pretty(),
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
text: " for ${Duration(seconds: duration.toInt()).pretty()}",
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user