Better replies

This commit is contained in:
Christian Pauly 2020-02-11 12:49:39 +01:00
commit cf2b2f0433
6 changed files with 92 additions and 56 deletions

View file

@ -1,6 +1,7 @@
import 'package:bubble/bubble.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/message_content.dart';
import 'package:fluffychat/components/reply_content.dart';
import 'package:fluffychat/i18n/i18n.dart';
import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/utils/date_time_extension.dart';
@ -18,9 +19,14 @@ class Message extends StatelessWidget {
final Function(Event) onSelect;
final bool longPressSelect;
final bool selected;
final Timeline timeline;
const Message(this.event,
{this.nextEvent, this.longPressSelect, this.onSelect, this.selected});
{this.nextEvent,
this.longPressSelect,
this.onSelect,
this.selected,
this.timeline});
@override
Widget build(BuildContext context) {
@ -88,6 +94,30 @@ class Message extends StatelessWidget {
),
],
),
if (event.isReply)
FutureBuilder<Event>(
future: timeline.getEventById(event.content['m.relates_to']
['m.in_reply_to']['event_id']),
builder: (BuildContext context, snapshot) {
final Event replyEvent = snapshot.hasData
? snapshot.data
: Event(
eventId: event.content['m.relates_to']
['m.in_reply_to']['event_id'],
content: {"msgtype": "m.text", "body": "..."},
senderId: event.senderId,
typeKey: "m.room.message",
room: event.room,
roomId: event.roomId,
status: 1,
time: DateTime.now(),
);
return Container(
margin: EdgeInsets.symmetric(vertical: 4.0),
child: ReplyContent(replyEvent, lightText: ownMessage),
);
},
),
MessageContent(
event,
textColor: textColor,

View file

@ -130,7 +130,7 @@ class MessageContent extends StatelessWidget {
case MessageTypes.Notice:
case MessageTypes.Emote:
return LinkText(
text: event.getLocalizedBody(context),
text: event.getLocalizedBody(context, hideQuotes: true),
textStyle: TextStyle(
color: textColor,
decoration: event.redacted ? TextDecoration.lineThrough : null,

View file

@ -0,0 +1,52 @@
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/event_extension.dart';
import 'package:flutter/material.dart';
class ReplyContent extends StatelessWidget {
final Event replyEvent;
final bool lightText;
const ReplyContent(this.replyEvent, {this.lightText = false, Key key})
: super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: <Widget>[
Container(
width: 3,
height: 36,
color: lightText ? Colors.white : Theme.of(context).primaryColor,
),
SizedBox(width: 6),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
(replyEvent?.sender?.calcDisplayname() ?? "") + ":",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.bold,
color:
lightText ? Colors.white : Theme.of(context).primaryColor,
),
),
Text(
replyEvent?.getLocalizedBody(context,
withSenderNamePrefix: false) ??
"",
overflow: TextOverflow.ellipsis,
maxLines: 1,
style:
TextStyle(color: lightText ? Colors.white : Colors.black),
),
],
),
),
],
);
}
}