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/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,9 +553,8 @@ 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") {
@ -574,10 +576,9 @@ class _ChatState extends State<_Chat> {
foregroundColor: Colors.white, foregroundColor: Colors.white,
child: Icon(Icons.attachment), child: Icon(Icons.attachment),
), ),
title: Text( title:
I18n.of(context).sendFile), Text(I18n.of(context).sendFile),
contentPadding: contentPadding: EdgeInsets.all(0),
EdgeInsets.all(0),
), ),
), ),
PopupMenuItem<String>( PopupMenuItem<String>(
@ -590,68 +591,25 @@ class _ChatState extends State<_Chat> {
), ),
title: Text( title: Text(
I18n.of(context).sendImage), I18n.of(context).sendImage),
contentPadding: contentPadding: EdgeInsets.all(0),
EdgeInsets.all(0),
), ),
), ),
PopupMenuItem<String>( PopupMenuItem<String>(
value: "camera", value: "camera",
child: ListTile( child: ListTile(
leading: CircleAvatar( leading: CircleAvatar(
backgroundColor: backgroundColor: Colors.purple,
Colors.purple,
foregroundColor: Colors.white, foregroundColor: Colors.white,
child: Icon(Icons.camera_alt), child: Icon(Icons.camera_alt),
), ),
title: Text(I18n.of(context) title: Text(
.openCamera), I18n.of(context).openCamera),
contentPadding: contentPadding: EdgeInsets.all(0),
EdgeInsets.all(0),
), ),
), ),
], ],
), ),
FutureBuilder<List<DeviceKeys>>( EncryptionButton(room),
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),
),
),
);
}),
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);
}, },
), ),
), ),