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),
onPressed: () {
_searchController.clear();
widget.onChanged?.call('');
_focusNode.unfocus();
},
)

View File

@ -5,6 +5,7 @@ import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/app_config.dart';
import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/views/chat.dart';
import 'package:fluffychat/views/discover_view.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'matrix_identifier_string_extension.dart';
@ -78,14 +79,8 @@ class UrlLauncher {
);
return;
}
if (roomIdOrAlias[0] == '!') {
if (roomIdOrAlias.sigil == '!') {
roomId = roomIdOrAlias;
}
if (await showOkCancelAlertDialog(
context: context,
title: 'Join room $roomIdOrAlias',
) ==
OkCancelResult.ok) {
final response =
await SimpleDialogs(context).tryRequestWithLoadingDialog(
matrix.client.joinRoomOrAlias(
@ -103,8 +98,15 @@ class UrlLauncher {
context, ChatView(response, scrollToEventId: event)),
(r) => r.isFirst,
);
}
} else if (identifier[0] == '@') {
} else if (identifier.sigil == '#') {
await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(
context,
DiscoverView(alias: identifier),
),
(r) => r.isFirst,
);
} else if (identifier.sigil == '@') {
final user = User(
identifier,
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';
class DiscoverView extends StatelessWidget {
final String alias;
const DiscoverView({Key key, this.alias}) : super(key: key);
@override
Widget build(BuildContext context) {
return AdaptivePageLayout(
firstScaffold: DiscoverPage(),
firstScaffold: DiscoverPage(alias: alias),
secondScaffold: EmptyPage(),
);
}
}
class DiscoverPage extends StatefulWidget {
final String alias;
const DiscoverPage({Key key, this.alias}) : super(key: key);
@override
_DiscoverPageState createState() => _DiscoverPageState();
}
@ -114,6 +120,7 @@ class _DiscoverPageState extends State<DiscoverPage> {
@override
void initState() {
_genericSearchTerm = widget.alias;
_scrollController.addListener(() async {
if (_scrollController.position.pixels > 0 && _scrolledToTop) {
setState(() => _scrolledToTop = false);
@ -126,8 +133,11 @@ class _DiscoverPageState extends State<DiscoverPage> {
@override
Widget build(BuildContext context) {
final server = _genericSearchTerm?.isValidMatrixId ?? false
? _genericSearchTerm.domain
: _server;
_publicRoomsResponse ??= Matrix.of(context).client.searchPublicRooms(
server: _server,
server: server,
genericSearchTerm: _genericSearchTerm,
);
return Scaffold(
@ -149,7 +159,7 @@ class _DiscoverPageState extends State<DiscoverPage> {
if (snapshot.hasError) {
return Center(child: Text(snapshot.error.toString()));
}
if (!snapshot.hasData) {
if (snapshot.connectionState != ConnectionState.done) {
return Center(child: CircularProgressIndicator());
}
final publicRoomsResponse = snapshot.data;