Fix message types and update to newest sdk

This commit is contained in:
Christian Pauly 2020-01-04 12:53:49 +00:00 committed by Marcel
commit fda9b752df
8 changed files with 149 additions and 132 deletions

View file

@ -3,7 +3,6 @@ import 'package:cached_network_image/cached_network_image.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:link_text/link_text.dart';
import 'package:url_launcher/url_launcher.dart';
import 'matrix.dart';
@ -19,102 +18,112 @@ class MessageContent extends StatelessWidget {
Widget build(BuildContext context) {
final int maxLines = textOnly ? 1 : null;
final Widget unknown = Text(
"${event.sender.calcDisplayname()} sent a ${event.typeKey} event",
maxLines: maxLines,
overflow: textOnly ? TextOverflow.ellipsis : null,
style: TextStyle(
color: textColor,
decoration: event.redacted ? TextDecoration.lineThrough : null,
),
);
switch (event.type) {
case EventTypes.Image:
if (textOnly) {
return Text(
"${event.sender.calcDisplayname()} has sent an image",
maxLines: maxLines,
style: TextStyle(
color: textColor,
decoration: event.redacted ? TextDecoration.lineThrough : null,
),
);
case EventTypes.Message:
case EventTypes.Sticker:
switch (event.messageType) {
case MessageTypes.Image:
case MessageTypes.Sticker:
if (textOnly) {
return Text(
"${event.sender.calcDisplayname()} has sent an image",
maxLines: maxLines,
style: TextStyle(
color: textColor,
decoration:
event.redacted ? TextDecoration.lineThrough : null,
),
);
}
final int size = 400;
final String src = MxContent(event.content["url"]).getThumbnail(
Matrix.of(context).client,
width: size * MediaQuery.of(context).devicePixelRatio,
height: size * MediaQuery.of(context).devicePixelRatio,
method: ThumbnailMethod.scale,
);
return Bubble(
padding: BubbleEdges.all(0),
radius: Radius.circular(10),
elevation: 0,
child: InkWell(
onTap: () => launch(
MxContent(event.content["url"])
.getDownloadLink(Matrix.of(context).client),
),
child: kIsWeb
? Image.network(
src,
width: size.toDouble(),
)
: CachedNetworkImage(
imageUrl: src,
width: size.toDouble(),
),
),
);
case MessageTypes.Audio:
case MessageTypes.File:
case MessageTypes.Video:
return Container(
width: 200,
child: RaisedButton(
color: Colors.blueGrey,
child: Text(
"Download ${event.getBody()}",
overflow: TextOverflow.fade,
softWrap: false,
maxLines: 1,
),
onPressed: () => launch(
MxContent(event.content["url"])
.getDownloadLink(Matrix.of(context).client),
),
),
);
case MessageTypes.Text:
case MessageTypes.Reply:
case MessageTypes.Location:
case MessageTypes.None:
case MessageTypes.Notice:
final String senderPrefix =
textOnly && event.senderId != event.room.directChatMatrixID
? event.senderId == Matrix.of(context).client.userID
? "You: "
: "${event.sender.calcDisplayname()}: "
: "";
return Text(
senderPrefix + event.getBody(),
maxLines: maxLines,
overflow: textOnly ? TextOverflow.ellipsis : null,
style: TextStyle(
color: textColor,
decoration: event.redacted ? TextDecoration.lineThrough : null,
),
);
case MessageTypes.Emote:
return Text(
"* " + event.getBody(),
maxLines: maxLines,
overflow: textOnly ? TextOverflow.ellipsis : null,
style: TextStyle(
color: textColor,
fontStyle: FontStyle.italic,
decoration: event.redacted ? TextDecoration.lineThrough : null,
),
);
}
final int size = 400;
final String src = MxContent(event.content["url"]).getThumbnail(
Matrix.of(context).client,
width: size * MediaQuery.of(context).devicePixelRatio,
height: size * MediaQuery.of(context).devicePixelRatio,
method: ThumbnailMethod.scale,
);
return Bubble(
padding: BubbleEdges.all(0),
radius: Radius.circular(10),
elevation: 0,
child: InkWell(
onTap: () => launch(
MxContent(event.content["url"])
.getDownloadLink(Matrix.of(context).client),
),
child: kIsWeb
? Image.network(
src,
width: size.toDouble(),
)
: CachedNetworkImage(
imageUrl: src,
width: size.toDouble(),
),
),
);
case EventTypes.Audio:
case EventTypes.File:
case EventTypes.Video:
return Container(
width: 200,
child: RaisedButton(
color: Colors.blueGrey,
child: Text(
"Download ${event.getBody()}",
overflow: TextOverflow.fade,
softWrap: false,
maxLines: 1,
),
onPressed: () => launch(
MxContent(event.content["url"])
.getDownloadLink(Matrix.of(context).client),
),
),
);
case EventTypes.Text:
case EventTypes.Reply:
case EventTypes.Notice:
final String senderPrefix =
textOnly && event.senderId != event.room.directChatMatrixID
? event.senderId == Matrix.of(context).client.userID
? "You: "
: "${event.sender.calcDisplayname()}: "
: "";
if (textOnly) {
return Text(
senderPrefix + event.getBody(),
maxLines: maxLines,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: textColor,
decoration: event.redacted ? TextDecoration.lineThrough : null,
),
);
}
return LinkText(
text: senderPrefix + event.getBody(),
textStyle: TextStyle(
color: textColor,
decoration: event.redacted ? TextDecoration.lineThrough : null,
),
);
case EventTypes.Emote:
return Text(
"* " + event.getBody(),
maxLines: maxLines,
overflow: textOnly ? TextOverflow.ellipsis : null,
style: TextStyle(
color: textColor,
fontStyle: FontStyle.italic,
decoration: event.redacted ? TextDecoration.lineThrough : null,
),
);
return unknown;
case EventTypes.RoomCreate:
return Text(
"${event.sender.calcDisplayname()} has created the chat",
@ -272,15 +281,7 @@ class MessageContent extends StatelessWidget {
),
);
default:
return Text(
"${event.sender.calcDisplayname()} sent a ${event.typeKey} event",
maxLines: maxLines,
overflow: textOnly ? TextOverflow.ellipsis : null,
style: TextStyle(
color: textColor,
decoration: event.redacted ? TextDecoration.lineThrough : null,
),
);
return unknown;
}
}
}