Merge branch 'soru/url-opener' into 'master'
feat: open links better See merge request ChristianPauly/fluffychat-flutter!152
This commit is contained in:
commit
02595b0d16
|
@ -1,6 +1,11 @@
|
||||||
# Version 0.18.0 - 2020-09-??
|
# Version 0.18.0 - 2020-09-??
|
||||||
### Features
|
### Features
|
||||||
- Added translations: Armenian, Turkish, Chinese (Simplified)
|
- Added translations: Armenian, Turkish, Chinese (Simplified)
|
||||||
|
- Url-ify matrix identifiers
|
||||||
|
### Changes
|
||||||
|
- Tapping links, pills, etc. now does stuff
|
||||||
|
### Fixes:
|
||||||
|
- Various html rendering and url-ifying fixes
|
||||||
|
|
||||||
# Version 0.17.0 - 2020-08-31
|
# Version 0.17.0 - 2020-08-31
|
||||||
### Features
|
### Features
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:famedlysdk/famedlysdk.dart';
|
import 'package:famedlysdk/famedlysdk.dart';
|
||||||
import 'package:flutter_matrix_html/flutter_html.dart';
|
import 'package:flutter_matrix_html/flutter_html.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import '../utils/url_launcher.dart';
|
||||||
|
|
||||||
import 'matrix.dart';
|
import 'matrix.dart';
|
||||||
|
|
||||||
|
@ -42,12 +42,8 @@ class HtmlMessage extends StatelessWidget {
|
||||||
),
|
),
|
||||||
shrinkToFit: true,
|
shrinkToFit: true,
|
||||||
maxLines: maxLines,
|
maxLines: maxLines,
|
||||||
onLinkTap: (String url) {
|
onLinkTap: (url) => UrlLauncher(context, url).launchUrl(),
|
||||||
if (url == null || url.isEmpty) {
|
onPillTap: (url) => UrlLauncher(context, url).launchUrl(),
|
||||||
return;
|
|
||||||
}
|
|
||||||
launch(url);
|
|
||||||
},
|
|
||||||
getMxcUrl: (String mxc, double width, double height) {
|
getMxcUrl: (String mxc, double width, double height) {
|
||||||
final ratio = MediaQuery.of(context).devicePixelRatio;
|
final ratio = MediaQuery.of(context).devicePixelRatio;
|
||||||
return Uri.parse(mxc)?.getThumbnail(
|
return Uri.parse(mxc)?.getThumbnail(
|
||||||
|
|
|
@ -4,11 +4,12 @@ import 'package:fluffychat/components/image_bubble.dart';
|
||||||
import 'package:fluffychat/l10n/l10n.dart';
|
import 'package:fluffychat/l10n/l10n.dart';
|
||||||
import 'package:fluffychat/utils/event_extension.dart';
|
import 'package:fluffychat/utils/event_extension.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:link_text/link_text.dart';
|
import 'package:matrix_link_text/link_text.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
import 'matrix.dart';
|
import 'matrix.dart';
|
||||||
import 'message_download_content.dart';
|
import 'message_download_content.dart';
|
||||||
import 'html_message.dart';
|
import 'html_message.dart';
|
||||||
|
import '../utils/url_launcher.dart';
|
||||||
|
|
||||||
class MessageContent extends StatelessWidget {
|
class MessageContent extends StatelessWidget {
|
||||||
final Event event;
|
final Event event;
|
||||||
|
@ -84,6 +85,7 @@ class MessageContent extends StatelessWidget {
|
||||||
fontSize: DefaultTextStyle.of(context).style.fontSize,
|
fontSize: DefaultTextStyle.of(context).style.fontSize,
|
||||||
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
||||||
),
|
),
|
||||||
|
onLinkTap: (url) => UrlLauncher(context, url).launchUrl(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -12,7 +12,8 @@ class UrlLauncher {
|
||||||
const UrlLauncher(this.context, this.url);
|
const UrlLauncher(this.context, this.url);
|
||||||
|
|
||||||
void launchUrl() {
|
void launchUrl() {
|
||||||
if (url.startsWith('https://matrix.to/#/')) {
|
if (url.startsWith('https://matrix.to/#/') ||
|
||||||
|
{'#', '@', '!', '+', '\$'}.contains(url[0])) {
|
||||||
return openMatrixToUrl();
|
return openMatrixToUrl();
|
||||||
}
|
}
|
||||||
launch(url);
|
launch(url);
|
||||||
|
@ -21,33 +22,83 @@ class UrlLauncher {
|
||||||
void openMatrixToUrl() async {
|
void openMatrixToUrl() async {
|
||||||
final matrix = Matrix.of(context);
|
final matrix = Matrix.of(context);
|
||||||
final identifier = url.replaceAll('https://matrix.to/#/', '');
|
final identifier = url.replaceAll('https://matrix.to/#/', '');
|
||||||
if (identifier.substring(0, 1) == '#') {
|
if (identifier[0] == '#' || identifier[0] == '!') {
|
||||||
final response = await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
var room = matrix.client.getRoomByAlias(identifier);
|
||||||
matrix.client.joinRoom(
|
room ??= matrix.client.getRoomById(identifier);
|
||||||
Uri.encodeComponent(identifier),
|
var roomId = room?.id;
|
||||||
),
|
var servers = <String>[];
|
||||||
);
|
if (room == null && identifier == '#') {
|
||||||
if (response == false) return;
|
// we were unable to find the room locally...so resolve it
|
||||||
await Navigator.pushAndRemoveUntil(
|
final response =
|
||||||
context,
|
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||||
AppRoute.defaultRoute(context, ChatView(response['room_id'])),
|
matrix.client.requestRoomAliasInformations(identifier),
|
||||||
(r) => r.isFirst,
|
);
|
||||||
);
|
if (response != false) {
|
||||||
} else if (identifier.substring(0, 1) == '@') {
|
roomId = response.roomId;
|
||||||
|
servers = response.servers;
|
||||||
|
room = matrix.client.getRoomById(roomId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (room != null) {
|
||||||
|
// we have the room, so....just open it!
|
||||||
|
await Navigator.pushAndRemoveUntil(
|
||||||
|
context,
|
||||||
|
AppRoute.defaultRoute(context, ChatView(room.id)),
|
||||||
|
(r) => r.isFirst,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (identifier == '!') {
|
||||||
|
roomId = identifier;
|
||||||
|
}
|
||||||
|
if (roomId == null) {
|
||||||
|
// we haven't found this room....so let's ignore it
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (await SimpleDialogs(context)
|
||||||
|
.askConfirmation(titleText: 'Join room $identifier')) {
|
||||||
|
final response =
|
||||||
|
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||||
|
matrix.client.joinRoomOrAlias(
|
||||||
|
Uri.encodeComponent(roomId),
|
||||||
|
servers: servers,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (response == false) return;
|
||||||
|
await Navigator.pushAndRemoveUntil(
|
||||||
|
context,
|
||||||
|
AppRoute.defaultRoute(context, ChatView(response['room_id'])),
|
||||||
|
(r) => r.isFirst,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (identifier[0] == '@') {
|
||||||
final user = User(
|
final user = User(
|
||||||
identifier,
|
identifier,
|
||||||
room: Room(id: '', client: matrix.client),
|
room: Room(id: '', client: matrix.client),
|
||||||
);
|
);
|
||||||
final String roomID = await SimpleDialogs(context)
|
var roomId = matrix.client.getDirectChatFromUserId(identifier);
|
||||||
.tryRequestWithLoadingDialog(user.startDirectChat());
|
if (roomId != null) {
|
||||||
Navigator.of(context).pop();
|
|
||||||
|
|
||||||
if (roomID != null) {
|
|
||||||
await Navigator.pushAndRemoveUntil(
|
await Navigator.pushAndRemoveUntil(
|
||||||
context,
|
context,
|
||||||
AppRoute.defaultRoute(context, ChatView(roomID)),
|
AppRoute.defaultRoute(context, ChatView(roomId)),
|
||||||
(r) => r.isFirst,
|
(r) => r.isFirst,
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (await SimpleDialogs(context)
|
||||||
|
.askConfirmation(titleText: 'Message user $identifier')) {
|
||||||
|
roomId = await SimpleDialogs(context)
|
||||||
|
.tryRequestWithLoadingDialog(user.startDirectChat());
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
|
||||||
|
if (roomId != null) {
|
||||||
|
await Navigator.pushAndRemoveUntil(
|
||||||
|
context,
|
||||||
|
AppRoute.defaultRoute(context, ChatView(roomId)),
|
||||||
|
(r) => r.isFirst,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,10 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:bot_toast/bot_toast.dart';
|
import 'package:bot_toast/bot_toast.dart';
|
||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
import 'package:link_text/link_text.dart';
|
import 'package:matrix_link_text/link_text.dart';
|
||||||
import 'package:memoryfilepicker/memoryfilepicker.dart';
|
import 'package:memoryfilepicker/memoryfilepicker.dart';
|
||||||
import './settings_emotes.dart';
|
import './settings_emotes.dart';
|
||||||
|
import '../utils/url_launcher.dart';
|
||||||
|
|
||||||
class ChatDetails extends StatefulWidget {
|
class ChatDetails extends StatefulWidget {
|
||||||
final Room room;
|
final Room room;
|
||||||
|
@ -222,6 +223,8 @@ class _ChatDetailsState extends State<ChatDetails> {
|
||||||
.bodyText2
|
.bodyText2
|
||||||
.color,
|
.color,
|
||||||
),
|
),
|
||||||
|
onLinkTap: (url) =>
|
||||||
|
UrlLauncher(context, url).launchUrl(),
|
||||||
),
|
),
|
||||||
onTap: widget.room.canSendEvent('m.room.topic')
|
onTap: widget.room.canSendEvent('m.room.topic')
|
||||||
? () => setTopicAction(context)
|
? () => setTopicAction(context)
|
||||||
|
|
52
pubspec.lock
52
pubspec.lock
|
@ -78,6 +78,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.9+1"
|
version: "1.1.9+1"
|
||||||
|
cached_network_image:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: cached_network_image
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.3.1"
|
||||||
canonical_json:
|
canonical_json:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -270,12 +277,10 @@ packages:
|
||||||
flutter_matrix_html:
|
flutter_matrix_html:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "."
|
name: flutter_matrix_html
|
||||||
ref: "530df434b50002e04cbad63f53d6f0f5d5adbab5"
|
url: "https://pub.dartlang.org"
|
||||||
resolved-ref: "530df434b50002e04cbad63f53d6f0f5d5adbab5"
|
source: hosted
|
||||||
url: "https://github.com/Sorunome/flutter_matrix_html"
|
version: "0.1.4"
|
||||||
source: git
|
|
||||||
version: "0.1.2"
|
|
||||||
flutter_olm:
|
flutter_olm:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -426,13 +431,6 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.6.3-nullsafety"
|
version: "0.6.3-nullsafety"
|
||||||
link_text:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: link_text
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "0.1.2"
|
|
||||||
localstorage:
|
localstorage:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -468,6 +466,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.4"
|
version: "1.0.4"
|
||||||
|
matrix_link_text:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: matrix_link_text
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.1.4"
|
||||||
memoryfilepicker:
|
memoryfilepicker:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -524,6 +529,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.4.12"
|
version: "1.4.12"
|
||||||
|
octo_image:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: octo_image
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.2.1"
|
||||||
olm:
|
olm:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -685,6 +697,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.4.0+2"
|
version: "1.4.0+2"
|
||||||
|
rxdart:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: rxdart
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.24.1"
|
||||||
share:
|
share:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -886,6 +905,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.1.2"
|
version: "0.1.2"
|
||||||
|
uuid:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: uuid
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.2.2"
|
||||||
vector_math:
|
vector_math:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -40,7 +40,7 @@ dependencies:
|
||||||
ref: master
|
ref: master
|
||||||
firebase_messaging: ^6.0.13
|
firebase_messaging: ^6.0.13
|
||||||
flutter_local_notifications: ^1.4.3
|
flutter_local_notifications: ^1.4.3
|
||||||
link_text: ^0.1.1
|
matrix_link_text: ^0.1.4
|
||||||
path_provider: ^1.5.1
|
path_provider: ^1.5.1
|
||||||
webview_flutter: ^0.3.19+9
|
webview_flutter: ^0.3.19+9
|
||||||
share: ^0.6.3+5
|
share: ^0.6.3+5
|
||||||
|
@ -54,10 +54,7 @@ dependencies:
|
||||||
open_file: ^3.0.1
|
open_file: ^3.0.1
|
||||||
mime_type: ^0.3.0
|
mime_type: ^0.3.0
|
||||||
bot_toast: ^3.0.0
|
bot_toast: ^3.0.0
|
||||||
flutter_matrix_html:
|
flutter_matrix_html: ^0.1.4
|
||||||
git:
|
|
||||||
url: https://github.com/Sorunome/flutter_matrix_html
|
|
||||||
ref: 530df434b50002e04cbad63f53d6f0f5d5adbab5
|
|
||||||
moor: ^3.3.1
|
moor: ^3.3.1
|
||||||
sqlite3: ^0.1.4
|
sqlite3: ^0.1.4
|
||||||
random_string: ^2.0.1
|
random_string: ^2.0.1
|
||||||
|
|
Loading…
Reference in a new issue