Merge branch 'soru/pills' into 'master'

add pill support

See merge request ChristianPauly/fluffychat-flutter!51
This commit is contained in:
Christian Pauly 2020-05-14 05:43:21 +00:00
commit d220e1bb8d
5 changed files with 60 additions and 5 deletions

View file

@ -9,8 +9,9 @@ class HtmlMessage extends StatelessWidget {
final String html;
final Color textColor;
final int maxLines;
final Room room;
const HtmlMessage({this.html, this.textColor, this.maxLines});
const HtmlMessage({this.html, this.textColor, this.maxLines, this.room});
@override
Widget build(BuildContext context) {
@ -36,6 +37,57 @@ class HtmlMessage extends StatelessWidget {
method: ThumbnailMethod.scale,
);
},
getPillInfo: (String identifier) async {
if (room == null) {
return null;
}
if (identifier[0] == '@') {
// we have a user pill
final user = room.getState('m.room.member', identifier);
if (user != null) {
return user.content;
}
// there might still be a profile...
final profile = await room.client.getProfileFromUserId(identifier);
if (profile != null) {
return {
'displayname': profile.displayname,
'avatar_url': profile.avatarUrl.toString(),
};
}
return null;
}
if (identifier[0] == '#') {
// we have an alias pill
for (final r in room.client.rooms) {
final state = r.getState('m.room.canonical_alias');
if (
state != null && (
(state.content['alias'] is String && state.content['alias'] == identifier) ||
(state.content['alt_aliases'] is List && state.content['alt_aliases'].contains(identifier))
)) {
// we have a room!
return {
'displayname': identifier,
'avatar_url': r.getState('m.room.avatar')?.content['url'],
};
}
}
return null;
}
if (identifier[0] == '!') {
// we have a room ID pill
final r = room.client.getRoomById(identifier);
if (r == null) {
return null;
}
return {
'displayname': r.canonicalAlias,
'avatar_url': r.getState('m.room.avatar')?.content['url'],
};
}
return null;
},
);
}
}

View file

@ -40,6 +40,7 @@ class MessageContent extends StatelessWidget {
case MessageTypes.Text:
case MessageTypes.Notice:
case MessageTypes.Emote:
case MessageTypes.Reply:
if (Matrix.of(context).renderHtml &&
!event.redacted &&
event.content['format'] == 'org.matrix.custom.html' &&
@ -51,12 +52,12 @@ class MessageContent extends StatelessWidget {
return HtmlMessage(
html: html,
textColor: textColor,
room: event.room,
);
}
// else we fall through to the normal message rendering
continue textmessage;
case MessageTypes.BadEncrypted:
case MessageTypes.Reply:
case MessageTypes.Location:
case MessageTypes.None:
textmessage:

View file

@ -33,6 +33,7 @@ class ReplyContent extends StatelessWidget {
? Colors.white
: Theme.of(context).textTheme.bodyText2.color,
maxLines: 1,
room: replyEvent.room,
);
} else {
replyBody = Text(
@ -51,6 +52,7 @@ class ReplyContent extends StatelessWidget {
);
}
return Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
width: 3,
@ -58,7 +60,7 @@ class ReplyContent extends StatelessWidget {
color: lightText ? Colors.white : Theme.of(context).primaryColor,
),
SizedBox(width: 6),
Expanded(
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,

View file

@ -203,7 +203,7 @@ packages:
name: flutter_matrix_html
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.5"
version: "0.0.6"
flutter_plugin_android_lifecycle:
dependency: transitive
description:

View file

@ -54,7 +54,7 @@ dependencies:
open_file: ^3.0.1
mime_type: ^0.3.0
bot_toast: ^3.0.0
flutter_matrix_html: ^0.0.5
flutter_matrix_html: ^0.0.6
moor: ^3.0.2
random_string: ^2.0.1