feat: Store drafts

This commit is contained in:
Krille Fear 2022-12-30 13:32:39 +01:00
parent abb99df271
commit 1e1e591d27
2 changed files with 22 additions and 0 deletions

View File

@ -10,6 +10,7 @@
- feat: Add audio message support to linux (Krille Fear) - feat: Add audio message support to linux (Krille Fear)
- feat: Use Android system accent color (Krille Fear) - feat: Use Android system accent color (Krille Fear)
- feat: include olm to Windows builds (TheOneWithTheBraid) - feat: include olm to Windows builds (TheOneWithTheBraid)
- feat: Store drafts (Krille)
- fix: Android push notification follow-up (TheOneWithTheBraid) - fix: Android push notification follow-up (TheOneWithTheBraid)
- fix: Content banner (Krille Fear) - fix: Content banner (Krille Fear)
- fix: Correct redacted by username (Krille Fear) - fix: Correct redacted by username (Krille Fear)

View File

@ -16,6 +16,7 @@ import 'package:image_picker/image_picker.dart';
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
import 'package:record/record.dart'; import 'package:record/record.dart';
import 'package:scroll_to_index/scroll_to_index.dart'; import 'package:scroll_to_index/scroll_to_index.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:vrouter/vrouter.dart'; import 'package:vrouter/vrouter.dart';
import 'package:fluffychat/pages/chat/chat_view.dart'; import 'package:fluffychat/pages/chat/chat_view.dart';
@ -172,10 +173,20 @@ class ChatController extends State<Chat> {
} }
} }
void _loadDraft() async {
final prefs = await SharedPreferences.getInstance();
final draft = prefs.getString('draft_$roomId');
if (draft != null && draft.isNotEmpty) {
sendController.text = draft;
setState(() => inputText = draft);
}
}
@override @override
void initState() { void initState() {
scrollController.addListener(_updateScrollController); scrollController.addListener(_updateScrollController);
inputFocus.addListener(_inputFocusListener); inputFocus.addListener(_inputFocusListener);
_loadDraft();
super.initState(); super.initState();
} }
@ -257,6 +268,8 @@ class ChatController extends State<Chat> {
Future<void> send() async { Future<void> send() async {
if (sendController.text.trim().isEmpty) return; if (sendController.text.trim().isEmpty) return;
final prefs = await SharedPreferences.getInstance();
prefs.remove('draft_$roomId');
var parseCommands = true; var parseCommands = true;
final commandMatch = RegExp(r'^\/(\w+)').firstMatch(sendController.text); final commandMatch = RegExp(r'^\/(\w+)').firstMatch(sendController.text);
@ -920,7 +933,15 @@ class ChatController extends State<Chat> {
); );
} }
Timer? _storeInputTimeoutTimer;
static const Duration _storeInputTimeout = Duration(milliseconds: 500);
void onInputBarChanged(String text) { void onInputBarChanged(String text) {
_storeInputTimeoutTimer?.cancel();
_storeInputTimeoutTimer = Timer(_storeInputTimeout, () async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString('draft_$roomId', text);
});
setReadMarker(); setReadMarker();
if (text.endsWith(' ') && matrix!.hasComplexBundles) { if (text.endsWith(' ') && matrix!.hasComplexBundles) {
final clients = currentRoomBundle; final clients = currentRoomBundle;