FurryChat/lib/components/reply_content.dart

98 lines
3.0 KiB
Dart
Raw Normal View History

2020-02-11 11:49:39 +00:00
import 'package:famedlysdk/famedlysdk.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
2020-02-11 11:49:39 +00:00
2020-10-15 13:51:24 +00:00
import '../utils/matrix_locals.dart';
2020-05-09 11:36:41 +00:00
import 'html_message.dart';
import 'matrix.dart';
2020-02-11 11:49:39 +00:00
class ReplyContent extends StatelessWidget {
final Event replyEvent;
final bool lightText;
final Timeline timeline;
2020-02-11 11:49:39 +00:00
const ReplyContent(this.replyEvent,
{this.lightText = false, Key key, this.timeline})
2020-02-11 11:49:39 +00:00
: super(key: key);
@override
Widget build(BuildContext context) {
2020-05-09 11:36:41 +00:00
Widget replyBody;
final displayEvent = replyEvent != null && timeline != null
? replyEvent.getDisplayEvent(timeline)
: replyEvent;
if (displayEvent != null &&
2020-05-13 13:58:59 +00:00
Matrix.of(context).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) {
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(
html: html,
2020-05-15 05:47:32 +00:00
defaultTextStyle: TextStyle(
color: lightText
2020-05-22 10:21:16 +00:00
? Colors.white
: Theme.of(context).textTheme.bodyText2.color,
2020-05-15 05:47:32 +00:00
fontSize: DefaultTextStyle.of(context).style.fontSize,
),
2020-05-09 11:36:41 +00:00
maxLines: 1,
room: displayEvent.room,
2020-05-09 11:36:41 +00:00
);
} else {
replyBody = Text(
displayEvent?.getLocalizedBody(
MatrixLocals(L10n.of(context)),
2020-05-09 11:36:41 +00:00
withSenderNamePrefix: false,
hideReply: true,
) ??
2020-05-13 13:58:59 +00:00
'',
2020-05-09 11:36:41 +00:00
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: TextStyle(
2020-05-15 05:47:32 +00:00
color: lightText
2020-05-22 10:21:16 +00:00
? Colors.white
: Theme.of(context).textTheme.bodyText2.color,
2020-05-15 05:47:32 +00:00
fontSize: DefaultTextStyle.of(context).style.fontSize,
),
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: 36,
color: lightText ? Colors.white : Theme.of(context).primaryColor,
),
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>[
Text(
(displayEvent?.sender?.calcDisplayname() ?? '') + ':',
2020-02-11 11:49:39 +00:00
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.bold,
color:
lightText ? Colors.white : Theme.of(context).primaryColor,
),
),
2020-05-09 11:36:41 +00:00
replyBody,
2020-02-11 11:49:39 +00:00
],
),
),
],
);
}
}