Add public room discovery

This commit is contained in:
Christian Pauly 2020-02-22 20:05:04 +01:00
parent 020cba5679
commit 5c4d9cc12f
10 changed files with 170 additions and 23 deletions

View file

@ -48,7 +48,7 @@ flutter pub run intl_translation:extract_to_arb --output-dir=lib/i18n lib/i18n/i
4. Update the translations with this command: 4. Update the translations with this command:
``` ```
flutter pub pub run intl_translation:generate_from_arb --output-dir=lib/i18n --no-use-deferred-loading lib/i18n/I18n.dart lib/i18n/intl_*.arb flutter pub pub run intl_translation:generate_from_arb --output-dir=lib/i18n --no-use-deferred-loading lib/i18n/i18n.dart lib/i18n/intl_*.arb
``` ```
5. Make sure your language is in `supportedLocales` in `/lib/main.dart`. 5. Make sure your language is in `supportedLocales` in `/lib/main.dart`.

View file

@ -0,0 +1,48 @@
import 'package:famedlysdk/famedlysdk.dart';
import 'package:flutter/material.dart';
import '../../i18n/i18n.dart';
import '../../utils/app_route.dart';
import '../../views/chat.dart';
import '../avatar.dart';
import '../matrix.dart';
class PublicRoomListItem extends StatelessWidget {
final PublicRoomEntry publicRoomEntry;
const PublicRoomListItem(this.publicRoomEntry, {Key key}) : super(key: key);
void joinAction(BuildContext context) async {
final success = await Matrix.of(context)
.tryRequestWithLoadingDialog(publicRoomEntry.join());
if (success != false) {
await Navigator.of(context).push(
AppRoute.defaultRoute(
context,
ChatView(publicRoomEntry.roomId),
),
);
}
}
@override
Widget build(BuildContext context) {
final bool hasTopic =
publicRoomEntry.topic != null && publicRoomEntry.topic.isNotEmpty;
return ListTile(
leading:
Avatar(MxContent(publicRoomEntry.avatarUrl), publicRoomEntry.name),
title: Text(hasTopic
? "${publicRoomEntry.name} (${publicRoomEntry.numJoinedMembers})"
: publicRoomEntry.name),
subtitle: Text(
hasTopic
? publicRoomEntry.topic
: I18n.of(context).countParticipants(
publicRoomEntry.numJoinedMembers?.toString() ?? "0"),
maxLines: 1,
),
onTap: () => joinAction(context),
);
}
}

View file

@ -188,6 +188,8 @@ class I18n {
String get changeTheNameOfTheGroup => String get changeTheNameOfTheGroup =>
Intl.message("Change the name of the group"); Intl.message("Change the name of the group");
String get changeTheServer => Intl.message("Change the server");
String get channelCorruptedDecryptError => String get channelCorruptedDecryptError =>
Intl.message("The encryption has been corrupted"); Intl.message("The encryption has been corrupted");
@ -478,6 +480,8 @@ class I18n {
String get pleaseEnterYourUsername => String get pleaseEnterYourUsername =>
Intl.message("Please enter your username"); Intl.message("Please enter your username");
String get publicRooms => Intl.message("Public Rooms");
String get rejoin => Intl.message("Rejoin"); String get rejoin => Intl.message("Rejoin");
String redactedAnEvent(String username) => Intl.message( String redactedAnEvent(String username) => Intl.message(

View file

@ -216,6 +216,11 @@
"type": "text", "type": "text",
"placeholders": {} "placeholders": {}
}, },
"Change the server": "Ändere den Server",
"@Change the server": {
"type": "text",
"placeholders": {}
},
"The encryption has been corrupted": "Die Verschlüsselung wurde korrumpiert", "The encryption has been corrupted": "Die Verschlüsselung wurde korrumpiert",
"@The encryption has been corrupted": { "@The encryption has been corrupted": {
"type": "text", "type": "text",
@ -761,6 +766,11 @@
"type": "text", "type": "text",
"placeholders": {} "placeholders": {}
}, },
"Public Rooms": "Öffentliche Räume",
"@Public Rooms": {
"type": "text",
"placeholders": {}
},
"Rejoin": "Wieder beitreten", "Rejoin": "Wieder beitreten",
"@Rejoin": { "@Rejoin": {
"type": "text", "type": "text",

View file

@ -1,5 +1,5 @@
{ {
"@@last_modified": "2020-02-22T08:18:47.225173", "@@last_modified": "2020-02-22T20:02:42.757437",
"About": "About", "About": "About",
"@About": { "@About": {
"type": "text", "type": "text",
@ -216,6 +216,11 @@
"type": "text", "type": "text",
"placeholders": {} "placeholders": {}
}, },
"Change the server": "Change the server",
"@Change the server": {
"type": "text",
"placeholders": {}
},
"The encryption has been corrupted": "The encryption has been corrupted", "The encryption has been corrupted": "The encryption has been corrupted",
"@The encryption has been corrupted": { "@The encryption has been corrupted": {
"type": "text", "type": "text",
@ -761,6 +766,11 @@
"type": "text", "type": "text",
"placeholders": {} "placeholders": {}
}, },
"Public Rooms": "Public Rooms",
"@Public Rooms": {
"type": "text",
"placeholders": {}
},
"Rejoin": "Rejoin", "Rejoin": "Rejoin",
"@Rejoin": { "@Rejoin": {
"type": "text", "type": "text",

View file

@ -150,6 +150,7 @@ class MessageLookup extends MessageLookupByLibrary {
"Ban from chat" : MessageLookupByLibrary.simpleMessage("Aus dem Chat verbannen"), "Ban from chat" : MessageLookupByLibrary.simpleMessage("Aus dem Chat verbannen"),
"Banned" : MessageLookupByLibrary.simpleMessage("Banned"), "Banned" : MessageLookupByLibrary.simpleMessage("Banned"),
"Change the name of the group" : MessageLookupByLibrary.simpleMessage("Gruppenname ändern"), "Change the name of the group" : MessageLookupByLibrary.simpleMessage("Gruppenname ändern"),
"Change the server" : MessageLookupByLibrary.simpleMessage("Ändere den Server"),
"Change your style" : MessageLookupByLibrary.simpleMessage("Change your style"), "Change your style" : MessageLookupByLibrary.simpleMessage("Change your style"),
"Changelog" : MessageLookupByLibrary.simpleMessage("Changelog"), "Changelog" : MessageLookupByLibrary.simpleMessage("Changelog"),
"Chat details" : MessageLookupByLibrary.simpleMessage("Gruppeninfo"), "Chat details" : MessageLookupByLibrary.simpleMessage("Gruppeninfo"),
@ -234,6 +235,7 @@ class MessageLookup extends MessageLookupByLibrary {
"Please enter a matrix identifier" : MessageLookupByLibrary.simpleMessage("Bitte eine Matrix ID eingeben"), "Please enter a matrix identifier" : MessageLookupByLibrary.simpleMessage("Bitte eine Matrix ID eingeben"),
"Please enter your password" : MessageLookupByLibrary.simpleMessage("Bitte dein Passwort eingeben"), "Please enter your password" : MessageLookupByLibrary.simpleMessage("Bitte dein Passwort eingeben"),
"Please enter your username" : MessageLookupByLibrary.simpleMessage("Bitte deinen Benutzernamen eingeben"), "Please enter your username" : MessageLookupByLibrary.simpleMessage("Bitte deinen Benutzernamen eingeben"),
"Public Rooms" : MessageLookupByLibrary.simpleMessage("Öffentliche Räume"),
"Rejoin" : MessageLookupByLibrary.simpleMessage("Wieder beitreten"), "Rejoin" : MessageLookupByLibrary.simpleMessage("Wieder beitreten"),
"Remove" : MessageLookupByLibrary.simpleMessage("Entfernen"), "Remove" : MessageLookupByLibrary.simpleMessage("Entfernen"),
"Remove all other devices" : MessageLookupByLibrary.simpleMessage("Alle anderen Geräte entfernen"), "Remove all other devices" : MessageLookupByLibrary.simpleMessage("Alle anderen Geräte entfernen"),

View file

@ -150,6 +150,7 @@ class MessageLookup extends MessageLookupByLibrary {
"Ban from chat" : MessageLookupByLibrary.simpleMessage("Ban from chat"), "Ban from chat" : MessageLookupByLibrary.simpleMessage("Ban from chat"),
"Banned" : MessageLookupByLibrary.simpleMessage("Banned"), "Banned" : MessageLookupByLibrary.simpleMessage("Banned"),
"Change the name of the group" : MessageLookupByLibrary.simpleMessage("Change the name of the group"), "Change the name of the group" : MessageLookupByLibrary.simpleMessage("Change the name of the group"),
"Change the server" : MessageLookupByLibrary.simpleMessage("Change the server"),
"Change your style" : MessageLookupByLibrary.simpleMessage("Change your style"), "Change your style" : MessageLookupByLibrary.simpleMessage("Change your style"),
"Changelog" : MessageLookupByLibrary.simpleMessage("Changelog"), "Changelog" : MessageLookupByLibrary.simpleMessage("Changelog"),
"Chat details" : MessageLookupByLibrary.simpleMessage("Chat details"), "Chat details" : MessageLookupByLibrary.simpleMessage("Chat details"),
@ -234,6 +235,7 @@ class MessageLookup extends MessageLookupByLibrary {
"Please enter a matrix identifier" : MessageLookupByLibrary.simpleMessage("Please enter a matrix identifier"), "Please enter a matrix identifier" : MessageLookupByLibrary.simpleMessage("Please enter a matrix identifier"),
"Please enter your password" : MessageLookupByLibrary.simpleMessage("Please enter your password"), "Please enter your password" : MessageLookupByLibrary.simpleMessage("Please enter your password"),
"Please enter your username" : MessageLookupByLibrary.simpleMessage("Please enter your username"), "Please enter your username" : MessageLookupByLibrary.simpleMessage("Please enter your username"),
"Public Rooms" : MessageLookupByLibrary.simpleMessage("Public Rooms"),
"Rejoin" : MessageLookupByLibrary.simpleMessage("Rejoin"), "Rejoin" : MessageLookupByLibrary.simpleMessage("Rejoin"),
"Remove" : MessageLookupByLibrary.simpleMessage("Remove"), "Remove" : MessageLookupByLibrary.simpleMessage("Remove"),
"Remove all other devices" : MessageLookupByLibrary.simpleMessage("Remove all other devices"), "Remove all other devices" : MessageLookupByLibrary.simpleMessage("Remove all other devices"),

View file

@ -1,6 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/list_items/public_room_list_item.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
@ -8,6 +9,7 @@ import 'package:flutter_speed_dial/flutter_speed_dial.dart';
import 'package:toast/toast.dart'; import 'package:toast/toast.dart';
import 'package:uni_links/uni_links.dart'; import 'package:uni_links/uni_links.dart';
import '../components/dialogs/simple_dialogs.dart';
import '../components/theme_switcher.dart'; import '../components/theme_switcher.dart';
import '../components/adaptive_page_layout.dart'; import '../components/adaptive_page_layout.dart';
import '../components/list_items/chat_list_item.dart'; import '../components/list_items/chat_list_item.dart';
@ -51,6 +53,10 @@ class _ChatListState extends State<ChatList> {
StreamSubscription sub; StreamSubscription sub;
final TextEditingController searchController = TextEditingController(); final TextEditingController searchController = TextEditingController();
SelectMode selectMode = SelectMode.normal; SelectMode selectMode = SelectMode.normal;
Timer coolDown;
PublicRoomsResponse publicRoomsResponse;
bool loadingPublicRooms = false;
String searchServer;
Future<bool> waitForFirstSync(BuildContext context) async { Future<bool> waitForFirstSync(BuildContext context) async {
Client client = Matrix.of(context).client; Client client = Matrix.of(context).client;
@ -64,9 +70,38 @@ class _ChatListState extends State<ChatList> {
@override @override
void initState() { void initState() {
searchController.addListener( searchController.addListener(() {
() => setState(() => null), coolDown?.cancel();
coolDown = Timer(Duration(seconds: 1), () async {
setState(() => loadingPublicRooms = true);
final newPublicRoomsResponse =
await Matrix.of(context).tryRequestWithErrorToast(
Matrix.of(context).client.requestPublicRooms(
limit: 30,
includeAllNetworks: true,
genericSearchTerm: searchController.text,
server: searchServer,
),
); );
setState(() {
loadingPublicRooms = false;
if (newPublicRoomsResponse != false) {
publicRoomsResponse = newPublicRoomsResponse;
if (searchController.text.isNotEmpty &&
searchController.text.isValidMatrixId &&
searchController.text.sigil == "#") {
publicRoomsResponse.publicRooms.add(
PublicRoomEntry(
aliases: [searchController.text],
name: searchController.text,
roomId: searchController.text),
);
}
}
});
});
setState(() => null);
});
initUniLinks(); initUniLinks();
super.initState(); super.initState();
} }
@ -133,12 +168,38 @@ class _ChatListState extends State<ChatList> {
leading: searchMode leading: searchMode
? IconButton( ? IconButton(
icon: Icon(Icons.arrow_back), icon: Icon(Icons.arrow_back),
onPressed: () => setState(() => searchMode = false), onPressed: () => setState(() {
publicRoomsResponse = null;
loadingPublicRooms = false;
searchMode = false;
}),
) )
: null, : null,
automaticallyImplyLeading: false, automaticallyImplyLeading: false,
actions: searchMode actions: searchMode
? null ? <Widget>[
if (loadingPublicRooms)
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Center(
child: CircularProgressIndicator(strokeWidth: 2),
),
),
IconButton(
icon: Icon(Icons.domain),
onPressed: () async {
final String newSearchServer = await SimpleDialogs(context)
.enterText(
titleText: I18n.of(context).changeTheServer,
labelText: I18n.of(context).changeTheServer,
hintText: Matrix.of(context).client.userID.domain,
prefixText: "https://");
if (newSearchServer?.isNotEmpty ?? false) {
searchServer = newSearchServer;
}
},
)
]
: <Widget>[ : <Widget>[
IconButton( IconButton(
icon: Icon(Icons.search), icon: Icon(Icons.search),
@ -201,8 +262,7 @@ class _ChatListState extends State<ChatList> {
foregroundColor: Colors.white, foregroundColor: Colors.white,
backgroundColor: Colors.blue, backgroundColor: Colors.blue,
label: I18n.of(context).createNewGroup, label: I18n.of(context).createNewGroup,
labelStyle: labelStyle: TextStyle(fontSize: 18.0, color: Colors.black),
TextStyle(fontSize: 18.0, color: Colors.black),
onTap: () => Navigator.of(context).pushAndRemoveUntil( onTap: () => Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(context, NewGroupView()), AppRoute.defaultRoute(context, NewGroupView()),
(r) => r.isFirst), (r) => r.isFirst),
@ -212,9 +272,7 @@ class _ChatListState extends State<ChatList> {
foregroundColor: Colors.white, foregroundColor: Colors.white,
backgroundColor: Colors.green, backgroundColor: Colors.green,
label: I18n.of(context).newPrivateChat, label: I18n.of(context).newPrivateChat,
labelStyle: TextStyle( labelStyle: TextStyle(fontSize: 18.0, color: Colors.black),
fontSize: 18.0,
color: Colors.black),
onTap: () => Navigator.of(context).pushAndRemoveUntil( onTap: () => Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(context, NewPrivateChatView()), AppRoute.defaultRoute(context, NewPrivateChatView()),
(r) => r.isFirst), (r) => r.isFirst),
@ -231,7 +289,7 @@ class _ChatListState extends State<ChatList> {
!room.displayname !room.displayname
.toLowerCase() .toLowerCase()
.contains(searchController.text.toLowerCase() ?? "")); .contains(searchController.text.toLowerCase() ?? ""));
if (rooms.isEmpty) { if (rooms.isEmpty && (!searchMode || publicRoomsResponse == null)) {
return Center( return Center(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@ -248,14 +306,27 @@ class _ChatListState extends State<ChatList> {
), ),
); );
} }
final int publicRoomsCount =
(publicRoomsResponse?.publicRooms?.length ?? 0);
final int totalCount = rooms.length + publicRoomsCount;
return ListView.separated( return ListView.separated(
separatorBuilder: (BuildContext context, int i) => separatorBuilder: (BuildContext context, int i) =>
Divider(indent: 70, height: 1), i == totalCount - publicRoomsCount - 1
itemCount: rooms.length, ? Material(
itemBuilder: (BuildContext context, int i) => ChatListItem( elevation: 2,
child: ListTile(
title: Text("Public Rooms:"),
),
)
: Divider(indent: 70, height: 1),
itemCount: totalCount,
itemBuilder: (BuildContext context, int i) => i < rooms.length
? ChatListItem(
rooms[i], rooms[i],
activeChat: widget.activeChat == rooms[i].id, activeChat: widget.activeChat == rooms[i].id,
), )
: PublicRoomListItem(
publicRoomsResponse.publicRooms[i - rooms.length]),
); );
} else { } else {
return Center( return Center(

View file

@ -124,8 +124,8 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
path: "." path: "."
ref: "0b5e806cdfeccae6ef49c5cfe5dfa19c1a0ff259" ref: "0b0facb0e058403e3ddf79cb85f318f7acf1e593"
resolved-ref: "0b5e806cdfeccae6ef49c5cfe5dfa19c1a0ff259" resolved-ref: "0b0facb0e058403e3ddf79cb85f318f7acf1e593"
url: "https://gitlab.com/famedly/famedlysdk.git" url: "https://gitlab.com/famedly/famedlysdk.git"
source: git source: git
version: "0.0.1" version: "0.0.1"
@ -274,7 +274,7 @@ packages:
name: intl name: intl
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.16.1" version: "0.16.0"
intl_translation: intl_translation:
dependency: "direct main" dependency: "direct main"
description: description:

View file

@ -27,7 +27,7 @@ dependencies:
famedlysdk: famedlysdk:
git: git:
url: https://gitlab.com/famedly/famedlysdk.git url: https://gitlab.com/famedly/famedlysdk.git
ref: 0b5e806cdfeccae6ef49c5cfe5dfa19c1a0ff259 ref: 0b0facb0e058403e3ddf79cb85f318f7acf1e593
localstorage: ^3.0.1+4 localstorage: ^3.0.1+4
bubble: ^1.1.9+1 bubble: ^1.1.9+1