mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-25 06:52:35 +01:00
Merge branch 'krille/remember-server-search' into 'main'
feat: Remember homeserver on search page See merge request famedly/fluffychat!651
This commit is contained in:
commit
98afcf976a
@ -1,3 +1,5 @@
|
|||||||
|
//@dart=2.12
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -7,12 +9,13 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:vrouter/vrouter.dart';
|
import 'package:vrouter/vrouter.dart';
|
||||||
|
|
||||||
|
import 'package:fluffychat/utils/famedlysdk_store.dart';
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
import 'package:fluffychat/widgets/public_room_bottom_sheet.dart';
|
import 'package:fluffychat/widgets/public_room_bottom_sheet.dart';
|
||||||
import 'search_view.dart';
|
import 'search_view.dart';
|
||||||
|
|
||||||
class Search extends StatefulWidget {
|
class Search extends StatefulWidget {
|
||||||
const Search({Key key}) : super(key: key);
|
const Search({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
SearchController createState() => SearchController();
|
SearchController createState() => SearchController();
|
||||||
@ -20,13 +23,13 @@ class Search extends StatefulWidget {
|
|||||||
|
|
||||||
class SearchController extends State<Search> {
|
class SearchController extends State<Search> {
|
||||||
final TextEditingController controller = TextEditingController();
|
final TextEditingController controller = TextEditingController();
|
||||||
Future<QueryPublicRoomsResponse> publicRoomsResponse;
|
Future<QueryPublicRoomsResponse>? publicRoomsResponse;
|
||||||
String lastServer;
|
String? lastServer;
|
||||||
Timer _coolDown;
|
Timer? _coolDown;
|
||||||
String genericSearchTerm;
|
String? genericSearchTerm;
|
||||||
|
|
||||||
void search(String query) async {
|
void search(String query) async {
|
||||||
setState(() => null);
|
setState(() {});
|
||||||
_coolDown?.cancel();
|
_coolDown?.cancel();
|
||||||
_coolDown = Timer(
|
_coolDown = Timer(
|
||||||
const Duration(milliseconds: 500),
|
const Duration(milliseconds: 500),
|
||||||
@ -49,30 +52,33 @@ class SearchController extends State<Search> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
String server;
|
String? server;
|
||||||
|
|
||||||
|
static const String _serverStoreNamespace = 'im.fluffychat.search.server';
|
||||||
|
|
||||||
void setServer() async {
|
void setServer() async {
|
||||||
final newServer = await showTextInputDialog(
|
final newServer = await showTextInputDialog(
|
||||||
useRootNavigator: false,
|
useRootNavigator: false,
|
||||||
title: L10n.of(context).changeTheHomeserver,
|
title: L10n.of(context)!.changeTheHomeserver,
|
||||||
context: context,
|
context: context,
|
||||||
okLabel: L10n.of(context).ok,
|
okLabel: L10n.of(context)!.ok,
|
||||||
cancelLabel: L10n.of(context).cancel,
|
cancelLabel: L10n.of(context)!.cancel,
|
||||||
textFields: [
|
textFields: [
|
||||||
DialogTextField(
|
DialogTextField(
|
||||||
prefixText: 'https://',
|
prefixText: 'https://',
|
||||||
hintText: Matrix.of(context).client.homeserver.host,
|
hintText: Matrix.of(context).client.homeserver?.host,
|
||||||
initialText: server,
|
initialText: server,
|
||||||
keyboardType: TextInputType.url,
|
keyboardType: TextInputType.url,
|
||||||
)
|
)
|
||||||
]);
|
]);
|
||||||
if (newServer == null) return;
|
if (newServer == null) return;
|
||||||
|
Store().setItem(_serverStoreNamespace, newServer.single);
|
||||||
setState(() {
|
setState(() {
|
||||||
server = newServer.single;
|
server = newServer.single;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
String currentSearchTerm;
|
String? currentSearchTerm;
|
||||||
List<Profile> foundProfiles = [];
|
List<Profile> foundProfiles = [];
|
||||||
|
|
||||||
static const searchUserDirectoryLimit = 10;
|
static const searchUserDirectoryLimit = 10;
|
||||||
@ -84,9 +90,9 @@ class SearchController extends State<Search> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
currentSearchTerm = text;
|
currentSearchTerm = text;
|
||||||
if (currentSearchTerm.isEmpty) return;
|
if (currentSearchTerm?.isEmpty ?? true) return;
|
||||||
final matrix = Matrix.of(context);
|
final matrix = Matrix.of(context);
|
||||||
SearchUserDirectoryResponse response;
|
SearchUserDirectoryResponse? response;
|
||||||
try {
|
try {
|
||||||
response = await matrix.client.searchUserDirectory(
|
response = await matrix.client.searchUserDirectory(
|
||||||
text,
|
text,
|
||||||
@ -100,21 +106,22 @@ class SearchController extends State<Search> {
|
|||||||
'user_id': text,
|
'user_id': text,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
setState(() => null);
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _init = false;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
void initState() {
|
||||||
if (!_init) {
|
super.initState();
|
||||||
_init = true;
|
controller.text = VRouter.of(context).queryParameters['query'] ?? '';
|
||||||
controller.text = VRouter.of(context).queryParameters['query'] ?? '';
|
WidgetsBinding.instance?.addPostFrameCallback((_) async {
|
||||||
WidgetsBinding.instance
|
final server = await Store().getItem(_serverStoreNamespace) as String?;
|
||||||
.addPostFrameCallback((_) => search(controller.text));
|
if (server?.isNotEmpty ?? false) {
|
||||||
}
|
this.server = server;
|
||||||
|
}
|
||||||
return SearchView(this);
|
search(controller.text);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => SearchView(this);
|
||||||
}
|
}
|
||||||
// #fluffychat:matrix.org
|
|
||||||
|
Loading…
Reference in New Issue
Block a user