feat: chat mute

closes #7
This commit is contained in:
2025-05-12 11:53:55 +01:00
parent 194bff315c
commit a5aa8c5fa7

View File

@ -17,16 +17,48 @@ class ChatWidget extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final hostMuteList = ndk.lists.getSingleNip51List(
Nip51List.kMute,
Bip340EventSigner(privateKey: null, publicKey: stream.info.host),
forceRefresh: true,
);
final signer = ndk.accounts.getLoggedAccount()?.signer;
final myMuteList =
signer != null
? ndk.lists.getSingleNip51List(
Nip51List.kMute,
signer,
forceRefresh: true,
)
: Future.value(null);
return RxFilter<Nip01Event>( return RxFilter<Nip01Event>(
filters: [ filters: [
Filter(kinds: [1311, 9735], limit: 200, aTags: [stream.aTag]), Filter(kinds: [1311, 9735], limit: 200, aTags: [stream.aTag]),
], ],
builder: (ctx, state) { builder: (ctx, state) {
return FutureBuilder(
future: Future.wait([hostMuteList, myMuteList]),
builder: (ctx, muteState) {
final mutedPubkeys =
muteState.data
?.map((e) => e?.pubKeys)
.where((e) => e != null)
.expand((e) => e!)
.map((e) => e.value)
.toSet() ??
<String>{};
final filteredChat =
(state ?? [])
.where((e) => !mutedPubkeys.contains(e.pubKey))
.toList();
return Column( return Column(
spacing: 8, spacing: 8,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
_TopZappersWidget(events: state ?? []), _TopZappersWidget(events: filteredChat),
Expanded( Expanded(
child: SingleChildScrollView( child: SingleChildScrollView(
reverse: true, reverse: true,
@ -34,12 +66,18 @@ class ChatWidget extends StatelessWidget {
spacing: 8, spacing: 8,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: children:
(state ?? []) filteredChat
.sortedBy((c) => c.createdAt) .sortedBy((c) => c.createdAt)
.map( .map(
(c) => switch (c.kind) { (c) => switch (c.kind) {
1311 => ChatMessageWidget(stream: stream, msg: c), 1311 => ChatMessageWidget(
9735 => _ChatZapWidget(stream: stream, zap: c), stream: stream,
msg: c,
),
9735 => _ChatZapWidget(
stream: stream,
zap: c,
),
_ => SizedBox.shrink(), _ => SizedBox.shrink(),
}, },
) )
@ -65,6 +103,8 @@ class ChatWidget extends StatelessWidget {
); );
}, },
); );
},
);
} }
} }