2023-05-18 18:15:13 +00:00
|
|
|
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;
|
2023-05-18 18:15:13 +00:00
|
|
|
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() {
|
2023-05-18 18:15:13 +00:00
|
|
|
return (this._quotedReference == null) || (this.messageText.isEmpty);
|
2023-03-20 20:13:31 +00:00
|
|
|
}
|
|
|
|
|
2023-05-18 18:15:13 +00:00
|
|
|
String get messageText => ctrlCompose.text;
|
2023-03-20 20:13:31 +00:00
|
|
|
|
2023-05-18 18:15:13 +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();
|
|
|
|
}
|
2023-05-18 18:15:13 +00:00
|
|
|
|
|
|
|
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;
|
2023-05-18 18:15:13 +00:00
|
|
|
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);
|
|
|
|
}
|