mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-23 20:49:26 +01:00
feat: Open alias in discover page
This commit is contained in:
parent
6381cea62d
commit
f0d1f5aed2
@ -80,6 +80,7 @@ class _DefaultAppBarSearchFieldState extends State<DefaultAppBarSearchField> {
|
||||
icon: Icon(Icons.backspace_outlined),
|
||||
onPressed: () {
|
||||
_searchController.clear();
|
||||
widget.onChanged?.call('');
|
||||
_focusNode.unfocus();
|
||||
},
|
||||
)
|
||||
|
@ -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,37 +98,45 @@ class UrlLauncher {
|
||||
context, ChatView(response, scrollToEventId: event)),
|
||||
(r) => r.isFirst,
|
||||
);
|
||||
}
|
||||
} else if (identifier[0] == '@') {
|
||||
final user = User(
|
||||
identifier,
|
||||
room: Room(id: '', client: matrix.client),
|
||||
);
|
||||
var roomId = matrix.client.getDirectChatFromUserId(identifier);
|
||||
if (roomId != null) {
|
||||
await Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
AppRoute.defaultRoute(context, ChatView(roomId)),
|
||||
} else if (identifier.sigil == '#') {
|
||||
await Navigator.of(context).pushAndRemoveUntil(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
DiscoverView(alias: identifier),
|
||||
),
|
||||
(r) => r.isFirst,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
title: 'Message user $identifier',
|
||||
) ==
|
||||
OkCancelResult.ok) {
|
||||
roomId = await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(user.startDirectChat());
|
||||
Navigator.of(context).pop();
|
||||
|
||||
} else if (identifier.sigil == '@') {
|
||||
final user = User(
|
||||
identifier,
|
||||
room: Room(id: '', client: matrix.client),
|
||||
);
|
||||
var roomId = matrix.client.getDirectChatFromUserId(identifier);
|
||||
if (roomId != null) {
|
||||
await Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
AppRoute.defaultRoute(context, ChatView(roomId)),
|
||||
(r) => r.isFirst,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
title: 'Message user $identifier',
|
||||
) ==
|
||||
OkCancelResult.ok) {
|
||||
roomId = await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(user.startDirectChat());
|
||||
Navigator.of(context).pop();
|
||||
|
||||
if (roomId != null) {
|
||||
await Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
AppRoute.defaultRoute(context, ChatView(roomId)),
|
||||
(r) => r.isFirst,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user