mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-01-11 18:22:49 +01:00
feat: Permission dialog before open link in browser
This commit is contained in:
parent
17bccc0dea
commit
ce18cfdf2a
@ -2529,5 +2529,6 @@
|
|||||||
},
|
},
|
||||||
"jumpToLastReadMessage": "Jump to last read message",
|
"jumpToLastReadMessage": "Jump to last read message",
|
||||||
"readUpToHere": "Read up to here",
|
"readUpToHere": "Read up to here",
|
||||||
"jump": "Jump"
|
"jump": "Jump",
|
||||||
|
"openLinkInBrowser": "Open link in browser"
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import 'package:matrix/matrix.dart';
|
|||||||
import 'package:fluffychat/widgets/matrix.dart';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
import '../../../config/app_config.dart';
|
import '../../../config/app_config.dart';
|
||||||
import '../../../config/setting_keys.dart';
|
import '../../../config/setting_keys.dart';
|
||||||
import '../../../pages/image_viewer/image_viewer.dart';
|
|
||||||
import '../../../utils/matrix_sdk_extensions/matrix_locals.dart';
|
import '../../../utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||||
import '../../../utils/url_launcher.dart';
|
import '../../../utils/url_launcher.dart';
|
||||||
|
|
||||||
@ -83,24 +82,7 @@ class HtmlMessage extends StatelessWidget {
|
|||||||
)
|
)
|
||||||
.toString();
|
.toString();
|
||||||
},
|
},
|
||||||
onImageTap: (String mxc) => showDialog(
|
onImageTap: (url) => UrlLauncher(context, url).launchUrl(),
|
||||||
context: Matrix.of(context).navigatorContext,
|
|
||||||
useRootNavigator: false,
|
|
||||||
builder: (_) => ImageViewer(
|
|
||||||
Event(
|
|
||||||
type: EventTypes.Message,
|
|
||||||
content: <String, dynamic>{
|
|
||||||
'body': mxc,
|
|
||||||
'url': mxc,
|
|
||||||
'msgtype': MessageTypes.Image,
|
|
||||||
},
|
|
||||||
senderId: room.client.userID!,
|
|
||||||
originServerTs: DateTime.now(),
|
|
||||||
eventId: 'fake_event',
|
|
||||||
room: room,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
setCodeLanguage: (String key, String value) async {
|
setCodeLanguage: (String key, String value) async {
|
||||||
await matrix.store.setItem('${SettingKeys.codeLanguage}.$key', value);
|
await matrix.store.setItem('${SettingKeys.codeLanguage}.$key', value);
|
||||||
},
|
},
|
||||||
|
@ -22,7 +22,7 @@ class UrlLauncher {
|
|||||||
|
|
||||||
const UrlLauncher(this.context, this.url);
|
const UrlLauncher(this.context, this.url);
|
||||||
|
|
||||||
void launchUrl() {
|
void launchUrl() async {
|
||||||
if (url!.toLowerCase().startsWith(AppConfig.deepLinkPrefix) ||
|
if (url!.toLowerCase().startsWith(AppConfig.deepLinkPrefix) ||
|
||||||
url!.toLowerCase().startsWith(AppConfig.inviteLinkPrefix) ||
|
url!.toLowerCase().startsWith(AppConfig.inviteLinkPrefix) ||
|
||||||
{'#', '@', '!', '+', '\$'}.contains(url![0]) ||
|
{'#', '@', '!', '+', '\$'}.contains(url![0]) ||
|
||||||
@ -37,6 +37,15 @@ class UrlLauncher {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
final consent = await showOkCancelAlertDialog(
|
||||||
|
context: context,
|
||||||
|
title: L10n.of(context)!.openLinkInBrowser,
|
||||||
|
message: url,
|
||||||
|
okLabel: L10n.of(context)!.ok,
|
||||||
|
cancelLabel: L10n.of(context)!.cancel,
|
||||||
|
);
|
||||||
|
if (consent != OkCancelResult.ok) return;
|
||||||
|
|
||||||
if (!{'https', 'http'}.contains(uri.scheme)) {
|
if (!{'https', 'http'}.contains(uri.scheme)) {
|
||||||
// just launch non-https / non-http uris directly
|
// just launch non-https / non-http uris directly
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user