Handle matrix.to links

This commit is contained in:
Christian Pauly 2020-01-19 19:28:12 +01:00
commit 4f4e3a4df5
6 changed files with 116 additions and 3 deletions

View file

@ -13,9 +13,9 @@ import 'package:fluffychat/utils/room_state_enums_extensions.dart';
import 'package:fluffychat/views/chat_list.dart';
import 'package:fluffychat/views/invitation_selection.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import 'package:link_text/link_text.dart';
import 'package:share/share.dart';
import 'package:toast/toast.dart';
class ChatDetails extends StatefulWidget {
@ -157,8 +157,13 @@ class _ChatDetailsState extends State<ChatDetails> {
if (widget.room.canonicalAlias?.isNotEmpty ?? false)
IconButton(
icon: Icon(Icons.share),
onPressed: () => Share.share(
"https://matrix.to/#/${widget.room.canonicalAlias}"),
onPressed: () {
Clipboard.setData(
ClipboardData(text: widget.room.canonicalAlias),
);
Toast.show("Invitation link copied to clipboard", context,
duration: 5);
},
),
ChatSettingsPopupMenu(widget.room, false)
],
@ -209,6 +214,7 @@ class _ChatDetailsState extends State<ChatDetails> {
text: widget.room.topic?.isEmpty ?? true
? "Add a group description"
: widget.room.topic,
linkStyle: TextStyle(color: Colors.blueAccent),
textStyle: TextStyle(
fontSize: 14,
color: Colors.black,

View file

@ -7,10 +7,12 @@ import 'package:fluffychat/components/dialogs/new_private_chat_dialog.dart';
import 'package:fluffychat/components/list_items/chat_list_item.dart';
import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/utils/url_launcher.dart';
import 'package:fluffychat/views/archive.dart';
import 'package:fluffychat/views/settings.dart';
import 'package:flutter/material.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
enum SelectMode { normal, multi_select, share }
@ -57,15 +59,40 @@ class _ChatListState extends State<ChatList> {
searchController.addListener(
() => setState(() => null),
);
getSharedData();
super.initState();
}
StreamSubscription _intentDataStreamSubscription;
void processSharedText(String text) {
if (text.startsWith("https://matrix.to/#/")) {
UrlLauncher(context, text).openMatrixToUrl();
} else {
setState(() => Matrix.of(context).shareContent = {
"msgtype": "m.text",
"body": text,
});
}
}
void getSharedData() {
// For sharing or opening urls/text coming from outside the app while the app is in the memory
_intentDataStreamSubscription = ReceiveSharingIntent.getTextStream()
.listen(processSharedText, onError: (err) {
print("getLinkStream error: $err");
});
// For sharing or opening urls/text coming from outside the app while the app is closed
ReceiveSharingIntent.getInitialText().then(processSharedText);
}
@override
void dispose() {
sub?.cancel();
searchController.removeListener(
() => setState(() => null),
);
_intentDataStreamSubscription?.cancel();
super.dispose();
}