refactor: matrix to link prefix

This commit is contained in:
Christian Pauly 2020-11-22 21:51:30 +01:00
parent d1e291ea76
commit 1aa9c08a3e
4 changed files with 12 additions and 12 deletions

View File

@ -18,6 +18,7 @@ abstract class AppConfig {
static bool renderHtml = false; static bool renderHtml = false;
static bool hideRedactedEvents = false; static bool hideRedactedEvents = false;
static bool hideUnknownEvents = false; static bool hideUnknownEvents = false;
static String matrixToLinkPrefix = 'https://matrix.to/#/';
static void loadFromJson(Map<String, dynamic> json) { static void loadFromJson(Map<String, dynamic> json) {
if (json['application_name'] is String) { if (json['application_name'] is String) {

View File

@ -2,6 +2,7 @@ import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
import 'package:fluffychat/components/matrix.dart'; import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/utils/app_route.dart'; import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/views/chat.dart'; import 'package:fluffychat/views/chat.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -14,7 +15,7 @@ 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(AppConfig.matrixToLinkPrefix) ||
{'#', '@', '!', '+', '\$'}.contains(url[0])) { {'#', '@', '!', '+', '\$'}.contains(url[0])) {
return openMatrixToUrl(); return openMatrixToUrl();
} }
@ -23,7 +24,7 @@ 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(AppConfig.matrixToLinkPrefix, '');
if (identifier[0] == '#' || identifier[0] == '!') { if (identifier[0] == '#' || identifier[0] == '!') {
// sometimes we have identifiers which have an event id and additional query parameters // sometimes we have identifiers which have an event id and additional query parameters
// we want to separate those. // we want to separate those.

View File

@ -1,4 +1,6 @@
import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/utils/fluffy_share.dart';
import 'package:flushbar/flushbar_helper.dart'; import 'package:flushbar/flushbar_helper.dart';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:famedlysdk/matrix_api.dart'; import 'package:famedlysdk/matrix_api.dart';
@ -16,7 +18,6 @@ import 'package:fluffychat/views/chat_list.dart';
import 'package:fluffychat/views/invitation_selection.dart'; import 'package:fluffychat/views/invitation_selection.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
import 'package:matrix_link_text/link_text.dart'; import 'package:matrix_link_text/link_text.dart';
@ -198,14 +199,10 @@ class _ChatDetailsState extends State<ChatDetails> {
if (widget.room.canonicalAlias?.isNotEmpty ?? false) if (widget.room.canonicalAlias?.isNotEmpty ?? false)
IconButton( IconButton(
icon: Icon(Icons.share), icon: Icon(Icons.share),
onPressed: () { onPressed: () => FluffyShare.share(
Clipboard.setData( AppConfig.matrixToLinkPrefix +
ClipboardData(text: widget.room.canonicalAlias), widget.room.canonicalAlias,
); context),
FlushbarHelper.createSuccess(
message: L10n.of(context).copiedToClipboard)
.show(context);
},
), ),
ChatSettingsPopupMenu(widget.room, false) ChatSettingsPopupMenu(widget.room, false)
], ],

View File

@ -7,6 +7,7 @@ import 'package:famedlysdk/matrix_api.dart';
import 'package:fluffychat/components/connection_status_header.dart'; import 'package:fluffychat/components/connection_status_header.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
import 'package:fluffychat/components/list_items/public_room_list_item.dart'; import 'package:fluffychat/components/list_items/public_room_list_item.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/utils/fluffy_share.dart'; import 'package:fluffychat/utils/fluffy_share.dart';
import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/platform_infos.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
@ -157,7 +158,7 @@ class _ChatListState extends State<ChatList> {
if (Navigator.of(context).canPop()) { if (Navigator.of(context).canPop()) {
Navigator.of(context).popUntil((r) => r.isFirst); Navigator.of(context).popUntil((r) => r.isFirst);
} }
if (text.startsWith('https://matrix.to/#/')) { if (text.startsWith(AppConfig.matrixToLinkPrefix)) {
UrlLauncher(context, text).openMatrixToUrl(); UrlLauncher(context, text).openMatrixToUrl();
return; return;
} }