This commit is contained in:
Christian Pauly 2020-02-22 09:03:44 +01:00
parent 3ec2e9f9b5
commit 1a2c5c9380
2 changed files with 120 additions and 99 deletions

View 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),
),
),
);
});
}
}

View file

@ -6,6 +6,7 @@ import 'package:file_picker/file_picker.dart';
import 'package:fluffychat/components/adaptive_page_layout.dart';
import 'package:fluffychat/components/chat_settings_popup_menu.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/matrix.dart';
import 'package:fluffychat/components/reply_content.dart';
@ -80,6 +81,8 @@ class _ChatState extends State<_Chat> {
final int _loadHistoryCount = 100;
String inputText = "";
void requestHistory() async {
if (timeline.events.last.type != EventTypes.RoomCreate) {
setState(() => this._loadingHistory = true);
@ -550,9 +553,8 @@ class _ChatState extends State<_Chat> {
: Container(),
]
: <Widget>[
kIsWeb
? Container()
: PopupMenuButton<String>(
if (!kIsWeb && inputText.isEmpty)
PopupMenuButton<String>(
icon: Icon(Icons.add),
onSelected: (String choice) async {
if (choice == "file") {
@ -574,10 +576,9 @@ class _ChatState extends State<_Chat> {
foregroundColor: Colors.white,
child: Icon(Icons.attachment),
),
title: Text(
I18n.of(context).sendFile),
contentPadding:
EdgeInsets.all(0),
title:
Text(I18n.of(context).sendFile),
contentPadding: EdgeInsets.all(0),
),
),
PopupMenuItem<String>(
@ -590,68 +591,25 @@ class _ChatState extends State<_Chat> {
),
title: Text(
I18n.of(context).sendImage),
contentPadding:
EdgeInsets.all(0),
contentPadding: EdgeInsets.all(0),
),
),
PopupMenuItem<String>(
value: "camera",
child: ListTile(
leading: CircleAvatar(
backgroundColor:
Colors.purple,
backgroundColor: Colors.purple,
foregroundColor: Colors.white,
child: Icon(Icons.camera_alt),
),
title: Text(I18n.of(context)
.openCamera),
contentPadding:
EdgeInsets.all(0),
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(
icon: Icon(
room.encrypted
? Icons.lock
: Icons.lock_open,
size: 20,
color: color),
onPressed: () =>
Navigator.of(context).push(
AppRoute.defaultRoute(
context,
ChatEncryptionSettingsView(
widget.id),
),
),
);
}),
EncryptionButton(room),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(
@ -693,6 +651,7 @@ class _ChatState extends State<_Chat> {
timeout: Duration(seconds: 30)
.inMilliseconds);
}
setState(() => inputText = text);
},
),
),