feat: Open alias in discover page

This commit is contained in:
Christian Pauly 2020-12-20 16:53:37 +01:00
parent 6381cea62d
commit f0d1f5aed2
3 changed files with 47 additions and 33 deletions

View File

@ -80,6 +80,7 @@ class _DefaultAppBarSearchFieldState extends State<DefaultAppBarSearchField> {
icon: Icon(Icons.backspace_outlined), icon: Icon(Icons.backspace_outlined),
onPressed: () { onPressed: () {
_searchController.clear(); _searchController.clear();
widget.onChanged?.call('');
_focusNode.unfocus(); _focusNode.unfocus();
}, },
) )

View File

@ -5,6 +5,7 @@ import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/app_config.dart'; import 'package:fluffychat/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:fluffychat/views/discover_view.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import 'matrix_identifier_string_extension.dart'; import 'matrix_identifier_string_extension.dart';
@ -78,14 +79,8 @@ class UrlLauncher {
); );
return; return;
} }
if (roomIdOrAlias[0] == '!') { if (roomIdOrAlias.sigil == '!') {
roomId = roomIdOrAlias; roomId = roomIdOrAlias;
}
if (await showOkCancelAlertDialog(
context: context,
title: 'Join room $roomIdOrAlias',
) ==
OkCancelResult.ok) {
final response = final response =
await SimpleDialogs(context).tryRequestWithLoadingDialog( await SimpleDialogs(context).tryRequestWithLoadingDialog(
matrix.client.joinRoomOrAlias( matrix.client.joinRoomOrAlias(
@ -103,8 +98,15 @@ class UrlLauncher {
context, ChatView(response, scrollToEventId: event)), context, ChatView(response, scrollToEventId: event)),
(r) => r.isFirst, (r) => r.isFirst,
); );
} } else if (identifier.sigil == '#') {
} else if (identifier[0] == '@') { await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(
context,
DiscoverView(alias: identifier),
),
(r) => r.isFirst,
);
} else if (identifier.sigil == '@') {
final user = User( final user = User(
identifier, identifier,
room: Room(id: '', client: matrix.client), room: Room(id: '', client: matrix.client),
@ -139,3 +141,4 @@ class UrlLauncher {
} }
} }
} }
}

View File

@ -15,16 +15,22 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'empty_page.dart'; import 'empty_page.dart';
class DiscoverView extends StatelessWidget { class DiscoverView extends StatelessWidget {
final String alias;
const DiscoverView({Key key, this.alias}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AdaptivePageLayout( return AdaptivePageLayout(
firstScaffold: DiscoverPage(), firstScaffold: DiscoverPage(alias: alias),
secondScaffold: EmptyPage(), secondScaffold: EmptyPage(),
); );
} }
} }
class DiscoverPage extends StatefulWidget { class DiscoverPage extends StatefulWidget {
final String alias;
const DiscoverPage({Key key, this.alias}) : super(key: key);
@override @override
_DiscoverPageState createState() => _DiscoverPageState(); _DiscoverPageState createState() => _DiscoverPageState();
} }
@ -114,6 +120,7 @@ class _DiscoverPageState extends State<DiscoverPage> {
@override @override
void initState() { void initState() {
_genericSearchTerm = widget.alias;
_scrollController.addListener(() async { _scrollController.addListener(() async {
if (_scrollController.position.pixels > 0 && _scrolledToTop) { if (_scrollController.position.pixels > 0 && _scrolledToTop) {
setState(() => _scrolledToTop = false); setState(() => _scrolledToTop = false);
@ -126,8 +133,11 @@ class _DiscoverPageState extends State<DiscoverPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final server = _genericSearchTerm?.isValidMatrixId ?? false
? _genericSearchTerm.domain
: _server;
_publicRoomsResponse ??= Matrix.of(context).client.searchPublicRooms( _publicRoomsResponse ??= Matrix.of(context).client.searchPublicRooms(
server: _server, server: server,
genericSearchTerm: _genericSearchTerm, genericSearchTerm: _genericSearchTerm,
); );
return Scaffold( return Scaffold(
@ -149,7 +159,7 @@ class _DiscoverPageState extends State<DiscoverPage> {
if (snapshot.hasError) { if (snapshot.hasError) {
return Center(child: Text(snapshot.error.toString())); return Center(child: Text(snapshot.error.toString()));
} }
if (!snapshot.hasData) { if (snapshot.connectionState != ConnectionState.done) {
return Center(child: CircularProgressIndicator()); return Center(child: CircularProgressIndicator());
} }
final publicRoomsResponse = snapshot.data; final publicRoomsResponse = snapshot.data;