cwtch-ui/lib/models/message_draft.dart

74 lines
1.6 KiB
Dart
Raw Permalink Normal View History

import 'package:flutter/cupertino.dart';
2023-03-20 20:13:31 +00:00
/// A "MessageDraft" structure that stores information about in-progress message drafts.
/// MessageDraft stores text, quoted replies, and attached images.
/// Only one draft is stored per conversation.
class MessageDraft extends ChangeNotifier {
QuotedReference? _quotedReference;
2023-09-25 21:40:48 +00:00
int? _inviteHandle;
TextEditingController ctrlCompose = TextEditingController();
2023-03-20 20:13:31 +00:00
static MessageDraft empty() {
return MessageDraft();
}
2023-03-27 22:27:43 +00:00
bool isEmpty() {
return (this._quotedReference == null) || (this.messageText.isEmpty);
2023-03-20 20:13:31 +00:00
}
String get messageText => ctrlCompose.text;
2023-03-20 20:13:31 +00:00
set messageText(String text) {
this.ctrlCompose.text = text;
2023-03-20 20:13:31 +00:00
notifyListeners();
}
set quotedReference(int index) {
this._quotedReference = QuotedReference(index);
notifyListeners();
}
2023-09-25 21:40:48 +00:00
void attachInvite(int handle) {
this._inviteHandle = handle;
notifyListeners();
}
int? getInviteHandle() {
return this._inviteHandle;
}
2023-03-20 20:13:31 +00:00
QuotedReference? getQuotedMessage() {
return this._quotedReference;
}
void clearQuotedReference() {
this._quotedReference = null;
notifyListeners();
}
void clearDraft() {
this._quotedReference = null;
this.ctrlCompose.clear();
2024-03-20 19:34:26 +00:00
this.ctrlCompose.clearComposing();
this.ctrlCompose.text = "";
2023-09-25 21:40:48 +00:00
this._inviteHandle = null;
notifyListeners();
}
@override
void dispose() {
ctrlCompose.dispose();
super.dispose();
}
2023-09-25 21:40:48 +00:00
void clearInvite() {
this._inviteHandle = null;
}
2023-03-20 20:13:31 +00:00
}
/// A QuotedReference encapsulates the state of replied-to message.
class QuotedReference {
int index;
QuotedReference(this.index);
}