added option to react to messages
This commit is contained in:
parent
d067ee702a
commit
c4a7533315
@ -7,7 +7,7 @@ part 'sendMessageParams.g.dart';
|
||||
@JsonSerializable(explicitToJson: true, includeIfNull: false)
|
||||
class SendMessageParams extends ApiParams {
|
||||
String message;
|
||||
int? replyTo;
|
||||
String? replyTo;
|
||||
|
||||
SendMessageParams(this.message, {this.replyTo});
|
||||
|
||||
|
@ -9,7 +9,7 @@ part of 'sendMessageParams.dart';
|
||||
SendMessageParams _$SendMessageParamsFromJson(Map<String, dynamic> json) =>
|
||||
SendMessageParams(
|
||||
json['message'] as String,
|
||||
replyTo: json['replyTo'] as int?,
|
||||
replyTo: json['replyTo'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$SendMessageParamsToJson(SendMessageParams instance) {
|
||||
|
@ -10,6 +10,8 @@ class ChatProps extends DataHolder {
|
||||
GetChatResponse? _getChatResponse;
|
||||
GetChatResponse get getChatResponse => _getChatResponse!;
|
||||
|
||||
int? referenceMessageId;
|
||||
|
||||
@override
|
||||
List<ApiResponse?> properties() => [_getChatResponse];
|
||||
|
||||
@ -30,6 +32,11 @@ class ChatProps extends DataHolder {
|
||||
);
|
||||
}
|
||||
|
||||
void setReferenceMessageId(int? messageId) {
|
||||
referenceMessageId = messageId;
|
||||
run();
|
||||
}
|
||||
|
||||
void setQueryToken(String token) {
|
||||
_queryToken = token;
|
||||
_getChatResponse = null;
|
||||
|
@ -288,6 +288,11 @@ class _ChatBubbleState extends State<ChatBubble> {
|
||||
|
||||
children: [
|
||||
GestureDetector(
|
||||
onHorizontalDragEnd: (DragEndDetails details) {
|
||||
if(widget.bubbleData.isReplyable) {
|
||||
Provider.of<ChatProps>(context, listen: false).setReferenceMessageId(widget.bubbleData.id);
|
||||
}
|
||||
},
|
||||
onLongPress: showOptionsDialog,
|
||||
onDoubleTap: showOptionsDialog,
|
||||
onTap: () {
|
||||
|
@ -78,6 +78,7 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
settings = Provider.of<SettingsProvider>(context, listen: false);
|
||||
Provider.of<ChatProps>(context, listen: false).referenceMessageId = null;
|
||||
}
|
||||
|
||||
@override
|
||||
@ -91,7 +92,29 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
child: Container(
|
||||
padding: const EdgeInsets.only(left: 10, bottom: 3, top: 3, right: 10),
|
||||
width: double.infinity,
|
||||
child: Row(
|
||||
child: Column(
|
||||
children: [
|
||||
Consumer<ChatProps>(
|
||||
builder: (context, data, child) {
|
||||
// Text(data.referenceMessageId.toString());
|
||||
if(data.referenceMessageId != null) {
|
||||
var referenceMessage = data.getChatResponse.sortByTimestamp().where((element) => element.id == data.referenceMessageId).first;
|
||||
return Row(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () => data.setReferenceMessageId(null),
|
||||
icon: const Icon(Icons.close_outlined),
|
||||
padding: const EdgeInsets.only(left: 0),
|
||||
),
|
||||
Text(referenceMessage.message),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
},
|
||||
),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
GestureDetector(
|
||||
onTap: (){
|
||||
@ -170,7 +193,10 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
});
|
||||
SendMessage(widget.sendToToken, SendMessageParams(_textBoxController.text)).run().then((value) {
|
||||
SendMessage(widget.sendToToken, SendMessageParams(
|
||||
_textBoxController.text,
|
||||
replyTo: Provider.of<ChatProps>(context, listen: false).referenceMessageId.toString()
|
||||
)).run().then((value) {
|
||||
_query();
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
@ -178,6 +204,7 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
_textBoxController.text = '';
|
||||
setDraft('');
|
||||
});
|
||||
Provider.of<ChatProps>(context, listen: false).referenceMessageId = null;
|
||||
},
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
elevation: 5,
|
||||
@ -187,6 +214,9 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
),
|
||||
),
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user