FurryChat/lib/views/chat.dart

757 lines
31 KiB
Dart
Raw Normal View History

2020-01-05 11:27:03 +00:00
import 'dart:async';
2020-01-01 18:10:13 +00:00
import 'dart:io';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:file_picker/file_picker.dart';
import 'package:fluffychat/components/adaptive_page_layout.dart';
import 'package:fluffychat/components/chat_settings_popup_menu.dart';
2020-03-15 10:27:51 +00:00
import 'package:fluffychat/components/dialogs/recording_dialog.dart';
2020-02-16 10:36:18 +00:00
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
2020-02-22 08:03:44 +00:00
import 'package:fluffychat/components/encryption_button.dart';
2020-01-01 18:10:13 +00:00
import 'package:fluffychat/components/list_items/message.dart';
import 'package:fluffychat/components/matrix.dart';
2020-02-11 11:49:39 +00:00
import 'package:fluffychat/components/reply_content.dart';
2020-05-07 05:52:40 +00:00
import 'package:fluffychat/l10n/l10n.dart';
2020-01-01 18:10:13 +00:00
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
2020-02-09 14:15:29 +00:00
import 'package:flutter/services.dart';
2020-04-12 07:19:22 +00:00
import 'package:flutter_styled_toast/flutter_styled_toast.dart';
2020-01-01 18:10:13 +00:00
import 'package:image_picker/image_picker.dart';
2020-01-24 11:10:35 +00:00
import 'package:pedantic/pedantic.dart';
2020-01-01 18:10:13 +00:00
import 'chat_list.dart';
2020-01-27 09:14:38 +00:00
class ChatView extends StatelessWidget {
2020-01-01 18:10:13 +00:00
final String id;
2020-01-27 09:14:38 +00:00
const ChatView(this.id, {Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
// TODO: implement build
return AdaptivePageLayout(
primaryPage: FocusPage.SECOND,
firstScaffold: ChatList(
activeChat: id,
),
secondScaffold: _Chat(id),
);
}
}
class _Chat extends StatefulWidget {
final String id;
const _Chat(this.id, {Key key}) : super(key: key);
2020-01-01 18:10:13 +00:00
@override
_ChatState createState() => _ChatState();
}
2020-01-27 09:14:38 +00:00
class _ChatState extends State<_Chat> {
2020-01-01 18:10:13 +00:00
Room room;
Timeline timeline;
2020-01-08 13:19:15 +00:00
MatrixState matrix;
2020-01-05 11:27:03 +00:00
String seenByText = "";
2020-01-02 21:31:39 +00:00
final ScrollController _scrollController = ScrollController();
2020-01-01 18:10:13 +00:00
2020-01-24 10:51:23 +00:00
FocusNode inputFocus = FocusNode();
2020-01-05 11:27:03 +00:00
Timer typingCoolDown;
Timer typingTimeout;
bool currentlyTyping = false;
2020-04-02 11:14:39 +00:00
List<Event> selectedEvents = [];
2020-02-09 14:15:29 +00:00
Event replyEvent;
2020-02-09 15:58:49 +00:00
bool showScrollDownButton = false;
2020-02-09 14:15:29 +00:00
bool get selectMode => selectedEvents.isNotEmpty;
2020-02-14 13:34:28 +00:00
bool _loadingHistory = false;
final int _loadHistoryCount = 100;
2020-02-22 08:03:44 +00:00
String inputText = "";
2020-05-09 07:30:03 +00:00
bool get _canLoadMore => timeline.events.last.type != EventTypes.RoomCreate;
2020-02-14 13:34:28 +00:00
void requestHistory() async {
2020-05-09 07:30:03 +00:00
if (_canLoadMore) {
2020-02-14 13:37:31 +00:00
setState(() => this._loadingHistory = true);
await timeline.requestHistory(historyCount: _loadHistoryCount);
2020-03-29 10:45:39 +00:00
if (mounted) setState(() => this._loadingHistory = false);
2020-02-14 13:37:31 +00:00
}
2020-02-14 13:34:28 +00:00
}
2020-01-01 18:10:13 +00:00
@override
void initState() {
_scrollController.addListener(() async {
if (_scrollController.position.pixels ==
2020-01-02 21:31:39 +00:00
_scrollController.position.maxScrollExtent &&
timeline.events.isNotEmpty &&
timeline.events[timeline.events.length - 1].type !=
EventTypes.RoomCreate) {
2020-02-14 13:34:28 +00:00
requestHistory();
2020-01-01 18:10:13 +00:00
}
2020-02-09 15:58:49 +00:00
if (_scrollController.position.pixels > 0 &&
showScrollDownButton == false) {
setState(() => showScrollDownButton = true);
} else if (_scrollController.position.pixels == 0 &&
showScrollDownButton == true) {
setState(() => showScrollDownButton = false);
}
2020-01-01 18:10:13 +00:00
});
super.initState();
}
2020-01-05 11:27:03 +00:00
void updateView() {
if (!mounted) return;
2020-01-05 11:27:03 +00:00
String seenByText = "";
if (timeline.events.isNotEmpty) {
List lastReceipts = List.from(timeline.events.first.receipts);
lastReceipts.removeWhere((r) =>
r.user.id == room.client.userID ||
r.user.id == timeline.events.first.senderId);
if (lastReceipts.length == 1) {
2020-05-07 05:52:40 +00:00
seenByText = L10n.of(context)
2020-01-20 12:46:39 +00:00
.seenByUser(lastReceipts.first.user.calcDisplayname());
2020-01-05 11:27:03 +00:00
} else if (lastReceipts.length == 2) {
2020-05-07 05:52:40 +00:00
seenByText = seenByText = L10n.of(context).seenByUserAndUser(
2020-01-20 12:46:39 +00:00
lastReceipts.first.user.calcDisplayname(),
lastReceipts[1].user.calcDisplayname());
2020-01-05 11:27:03 +00:00
} else if (lastReceipts.length > 2) {
2020-05-07 05:52:40 +00:00
seenByText = L10n.of(context).seenByUserAndCountOthers(
2020-01-20 12:46:39 +00:00
lastReceipts.first.user.calcDisplayname(),
(lastReceipts.length - 1).toString());
2020-01-05 11:27:03 +00:00
}
}
if (timeline != null) {
setState(() {
this.seenByText = seenByText;
});
}
2020-01-05 11:27:03 +00:00
}
Future<bool> getTimeline() async {
if (timeline == null) {
timeline = await room.getTimeline(onUpdate: updateView);
if (timeline.events.isNotEmpty) {
2020-01-24 11:10:35 +00:00
unawaited(room.sendReadReceipt(timeline.events.first.eventId));
}
2020-02-14 13:34:28 +00:00
if (timeline.events.length < _loadHistoryCount) {
this.requestHistory();
}
}
2020-01-05 11:27:03 +00:00
updateView();
2020-01-01 18:10:13 +00:00
return true;
}
@override
void dispose() {
2020-02-22 07:27:08 +00:00
timeline?.cancelSubscriptions();
timeline = null;
2020-01-08 13:19:15 +00:00
matrix.activeRoomId = "";
2020-01-01 18:10:13 +00:00
super.dispose();
}
2020-01-17 09:41:28 +00:00
TextEditingController sendController = TextEditingController();
2020-01-01 18:10:13 +00:00
void send() {
if (sendController.text.isEmpty) return;
2020-02-11 11:49:39 +00:00
room.sendTextEvent(sendController.text, inReplyTo: replyEvent);
sendController.text = "";
2020-02-09 14:15:29 +00:00
if (replyEvent != null) {
setState(() => replyEvent = null);
}
2020-02-23 07:52:28 +00:00
setState(() => inputText = "");
2020-01-01 18:10:13 +00:00
}
void sendFileAction(BuildContext context) async {
if (kIsWeb) {
2020-05-07 05:52:40 +00:00
showToast(L10n.of(context).notSupportedInWeb);
2020-03-29 10:06:25 +00:00
return;
2020-01-01 18:10:13 +00:00
}
File file = await FilePicker.getFile();
if (file == null) return;
2020-04-27 11:36:39 +00:00
await SimpleDialogs(context).tryRequestWithLoadingDialog(
2020-01-01 18:10:13 +00:00
room.sendFileEvent(
MatrixFile(bytes: await file.readAsBytes(), path: file.path),
),
);
}
void sendImageAction(BuildContext context) async {
if (kIsWeb) {
2020-05-07 05:52:40 +00:00
showToast(L10n.of(context).notSupportedInWeb);
2020-03-29 10:06:25 +00:00
return;
2020-01-01 18:10:13 +00:00
}
File file = await ImagePicker.pickImage(
source: ImageSource.gallery,
imageQuality: 50,
maxWidth: 1600,
maxHeight: 1600);
if (file == null) return;
2020-04-27 11:36:39 +00:00
await SimpleDialogs(context).tryRequestWithLoadingDialog(
2020-01-01 18:10:13 +00:00
room.sendImageEvent(
MatrixFile(bytes: await file.readAsBytes(), path: file.path),
),
);
}
void openCameraAction(BuildContext context) async {
if (kIsWeb) {
2020-05-07 05:52:40 +00:00
showToast(L10n.of(context).notSupportedInWeb);
2020-03-29 10:06:25 +00:00
return;
2020-01-01 18:10:13 +00:00
}
File file = await ImagePicker.pickImage(
source: ImageSource.camera,
imageQuality: 50,
maxWidth: 1600,
maxHeight: 1600);
if (file == null) return;
2020-04-27 11:36:39 +00:00
await SimpleDialogs(context).tryRequestWithLoadingDialog(
2020-01-01 18:10:13 +00:00
room.sendImageEvent(
MatrixFile(bytes: await file.readAsBytes(), path: file.path),
),
);
}
2020-03-15 10:27:51 +00:00
void voiceMessageAction(BuildContext context) async {
String result;
await showDialog(
context: context,
builder: (context) => RecordingDialog(
onFinished: (r) => result = r,
));
if (result == null) return;
final File audioFile = File(result);
2020-04-27 11:36:39 +00:00
await SimpleDialogs(context).tryRequestWithLoadingDialog(
2020-03-15 10:27:51 +00:00
room.sendAudioEvent(
MatrixFile(bytes: audioFile.readAsBytesSync(), path: audioFile.path),
),
);
}
2020-02-09 14:15:29 +00:00
String _getSelectedEventString(BuildContext context) {
String copyString = "";
2020-04-02 11:14:39 +00:00
if (selectedEvents.length == 1) {
2020-05-07 05:52:40 +00:00
return selectedEvents.first.getLocalizedBody(L10n.of(context));
2020-04-02 11:14:39 +00:00
}
2020-02-09 14:15:29 +00:00
for (Event event in selectedEvents) {
if (copyString.isNotEmpty) copyString += "\n\n";
2020-05-05 12:55:19 +00:00
copyString +=
2020-05-07 05:52:40 +00:00
event.getLocalizedBody(L10n.of(context), withSenderNamePrefix: true);
2020-02-09 14:15:29 +00:00
}
return copyString;
}
void copyEventsAction(BuildContext context) {
Clipboard.setData(ClipboardData(text: _getSelectedEventString(context)));
setState(() => selectedEvents.clear());
}
void redactEventsAction(BuildContext context) async {
2020-02-16 10:36:18 +00:00
bool confirmed = await SimpleDialogs(context).askConfirmation(
2020-05-07 05:52:40 +00:00
titleText: L10n.of(context).messageWillBeRemovedWarning,
confirmText: L10n.of(context).remove,
2020-02-09 14:15:29 +00:00
);
if (!confirmed) return;
for (Event event in selectedEvents) {
2020-04-27 11:36:39 +00:00
await SimpleDialogs(context).tryRequestWithLoadingDialog(
2020-02-09 14:15:29 +00:00
event.status > 0 ? event.redact() : event.remove());
}
setState(() => selectedEvents.clear());
}
bool get canRedactSelectedEvents {
for (Event event in selectedEvents) {
if (event.canRedact == false) return false;
}
return true;
}
void forwardEventsAction(BuildContext context) async {
if (selectedEvents.length == 1) {
Matrix.of(context).shareContent = selectedEvents.first.content;
} else {
Matrix.of(context).shareContent = {
"msgtype": "m.text",
"body": _getSelectedEventString(context),
};
}
setState(() => selectedEvents.clear());
Navigator.of(context).popUntil((r) => r.isFirst);
}
void sendAgainAction() {
selectedEvents.first.sendAgain();
setState(() => selectedEvents.clear());
}
void replyAction() {
setState(() {
replyEvent = selectedEvents.first;
selectedEvents.clear();
});
2020-02-16 10:36:18 +00:00
inputFocus.requestFocus();
2020-02-09 14:15:29 +00:00
}
2020-01-01 18:10:13 +00:00
@override
Widget build(BuildContext context) {
2020-01-08 13:19:15 +00:00
matrix = Matrix.of(context);
Client client = matrix.client;
2020-01-01 18:10:13 +00:00
room ??= client.getRoomById(widget.id);
2020-01-05 11:27:03 +00:00
if (room == null) {
2020-01-20 12:46:39 +00:00
return Scaffold(
appBar: AppBar(
2020-05-07 05:52:40 +00:00
title: Text(L10n.of(context).oopsSomethingWentWrong),
2020-01-20 12:46:39 +00:00
),
body: Center(
2020-05-07 05:52:40 +00:00
child: Text(L10n.of(context).youAreNoLongerParticipatingInThisChat),
2020-01-20 12:46:39 +00:00
),
2020-01-05 11:27:03 +00:00
);
}
2020-01-08 13:19:15 +00:00
matrix.activeRoomId = widget.id;
2020-01-05 11:27:03 +00:00
if (room.membership == Membership.invite) {
2020-04-27 11:36:39 +00:00
SimpleDialogs(context).tryRequestWithLoadingDialog(room.join());
2020-01-05 11:27:03 +00:00
}
2020-01-01 18:10:13 +00:00
2020-01-05 11:27:03 +00:00
String typingText = "";
List<User> typingUsers = room.typingUsers;
typingUsers.removeWhere((User u) => u.id == client.userID);
if (typingUsers.length == 1) {
2020-05-07 05:52:40 +00:00
typingText = L10n.of(context).isTyping;
2020-01-18 12:27:36 +00:00
if (typingUsers.first.id != room.directChatMatrixID) {
2020-01-20 12:46:39 +00:00
typingText =
2020-05-07 05:52:40 +00:00
L10n.of(context).userIsTyping(typingUsers.first.calcDisplayname());
2020-01-18 12:27:36 +00:00
}
2020-01-05 11:27:03 +00:00
} else if (typingUsers.length == 2) {
2020-05-07 05:52:40 +00:00
typingText = L10n.of(context).userAndUserAreTyping(
2020-01-20 12:46:39 +00:00
typingUsers.first.calcDisplayname(),
typingUsers[1].calcDisplayname());
2020-01-05 11:27:03 +00:00
} else if (typingUsers.length > 2) {
2020-05-07 05:52:40 +00:00
typingText = L10n.of(context).userAndOthersAreTyping(
2020-01-20 12:46:39 +00:00
typingUsers.first.calcDisplayname(),
(typingUsers.length - 1).toString());
2020-01-05 11:27:03 +00:00
}
2020-01-01 18:10:13 +00:00
2020-01-27 09:14:38 +00:00
return Scaffold(
appBar: AppBar(
2020-02-09 14:15:29 +00:00
leading: selectMode
? IconButton(
icon: Icon(Icons.close),
onPressed: () => setState(() => selectedEvents.clear()),
)
: null,
title: selectedEvents.isEmpty
? Column(
mainAxisSize: MainAxisSize.min,
2020-04-09 07:51:52 +00:00
crossAxisAlignment: !kIsWeb && Platform.isIOS
2020-04-05 07:52:56 +00:00
? CrossAxisAlignment.center
: CrossAxisAlignment.start,
2020-01-27 09:14:38 +00:00
children: <Widget>[
2020-05-07 05:52:40 +00:00
Text(room.getLocalizedDisplayname(L10n.of(context))),
2020-02-09 14:15:29 +00:00
AnimatedContainer(
duration: Duration(milliseconds: 500),
height: typingText.isEmpty ? 0 : 20,
child: Row(
children: <Widget>[
typingText.isEmpty
? Container()
: Icon(Icons.edit,
color: Theme.of(context).primaryColor,
2020-02-14 13:34:28 +00:00
size: 13),
2020-02-09 14:15:29 +00:00
SizedBox(width: 4),
Text(
typingText,
style: TextStyle(
color: Theme.of(context).primaryColor,
fontStyle: FontStyle.italic,
2020-02-14 13:34:28 +00:00
fontSize: 16,
2020-02-09 14:15:29 +00:00
),
),
],
2020-01-05 11:27:03 +00:00
),
2020-01-27 09:14:38 +00:00
),
],
2020-02-09 14:15:29 +00:00
)
2020-05-07 05:52:40 +00:00
: Text(L10n.of(context)
2020-02-09 14:15:29 +00:00
.numberSelected(selectedEvents.length.toString())),
actions: selectMode
? <Widget>[
IconButton(
icon: Icon(Icons.content_copy),
onPressed: () => copyEventsAction(context),
),
if (canRedactSelectedEvents)
IconButton(
icon: Icon(Icons.delete),
onPressed: () => redactEventsAction(context),
),
]
: <Widget>[ChatSettingsPopupMenu(room, !room.isDirectChat)],
2020-01-27 09:14:38 +00:00
),
2020-02-09 15:58:49 +00:00
floatingActionButton: showScrollDownButton
? Padding(
padding: const EdgeInsets.only(bottom: 56.0),
child: FloatingActionButton(
child: Icon(Icons.arrow_downward,
color: Theme.of(context).primaryColor),
onPressed: () => _scrollController.jumpTo(0),
2020-05-06 16:43:30 +00:00
foregroundColor: Theme.of(context).textTheme.bodyText2.color,
2020-02-09 15:58:49 +00:00
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
mini: true,
),
)
: null,
2020-02-14 13:34:28 +00:00
body: Stack(
children: <Widget>[
2020-04-03 18:24:25 +00:00
if (Matrix.of(context).wallpaper != null)
Opacity(
opacity: 0.66,
child: Image.file(
Matrix.of(context).wallpaper,
height: double.infinity,
width: double.infinity,
fit: BoxFit.cover,
),
2020-01-27 09:14:38 +00:00
),
2020-02-14 13:34:28 +00:00
SafeArea(
child: Column(
children: <Widget>[
2020-02-16 10:36:18 +00:00
if (_loadingHistory) LinearProgressIndicator(),
2020-02-14 13:34:28 +00:00
Expanded(
child: FutureBuilder<bool>(
future: getTimeline(),
builder: (BuildContext context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
if (room.notificationCount != null &&
room.notificationCount > 0 &&
timeline != null &&
timeline.events.isNotEmpty) {
room.sendReadReceipt(timeline.events.first.eventId);
}
if (timeline.events.isEmpty) return Container();
return ListView.builder(
reverse: true,
2020-05-09 07:30:03 +00:00
itemCount: timeline.events.length + 2,
2020-02-14 13:34:28 +00:00
controller: _scrollController,
itemBuilder: (BuildContext context, int i) {
2020-05-09 07:30:03 +00:00
return i == timeline.events.length + 1
? _canLoadMore
? FlatButton(
child: Text(
L10n.of(context).loadMore,
style: TextStyle(
color:
Theme.of(context).primaryColor,
fontWeight: FontWeight.bold,
decoration:
TextDecoration.underline,
),
),
onPressed: requestHistory,
)
: Container()
: i == 0
? AnimatedContainer(
height: seenByText.isEmpty ? 0 : 24,
duration: seenByText.isEmpty
? Duration(milliseconds: 0)
: Duration(milliseconds: 500),
alignment:
timeline.events.first.senderId ==
client.userID
? Alignment.topRight
: Alignment.topLeft,
child: Text(
seenByText,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color:
Theme.of(context).primaryColor,
),
),
padding: EdgeInsets.only(
left: 8,
right: 8,
bottom: 8,
),
)
: Message(timeline.events[i - 1],
onAvatarTab: (Event event) {
sendController.text +=
' ${event.senderId}';
}, onSelect: (Event event) {
if (!event.redacted) {
if (selectedEvents.contains(event)) {
setState(
() =>
selectedEvents.remove(event),
);
} else {
setState(
() => selectedEvents.add(event),
);
}
selectedEvents.sort(
(a, b) => a.time.compareTo(b.time),
);
}
},
longPressSelect: selectedEvents.isEmpty,
selected: selectedEvents
.contains(timeline.events[i - 1]),
timeline: timeline,
nextEvent: i >= 2
? timeline.events[i - 2]
: null);
2020-02-14 13:34:28 +00:00
});
},
),
),
AnimatedContainer(
duration: Duration(milliseconds: 300),
height: replyEvent != null ? 56 : 0,
child: Material(
color: Theme.of(context).secondaryHeaderColor,
child: Row(
children: <Widget>[
IconButton(
icon: Icon(Icons.close),
onPressed: () => setState(() => replyEvent = null),
),
Expanded(
child: ReplyContent(replyEvent),
2020-01-27 09:14:38 +00:00
),
],
),
2020-02-14 13:34:28 +00:00
),
),
2020-04-02 12:16:45 +00:00
Divider(
height: 1,
color: Theme.of(context).secondaryHeaderColor,
thickness: 1,
),
2020-02-14 13:34:28 +00:00
room.canSendDefaultMessages &&
room.membership == Membership.join
? Container(
decoration: BoxDecoration(
2020-04-03 18:24:25 +00:00
color: Theme.of(context)
.backgroundColor
.withOpacity(0.8),
2020-02-14 13:34:28 +00:00
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: selectMode
? <Widget>[
Container(
height: 56,
child: FlatButton(
onPressed: () =>
forwardEventsAction(context),
child: Row(
children: <Widget>[
Icon(Icons.keyboard_arrow_left),
2020-05-07 05:52:40 +00:00
Text(L10n.of(context).forward),
2020-02-14 13:34:28 +00:00
],
),
),
2020-01-27 09:14:38 +00:00
),
2020-02-14 13:34:28 +00:00
selectedEvents.length == 1
? selectedEvents.first.status > 0
? Container(
height: 56,
child: FlatButton(
onPressed: () => replyAction(),
child: Row(
children: <Widget>[
Text(
2020-05-07 05:52:40 +00:00
L10n.of(context).reply),
2020-02-14 13:34:28 +00:00
Icon(Icons
.keyboard_arrow_right),
],
),
),
)
: Container(
height: 56,
child: FlatButton(
onPressed: () =>
sendAgainAction(),
child: Row(
children: <Widget>[
2020-05-07 05:52:40 +00:00
Text(L10n.of(context)
2020-02-14 13:34:28 +00:00
.tryToSendAgain),
SizedBox(width: 4),
Icon(Icons.send, size: 16),
],
),
),
)
: Container(),
]
: <Widget>[
2020-02-22 08:03:44 +00:00
if (!kIsWeb && inputText.isEmpty)
PopupMenuButton<String>(
icon: Icon(Icons.add),
onSelected: (String choice) async {
if (choice == "file") {
sendFileAction(context);
} else if (choice == "image") {
sendImageAction(context);
}
if (choice == "camera") {
openCameraAction(context);
}
2020-03-15 10:27:51 +00:00
if (choice == "voice") {
voiceMessageAction(context);
}
2020-02-22 08:03:44 +00:00
},
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<String>>[
PopupMenuItem<String>(
value: "file",
child: ListTile(
leading: CircleAvatar(
backgroundColor: Colors.green,
foregroundColor: Colors.white,
child: Icon(Icons.attachment),
2020-02-09 14:15:29 +00:00
),
2020-02-22 08:03:44 +00:00
title:
2020-05-07 05:52:40 +00:00
Text(L10n.of(context).sendFile),
2020-02-22 08:03:44 +00:00
contentPadding: EdgeInsets.all(0),
),
),
PopupMenuItem<String>(
value: "image",
child: ListTile(
leading: CircleAvatar(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
child: Icon(Icons.image),
2020-02-09 14:15:29 +00:00
),
2020-02-22 08:03:44 +00:00
title: Text(
2020-05-07 05:52:40 +00:00
L10n.of(context).sendImage),
2020-02-22 08:03:44 +00:00
contentPadding: EdgeInsets.all(0),
),
2020-02-09 14:15:29 +00:00
),
2020-02-22 08:03:44 +00:00
PopupMenuItem<String>(
value: "camera",
child: ListTile(
leading: CircleAvatar(
backgroundColor: Colors.purple,
foregroundColor: Colors.white,
child: Icon(Icons.camera_alt),
2020-02-22 07:44:50 +00:00
),
2020-02-22 08:03:44 +00:00
title: Text(
2020-05-07 05:52:40 +00:00
L10n.of(context).openCamera),
2020-02-22 08:03:44 +00:00
contentPadding: EdgeInsets.all(0),
2020-02-22 07:44:50 +00:00
),
2020-02-22 08:03:44 +00:00
),
2020-03-15 10:27:51 +00:00
PopupMenuItem<String>(
value: "voice",
child: ListTile(
leading: CircleAvatar(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
child: Icon(Icons.mic),
),
title: Text(
2020-05-07 05:52:40 +00:00
L10n.of(context).voiceMessage),
2020-03-15 10:27:51 +00:00
contentPadding: EdgeInsets.all(0),
),
),
2020-02-22 08:03:44 +00:00
],
),
EncryptionButton(room),
2020-02-14 13:34:28 +00:00
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 4.0),
child: TextField(
minLines: 1,
maxLines: kIsWeb ? 1 : 8,
keyboardType: kIsWeb
? TextInputType.text
: TextInputType.multiline,
onSubmitted: (String text) {
send();
FocusScope.of(context)
.requestFocus(inputFocus);
},
focusNode: inputFocus,
controller: sendController,
decoration: InputDecoration(
hintText:
2020-05-07 05:52:40 +00:00
L10n.of(context).writeAMessage,
2020-02-14 13:34:28 +00:00
border: InputBorder.none,
2020-02-09 14:15:29 +00:00
),
2020-02-14 13:34:28 +00:00
onChanged: (String text) {
this.typingCoolDown?.cancel();
this.typingCoolDown =
Timer(Duration(seconds: 2), () {
this.typingCoolDown = null;
this.currentlyTyping = false;
room.sendTypingInfo(false);
});
this.typingTimeout ??=
Timer(Duration(seconds: 30), () {
this.typingTimeout = null;
this.currentlyTyping = false;
});
if (!this.currentlyTyping) {
this.currentlyTyping = true;
room.sendTypingInfo(true,
timeout: Duration(seconds: 30)
.inMilliseconds);
}
2020-02-22 08:03:44 +00:00
setState(() => inputText = text);
2020-02-14 13:34:28 +00:00
},
),
2020-01-05 11:27:03 +00:00
),
2020-01-27 09:14:38 +00:00
),
2020-03-15 10:27:51 +00:00
if (!kIsWeb && inputText.isEmpty)
IconButton(
icon: Icon(Icons.mic),
onPressed: () =>
voiceMessageAction(context),
),
if (kIsWeb || inputText.isNotEmpty)
IconButton(
icon: Icon(Icons.send),
onPressed: () => send(),
),
2020-02-14 13:34:28 +00:00
],
),
)
: Container(),
],
),
),
],
2020-01-01 18:10:13 +00:00
),
);
}
}