feat: Handle matrix: URIs as per MSC2312

This commit is contained in:
Sorunome 2021-01-10 18:00:27 +01:00
commit 03058d44e6
15 changed files with 41 additions and 101 deletions

View file

@ -1,6 +1,6 @@
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:famedlysdk/encryption.dart';
import 'package:famedlysdk/matrix_api.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

View file

@ -53,14 +53,15 @@ class HtmlMessage extends StatelessWidget {
maxLines: maxLines,
onLinkTap: (url) => UrlLauncher(context, url).launchUrl(),
onPillTap: (url) => UrlLauncher(context, url).launchUrl(),
getMxcUrl: (String mxc, double width, double height) {
getMxcUrl: (String mxc, double width, double height,
{bool animated = false}) {
final ratio = MediaQuery.of(context).devicePixelRatio;
return Uri.parse(mxc)?.getThumbnail(
matrix.client,
width: (width ?? 800) * ratio,
height: (height ?? 800) * ratio,
method: ThumbnailMethod.scale,
animated: true,
animated: animated,
);
},
setCodeLanguage: (String key, String value) async {
@ -69,11 +70,16 @@ class HtmlMessage extends StatelessWidget {
getCodeLanguage: (String key) async {
return await matrix.store.getItem('${SettingKeys.codeLanguage}.$key');
},
getPillInfo: (String identifier) async {
getPillInfo: (String url) async {
if (room == null) {
return null;
}
if (identifier[0] == '@') {
final identityParts = url.parseIdentifierIntoParts();
final identifier = identityParts?.primaryIdentifier;
if (identifier == null) {
return null;
}
if (identifier.sigil == '@') {
// we have a user pill
final user = room.getState('m.room.member', identifier);
if (user != null) {
@ -89,7 +95,7 @@ class HtmlMessage extends StatelessWidget {
}
return null;
}
if (identifier[0] == '#') {
if (identifier.sigil == '#') {
// we have an alias pill
for (final r in room.client.rooms) {
final state = r.getState('m.room.canonical_alias');
@ -107,7 +113,7 @@ class HtmlMessage extends StatelessWidget {
}
return null;
}
if (identifier[0] == '!') {
if (identifier.sigil == '!') {
// we have a room ID pill
final r = room.client.getRoomById(identifier);
if (r == null) {

View file

@ -1,5 +1,4 @@
import 'package:famedlysdk/famedlysdk.dart';
import 'package:famedlysdk/matrix_api.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';