mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-25 15:02:33 +01:00
Finish creating groups
This commit is contained in:
parent
7c81657a9b
commit
0c93fc39e1
@ -1,23 +1,52 @@
|
|||||||
import 'package:fluffychat/views/chat.dart';
|
import 'package:fluffychat/views/chat.dart';
|
||||||
|
import 'package:fluffychat/views/invitation_selection.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pedantic/pedantic.dart';
|
||||||
|
|
||||||
import '../matrix.dart';
|
import '../matrix.dart';
|
||||||
|
|
||||||
class NewGroupDialog extends StatelessWidget {
|
class NewGroupDialog extends StatefulWidget {
|
||||||
final TextEditingController controller = TextEditingController();
|
@override
|
||||||
|
_NewGroupDialogState createState() => _NewGroupDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _NewGroupDialogState extends State<NewGroupDialog> {
|
||||||
|
TextEditingController controller = TextEditingController();
|
||||||
|
bool publicGroup = false;
|
||||||
|
|
||||||
void submitAction(BuildContext context) async {
|
void submitAction(BuildContext context) async {
|
||||||
final MatrixState matrix = Matrix.of(context);
|
final MatrixState matrix = Matrix.of(context);
|
||||||
Map<String, dynamic> params = {};
|
Map<String, dynamic> params = {};
|
||||||
|
if (publicGroup) {
|
||||||
|
params["preset"] = "public_chat";
|
||||||
|
params["visibility"] = "public";
|
||||||
|
if (controller.text.isNotEmpty) {
|
||||||
|
params["room_alias_name"] = controller.text;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
params["preset"] = "private_chat";
|
||||||
|
}
|
||||||
if (controller.text.isNotEmpty) params["name"] = controller.text;
|
if (controller.text.isNotEmpty) params["name"] = controller.text;
|
||||||
final String roomID = await matrix.tryRequestWithLoadingDialog(
|
final String roomID = await matrix.tryRequestWithLoadingDialog(
|
||||||
matrix.client.createRoom(params: params),
|
matrix.client.createRoom(params: params),
|
||||||
);
|
);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
if (roomID != null) {
|
if (roomID != null) {
|
||||||
|
unawaited(
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) {
|
||||||
|
return Chat(roomID);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
await Navigator.push(
|
await Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => Chat(roomID)),
|
MaterialPageRoute(
|
||||||
|
builder: (context) => InvitationSelection(
|
||||||
|
matrix.client.getRoomById(roomID),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,15 +60,19 @@ class NewGroupDialog extends StatelessWidget {
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
TextField(
|
TextField(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
autofocus: true,
|
|
||||||
autocorrect: false,
|
autocorrect: false,
|
||||||
textInputAction: TextInputAction.go,
|
textInputAction: TextInputAction.go,
|
||||||
onSubmitted: (s) => submitAction(context),
|
onSubmitted: (s) => submitAction(context),
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: "Group name",
|
labelText: "(Optional) Group name",
|
||||||
icon: Icon(Icons.people),
|
icon: Icon(Icons.people),
|
||||||
hintText: "Enter a group name"),
|
hintText: "Enter a group name"),
|
||||||
),
|
),
|
||||||
|
SwitchListTile(
|
||||||
|
title: Text("Group is public"),
|
||||||
|
value: publicGroup,
|
||||||
|
onChanged: (bool b) => setState(() => publicGroup = b),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
|
@ -5,7 +5,8 @@ extension LocalizedRoomDisplayname on Room {
|
|||||||
String getLocalizedDisplayname(BuildContext context) {
|
String getLocalizedDisplayname(BuildContext context) {
|
||||||
if ((this.name?.isEmpty ?? true) &&
|
if ((this.name?.isEmpty ?? true) &&
|
||||||
(this.canonicalAlias?.isEmpty ?? true) &&
|
(this.canonicalAlias?.isEmpty ?? true) &&
|
||||||
!this.isDirectChat) {
|
!this.isDirectChat &&
|
||||||
|
this.mHeroes.isNotEmpty) {
|
||||||
return "Group with ${this.displayname}";
|
return "Group with ${this.displayname}";
|
||||||
}
|
}
|
||||||
return this.displayname;
|
return this.displayname;
|
||||||
|
Loading…
Reference in New Issue
Block a user