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