Clean up
This commit is contained in:
parent
3ec2e9f9b5
commit
1a2c5c9380
62
lib/components/encryption_button.dart
Normal file
62
lib/components/encryption_button.dart
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:famedlysdk/famedlysdk.dart';
|
||||||
|
import 'package:fluffychat/utils/app_route.dart';
|
||||||
|
import 'package:fluffychat/views/chat_encryption_settings.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'matrix.dart';
|
||||||
|
|
||||||
|
class EncryptionButton extends StatefulWidget {
|
||||||
|
final Room room;
|
||||||
|
const EncryptionButton(this.room, {Key key}) : super(key: key);
|
||||||
|
@override
|
||||||
|
_EncryptionButtonState createState() => _EncryptionButtonState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _EncryptionButtonState extends State<EncryptionButton> {
|
||||||
|
StreamSubscription _onSyncSub;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_onSyncSub?.cancel();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
_onSyncSub ??= Matrix.of(context)
|
||||||
|
.client
|
||||||
|
.onSync
|
||||||
|
.stream
|
||||||
|
.listen((s) => setState(() => null));
|
||||||
|
return FutureBuilder<List<DeviceKeys>>(
|
||||||
|
future: widget.room.getUserDeviceKeys(),
|
||||||
|
builder: (BuildContext context, snapshot) {
|
||||||
|
Color color;
|
||||||
|
if (widget.room.encrypted && snapshot.hasData) {
|
||||||
|
final List<DeviceKeys> deviceKeysList = snapshot.data;
|
||||||
|
color = Colors.orange;
|
||||||
|
if (deviceKeysList.indexWhere((DeviceKeys deviceKeys) =>
|
||||||
|
deviceKeys.verified == false &&
|
||||||
|
deviceKeys.blocked == false) ==
|
||||||
|
-1) {
|
||||||
|
color = Colors.black.withGreen(220).withOpacity(0.75);
|
||||||
|
}
|
||||||
|
} else if (!widget.room.encrypted &&
|
||||||
|
widget.room.joinRules != JoinRules.public) {
|
||||||
|
color = null;
|
||||||
|
}
|
||||||
|
return IconButton(
|
||||||
|
icon: Icon(widget.room.encrypted ? Icons.lock : Icons.lock_open,
|
||||||
|
size: 20, color: color),
|
||||||
|
onPressed: () => Navigator.of(context).push(
|
||||||
|
AppRoute.defaultRoute(
|
||||||
|
context,
|
||||||
|
ChatEncryptionSettingsView(widget.room.id),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:fluffychat/components/adaptive_page_layout.dart';
|
import 'package:fluffychat/components/adaptive_page_layout.dart';
|
||||||
import 'package:fluffychat/components/chat_settings_popup_menu.dart';
|
import 'package:fluffychat/components/chat_settings_popup_menu.dart';
|
||||||
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
||||||
|
import 'package:fluffychat/components/encryption_button.dart';
|
||||||
import 'package:fluffychat/components/list_items/message.dart';
|
import 'package:fluffychat/components/list_items/message.dart';
|
||||||
import 'package:fluffychat/components/matrix.dart';
|
import 'package:fluffychat/components/matrix.dart';
|
||||||
import 'package:fluffychat/components/reply_content.dart';
|
import 'package:fluffychat/components/reply_content.dart';
|
||||||
|
@ -80,6 +81,8 @@ class _ChatState extends State<_Chat> {
|
||||||
|
|
||||||
final int _loadHistoryCount = 100;
|
final int _loadHistoryCount = 100;
|
||||||
|
|
||||||
|
String inputText = "";
|
||||||
|
|
||||||
void requestHistory() async {
|
void requestHistory() async {
|
||||||
if (timeline.events.last.type != EventTypes.RoomCreate) {
|
if (timeline.events.last.type != EventTypes.RoomCreate) {
|
||||||
setState(() => this._loadingHistory = true);
|
setState(() => this._loadingHistory = true);
|
||||||
|
@ -550,108 +553,63 @@ class _ChatState extends State<_Chat> {
|
||||||
: Container(),
|
: Container(),
|
||||||
]
|
]
|
||||||
: <Widget>[
|
: <Widget>[
|
||||||
kIsWeb
|
if (!kIsWeb && inputText.isEmpty)
|
||||||
? Container()
|
PopupMenuButton<String>(
|
||||||
: PopupMenuButton<String>(
|
icon: Icon(Icons.add),
|
||||||
icon: Icon(Icons.add),
|
onSelected: (String choice) async {
|
||||||
onSelected: (String choice) async {
|
if (choice == "file") {
|
||||||
if (choice == "file") {
|
sendFileAction(context);
|
||||||
sendFileAction(context);
|
} else if (choice == "image") {
|
||||||
} else if (choice == "image") {
|
sendImageAction(context);
|
||||||
sendImageAction(context);
|
|
||||||
}
|
|
||||||
if (choice == "camera") {
|
|
||||||
openCameraAction(context);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
itemBuilder: (BuildContext context) =>
|
|
||||||
<PopupMenuEntry<String>>[
|
|
||||||
PopupMenuItem<String>(
|
|
||||||
value: "file",
|
|
||||||
child: ListTile(
|
|
||||||
leading: CircleAvatar(
|
|
||||||
backgroundColor: Colors.green,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
child: Icon(Icons.attachment),
|
|
||||||
),
|
|
||||||
title: Text(
|
|
||||||
I18n.of(context).sendFile),
|
|
||||||
contentPadding:
|
|
||||||
EdgeInsets.all(0),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
PopupMenuItem<String>(
|
|
||||||
value: "image",
|
|
||||||
child: ListTile(
|
|
||||||
leading: CircleAvatar(
|
|
||||||
backgroundColor: Colors.blue,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
child: Icon(Icons.image),
|
|
||||||
),
|
|
||||||
title: Text(
|
|
||||||
I18n.of(context).sendImage),
|
|
||||||
contentPadding:
|
|
||||||
EdgeInsets.all(0),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
PopupMenuItem<String>(
|
|
||||||
value: "camera",
|
|
||||||
child: ListTile(
|
|
||||||
leading: CircleAvatar(
|
|
||||||
backgroundColor:
|
|
||||||
Colors.purple,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
child: Icon(Icons.camera_alt),
|
|
||||||
),
|
|
||||||
title: Text(I18n.of(context)
|
|
||||||
.openCamera),
|
|
||||||
contentPadding:
|
|
||||||
EdgeInsets.all(0),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
FutureBuilder<List<DeviceKeys>>(
|
|
||||||
future: room.getUserDeviceKeys(),
|
|
||||||
builder:
|
|
||||||
(BuildContext context, snapshot) {
|
|
||||||
Color color;
|
|
||||||
if (room.encrypted &&
|
|
||||||
snapshot.hasData) {
|
|
||||||
final List<DeviceKeys>
|
|
||||||
deviceKeysList = snapshot.data;
|
|
||||||
color = Colors.orange;
|
|
||||||
if (deviceKeysList.indexWhere(
|
|
||||||
(DeviceKeys deviceKeys) =>
|
|
||||||
deviceKeys.verified ==
|
|
||||||
false &&
|
|
||||||
deviceKeys.blocked ==
|
|
||||||
false) ==
|
|
||||||
-1) {
|
|
||||||
color = Colors.green[700];
|
|
||||||
}
|
|
||||||
} else if (!room.encrypted &&
|
|
||||||
room.joinRules !=
|
|
||||||
JoinRules.public) {
|
|
||||||
color = Colors.red;
|
|
||||||
}
|
}
|
||||||
return IconButton(
|
if (choice == "camera") {
|
||||||
icon: Icon(
|
openCameraAction(context);
|
||||||
room.encrypted
|
}
|
||||||
? Icons.lock
|
},
|
||||||
: Icons.lock_open,
|
itemBuilder: (BuildContext context) =>
|
||||||
size: 20,
|
<PopupMenuEntry<String>>[
|
||||||
color: color),
|
PopupMenuItem<String>(
|
||||||
onPressed: () =>
|
value: "file",
|
||||||
Navigator.of(context).push(
|
child: ListTile(
|
||||||
AppRoute.defaultRoute(
|
leading: CircleAvatar(
|
||||||
context,
|
backgroundColor: Colors.green,
|
||||||
ChatEncryptionSettingsView(
|
foregroundColor: Colors.white,
|
||||||
widget.id),
|
child: Icon(Icons.attachment),
|
||||||
),
|
),
|
||||||
|
title:
|
||||||
|
Text(I18n.of(context).sendFile),
|
||||||
|
contentPadding: EdgeInsets.all(0),
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
}),
|
PopupMenuItem<String>(
|
||||||
|
value: "image",
|
||||||
|
child: ListTile(
|
||||||
|
leading: CircleAvatar(
|
||||||
|
backgroundColor: Colors.blue,
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
child: Icon(Icons.image),
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
I18n.of(context).sendImage),
|
||||||
|
contentPadding: EdgeInsets.all(0),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
PopupMenuItem<String>(
|
||||||
|
value: "camera",
|
||||||
|
child: ListTile(
|
||||||
|
leading: CircleAvatar(
|
||||||
|
backgroundColor: Colors.purple,
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
child: Icon(Icons.camera_alt),
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
I18n.of(context).openCamera),
|
||||||
|
contentPadding: EdgeInsets.all(0),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
EncryptionButton(room),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
|
@ -693,6 +651,7 @@ class _ChatState extends State<_Chat> {
|
||||||
timeout: Duration(seconds: 30)
|
timeout: Duration(seconds: 30)
|
||||||
.inMilliseconds);
|
.inMilliseconds);
|
||||||
}
|
}
|
||||||
|
setState(() => inputText = text);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue