fluffychat/lib/pages/chat/events/reply_content.dart

110 lines
3.6 KiB
Dart
Raw Normal View History

2020-02-11 11:49:39 +00:00
import 'package:flutter/material.dart';
2021-10-26 16:50:34 +00:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
2021-10-26 16:50:34 +00:00
import 'package:matrix/matrix.dart';
2020-02-11 11:49:39 +00:00
2022-12-30 16:54:01 +00:00
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
2021-11-09 20:32:16 +00:00
import '../../../config/app_config.dart';
2021-10-26 16:50:34 +00:00
import 'html_message.dart';
2020-05-09 11:36:41 +00:00
2020-02-11 11:49:39 +00:00
class ReplyContent extends StatelessWidget {
final Event replyEvent;
2022-05-27 13:13:24 +00:00
final bool ownMessage;
2022-01-29 11:35:03 +00:00
final Timeline? timeline;
2020-02-11 11:49:39 +00:00
2022-01-29 11:35:03 +00:00
const ReplyContent(
this.replyEvent, {
2022-05-27 13:13:24 +00:00
this.ownMessage = false,
2022-01-29 11:35:03 +00:00
Key? key,
this.timeline,
}) : super(key: key);
2020-02-11 11:49:39 +00:00
@override
Widget build(BuildContext context) {
2020-05-09 11:36:41 +00:00
Widget replyBody;
2022-01-29 11:35:03 +00:00
final timeline = this.timeline;
final displayEvent =
timeline != null ? replyEvent.getDisplayEvent(timeline) : replyEvent;
2021-11-13 12:06:36 +00:00
final fontSize = AppConfig.messageFontSize * AppConfig.fontSizeFactor;
2022-01-29 11:35:03 +00:00
if (AppConfig.renderHtml &&
[EventTypes.Message, EventTypes.Encrypted]
.contains(displayEvent.type) &&
2020-05-13 13:58:59 +00:00
[MessageTypes.Text, MessageTypes.Notice, MessageTypes.Emote]
.contains(displayEvent.messageType) &&
!displayEvent.redacted &&
displayEvent.content['format'] == 'org.matrix.custom.html' &&
displayEvent.content['formatted_body'] is String) {
2022-01-29 11:35:03 +00:00
String? html = displayEvent.content['formatted_body'];
if (displayEvent.messageType == MessageTypes.Emote) {
2020-05-13 13:58:59 +00:00
html = '* $html';
2020-05-09 11:36:41 +00:00
}
replyBody = HtmlMessage(
2022-01-29 11:35:03 +00:00
html: html!,
2020-05-15 05:47:32 +00:00
defaultTextStyle: TextStyle(
2022-05-27 13:13:24 +00:00
color: ownMessage
? Theme.of(context).colorScheme.onPrimary
: Theme.of(context).colorScheme.onBackground,
fontSize: fontSize,
2020-05-15 05:47:32 +00:00
),
2020-05-09 11:36:41 +00:00
maxLines: 1,
room: displayEvent.room,
emoteSize: fontSize * 1.5,
2020-05-09 11:36:41 +00:00
);
} else {
replyBody = Text(
displayEvent.calcLocalizedBodyFallback(
2022-01-29 11:35:03 +00:00
MatrixLocals(L10n.of(context)!),
withSenderNamePrefix: false,
hideReply: true,
),
2020-05-09 11:36:41 +00:00
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: TextStyle(
2022-05-27 13:13:24 +00:00
color: ownMessage
? Theme.of(context).colorScheme.onPrimary
: Theme.of(context).colorScheme.onBackground,
fontSize: fontSize,
2020-05-15 05:47:32 +00:00
),
2020-05-09 11:36:41 +00:00
);
}
2020-02-11 11:49:39 +00:00
return Row(
2020-05-14 05:43:21 +00:00
mainAxisSize: MainAxisSize.min,
2020-02-11 11:49:39 +00:00
children: <Widget>[
Container(
width: 3,
height: fontSize * 2 + 6,
2022-05-27 13:13:24 +00:00
color: ownMessage
? Theme.of(context).colorScheme.onPrimary
: Theme.of(context).colorScheme.onBackground,
2020-02-11 11:49:39 +00:00
),
2021-10-14 16:09:30 +00:00
const SizedBox(width: 6),
2020-05-14 05:43:21 +00:00
Flexible(
2020-02-11 11:49:39 +00:00
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FutureBuilder<User?>(
future: displayEvent.fetchSenderUser(),
builder: (context, snapshot) {
return Text(
2022-08-14 14:59:21 +00:00
'${snapshot.data?.calcDisplayname() ?? displayEvent.senderFromMemoryOrFallback.calcDisplayname()}:',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.bold,
color: ownMessage
? Theme.of(context).colorScheme.onPrimary
: Theme.of(context).colorScheme.onBackground,
fontSize: fontSize,
),
);
}),
2020-05-09 11:36:41 +00:00
replyBody,
2020-02-11 11:49:39 +00:00
],
),
),
],
);
}
}