You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fluffychat/lib/components/reply_content.dart

100 lines
3.1 KiB
Dart

5 years ago
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/matrix_locals.dart';
5 years ago
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
5 years ago
5 years ago
import 'html_message.dart';
import '../app_config.dart';
5 years ago
5 years ago
class ReplyContent extends StatelessWidget {
final Event replyEvent;
final bool lightText;
final Timeline timeline;
5 years ago
const ReplyContent(this.replyEvent,
{this.lightText = false, Key key, this.timeline})
5 years ago
: super(key: key);
@override
Widget build(BuildContext context) {
5 years ago
Widget replyBody;
final displayEvent = replyEvent != null && timeline != null
? replyEvent.getDisplayEvent(timeline)
: replyEvent;
if (displayEvent != null &&
AppConfig.renderHtml &&
[EventTypes.Message, EventTypes.Encrypted]
.contains(displayEvent.type) &&
5 years ago
[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) {
5 years ago
html = '* $html';
5 years ago
}
final fontSize = DefaultTextStyle.of(context).style.fontSize;
5 years ago
replyBody = HtmlMessage(
html: html,
defaultTextStyle: TextStyle(
color: lightText
? Colors.white
: Theme.of(context).textTheme.bodyText2.color,
fontSize: fontSize,
),
5 years ago
maxLines: 1,
room: displayEvent.room,
emoteSize: fontSize * 1.5,
5 years ago
);
} else {
replyBody = Text(
displayEvent?.getLocalizedBody(
MatrixLocals(L10n.of(context)),
5 years ago
withSenderNamePrefix: false,
hideReply: true,
) ??
5 years ago
'',
5 years ago
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: TextStyle(
color: lightText
? Colors.white
: Theme.of(context).textTheme.bodyText2.color,
fontSize: DefaultTextStyle.of(context).style.fontSize,
),
5 years ago
);
}
5 years ago
return Row(
5 years ago
mainAxisSize: MainAxisSize.min,
5 years ago
children: <Widget>[
Container(
width: 3,
height: 36,
color: lightText ? Colors.white : Theme.of(context).primaryColor,
),
SizedBox(width: 6),
5 years ago
Flexible(
5 years ago
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
(displayEvent?.sender?.calcDisplayname() ?? '') + ':',
5 years ago
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.bold,
color:
lightText ? Colors.white : Theme.of(context).primaryColor,
),
),
5 years ago
replyBody,
5 years ago
],
),
),
],
);
}
}