mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-05-02 07:37:23 +02:00
feat: Enable E2EE by default for new rooms
This commit is contained in:
parent
09cf1c7677
commit
f2e37b20ff
@ -17,19 +17,29 @@ class NewGroupController extends State<NewGroup> {
|
|||||||
void setPublicGroup(bool b) => setState(() => publicGroup = b);
|
void setPublicGroup(bool b) => setState(() => publicGroup = b);
|
||||||
|
|
||||||
void submitAction([_]) async {
|
void submitAction([_]) async {
|
||||||
final matrix = Matrix.of(context);
|
final client = Matrix.of(context).client;
|
||||||
final roomID = await showFutureLoadingDialog(
|
final roomID = await showFutureLoadingDialog(
|
||||||
context: context,
|
context: context,
|
||||||
future: () => matrix.client.createRoom(
|
future: () async {
|
||||||
preset: publicGroup
|
final roomId = await client.createRoom(
|
||||||
? sdk.CreateRoomPreset.publicChat
|
preset: publicGroup
|
||||||
: sdk.CreateRoomPreset.privateChat,
|
? sdk.CreateRoomPreset.publicChat
|
||||||
visibility: publicGroup ? sdk.Visibility.public : null,
|
: sdk.CreateRoomPreset.privateChat,
|
||||||
roomAliasName: publicGroup && controller.text.isNotEmpty
|
visibility: publicGroup ? sdk.Visibility.public : null,
|
||||||
? controller.text.trim().toLowerCase().replaceAll(' ', '_')
|
roomAliasName: publicGroup && controller.text.isNotEmpty
|
||||||
: null,
|
? controller.text.trim().toLowerCase().replaceAll(' ', '_')
|
||||||
name: controller.text.isNotEmpty ? controller.text : null,
|
: null,
|
||||||
),
|
name: controller.text.isNotEmpty ? controller.text : null,
|
||||||
|
);
|
||||||
|
if (client.getRoomById(roomId) == null) {
|
||||||
|
await client.onSync.stream.firstWhere(
|
||||||
|
(sync) => sync.rooms?.join?.containsKey(roomId) ?? false);
|
||||||
|
}
|
||||||
|
if (!publicGroup && client.encryptionEnabled) {
|
||||||
|
await client.getRoomById(roomId).enableEncryption();
|
||||||
|
}
|
||||||
|
return roomId;
|
||||||
|
},
|
||||||
);
|
);
|
||||||
if (roomID.error == null) {
|
if (roomID.error == null) {
|
||||||
VRouter.of(context).toSegments(['rooms', roomID.result, 'invite']);
|
VRouter.of(context).toSegments(['rooms', roomID.result, 'invite']);
|
||||||
|
@ -48,7 +48,6 @@ class FlutterMatrixHiveStore extends FamedlySdkHiveDatabase {
|
|||||||
static Future<FamedlySdkHiveDatabase> hiveDatabaseBuilder(
|
static Future<FamedlySdkHiveDatabase> hiveDatabaseBuilder(
|
||||||
Client client) async {
|
Client client) async {
|
||||||
if (!kIsWeb && !_hiveInitialized) {
|
if (!kIsWeb && !_hiveInitialized) {
|
||||||
Logs().i('Init Hive database...');
|
|
||||||
_hiveInitialized = true;
|
_hiveInitialized = true;
|
||||||
}
|
}
|
||||||
HiveCipher hiverCipher;
|
HiveCipher hiverCipher;
|
||||||
@ -81,7 +80,6 @@ class FlutterMatrixHiveStore extends FamedlySdkHiveDatabase {
|
|||||||
client.clientName,
|
client.clientName,
|
||||||
encryptionCipher: hiverCipher,
|
encryptionCipher: hiverCipher,
|
||||||
);
|
);
|
||||||
Logs().i('Open Hive database...');
|
|
||||||
try {
|
try {
|
||||||
await db.open();
|
await db.open();
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
@ -89,7 +87,6 @@ class FlutterMatrixHiveStore extends FamedlySdkHiveDatabase {
|
|||||||
await db.clear(client.id);
|
await db.clear(client.id);
|
||||||
await db.open();
|
await db.open();
|
||||||
}
|
}
|
||||||
Logs().i('Hive database is ready!');
|
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,9 +20,20 @@ class ProfileBottomSheet extends StatelessWidget {
|
|||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
void _startDirectChat(BuildContext context) async {
|
void _startDirectChat(BuildContext context) async {
|
||||||
|
final client = Matrix.of(context).client;
|
||||||
final result = await showFutureLoadingDialog<String>(
|
final result = await showFutureLoadingDialog<String>(
|
||||||
context: context,
|
context: context,
|
||||||
future: () => Matrix.of(context).client.startDirectChat(userId),
|
future: () async {
|
||||||
|
final roomId = await client.startDirectChat(userId);
|
||||||
|
if (client.getRoomById(roomId) == null) {
|
||||||
|
await client.onSync.stream.firstWhere(
|
||||||
|
(sync) => sync.rooms?.join?.containsKey(roomId) ?? false);
|
||||||
|
}
|
||||||
|
if (client.encryptionEnabled) {
|
||||||
|
await client.getRoomById(roomId).enableEncryption();
|
||||||
|
}
|
||||||
|
return roomId;
|
||||||
|
},
|
||||||
);
|
);
|
||||||
if (result.error == null) {
|
if (result.error == null) {
|
||||||
VRouter.of(context).toSegments(['rooms', result.result]);
|
VRouter.of(context).toSegments(['rooms', result.result]);
|
||||||
@ -81,8 +92,10 @@ class ProfileBottomSheet extends StatelessWidget {
|
|||||||
subtitle: Text(userId),
|
subtitle: Text(userId),
|
||||||
trailing: Icon(Icons.account_box_outlined),
|
trailing: Icon(Icons.account_box_outlined),
|
||||||
),
|
),
|
||||||
Center(
|
Container(
|
||||||
child: FloatingActionButton.extended(
|
width: double.infinity,
|
||||||
|
padding: EdgeInsets.all(12),
|
||||||
|
child: ElevatedButton.icon(
|
||||||
onPressed: () => _startDirectChat(context),
|
onPressed: () => _startDirectChat(context),
|
||||||
label: Text(L10n.of(context).newChat),
|
label: Text(L10n.of(context).newChat),
|
||||||
icon: Icon(Icons.send_outlined),
|
icon: Icon(Icons.send_outlined),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user