simplified code across the app and consolidated duplicated helpers

This commit is contained in:
2026-09-27 17:29:54 +02:00
parent 3e856d0b1c
commit ee1240f71a
155 changed files with 1772 additions and 2546 deletions
+28 -37
View File
@@ -105,9 +105,7 @@ class _ChatTextfieldState extends State<ChatTextfield> {
if (messageId != null) {
talkSettings.draftReplies[widget.sendToToken] = messageId;
} else {
talkSettings.draftReplies.removeWhere(
(key, _) => key == widget.sendToToken,
);
talkSettings.draftReplies.remove(widget.sendToToken);
}
}
@@ -285,43 +283,36 @@ class _ChatTextfieldState extends State<ChatTextfield> {
@override
Widget build(BuildContext context) {
final chatBloc = context.read<ChatBloc>();
// Only the reply reference is rendered from the chat state; loading flags
// and paging emits don't need to rebuild the input.
final (referenceMessageId, chatResponse) = context.select(
(ChatBloc b) => (
b.state.data?.referenceMessageId,
b.state.data?.chatResponse,
),
);
// Only the resolved reply reference is rendered from the chat state;
// incoming messages, loading flags and paging emits don't rebuild the input.
final referenceMessage = context.select((ChatBloc b) {
final data = b.state.data;
final id = data?.referenceMessageId;
if (id == null) return null;
return data!.chatResponse?.data.where((e) => e.id == id).firstOrNull;
});
Widget replyBanner = const SizedBox.shrink();
if (referenceMessageId != null && chatResponse != null) {
try {
final referenceMessage = chatResponse.data.firstWhere(
(e) => e.id == referenceMessageId,
);
replyBanner = Row(
children: [
Expanded(
child: AnswerReference(
referenceMessage: referenceMessage,
selfId: widget.selfId,
),
if (referenceMessage != null) {
replyBanner = Row(
children: [
Expanded(
child: AnswerReference(
referenceMessage: referenceMessage,
selfId: widget.selfId,
),
IconButton(
tooltip: 'Antwort verwerfen',
onPressed: () {
chatBloc.setReferenceMessageId(null);
_setDraftReply(null);
},
icon: const Icon(Icons.close_outlined),
padding: const EdgeInsets.only(left: 0),
),
],
);
} catch (_) {
/* reference no longer in current chat data */
}
),
IconButton(
tooltip: 'Antwort verwerfen',
onPressed: () {
chatBloc.setReferenceMessageId(null);
_setDraftReply(null);
},
icon: const Icon(Icons.close_outlined),
padding: const EdgeInsets.only(left: 0),
),
],
);
}
WidgetsBinding.instance.addPostFrameCallback((_) => _publishHeight());