Merge pull request #39 from GetStream/feature/messageInputInitialMessage
add initialMessage property to MessageInput
This commit is contained in:
@@ -71,11 +71,15 @@ class MessageInput extends StatefulWidget {
|
|||||||
this.disableAttachments = false,
|
this.disableAttachments = false,
|
||||||
this.doImageUploadRequest,
|
this.doImageUploadRequest,
|
||||||
this.doFileUploadRequest,
|
this.doFileUploadRequest,
|
||||||
|
this.initialMessage,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Message to edit
|
/// Message to edit
|
||||||
final Message editMessage;
|
final Message editMessage;
|
||||||
|
|
||||||
|
/// Message to start with
|
||||||
|
final Message initialMessage;
|
||||||
|
|
||||||
/// Function called after sending the message
|
/// Function called after sending the message
|
||||||
final void Function(Message) onMessageSent;
|
final void Function(Message) onMessageSent;
|
||||||
|
|
||||||
@@ -763,7 +767,7 @@ class _MessageInputState extends State<MessageInput> {
|
|||||||
|
|
||||||
sendingFuture = StreamChat.of(context).client.updateMessage(message);
|
sendingFuture = StreamChat.of(context).client.updateMessage(message);
|
||||||
} else {
|
} else {
|
||||||
message = Message(
|
message = (widget.initialMessage ?? Message()).copyWith(
|
||||||
parentId: widget.parentMessage?.id,
|
parentId: widget.parentMessage?.id,
|
||||||
text: text,
|
text: text,
|
||||||
attachments: _getAttachments(attachments).toList(),
|
attachments: _getAttachments(attachments).toList(),
|
||||||
@@ -839,12 +843,21 @@ class _MessageInputState extends State<MessageInput> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (widget.editMessage != null) {
|
if (widget.editMessage != null) {
|
||||||
_textController = TextEditingController(text: widget.editMessage.text);
|
_parseExistingMessage(widget.editMessage);
|
||||||
|
} else if (widget.initialMessage != null) {
|
||||||
|
_parseExistingMessage(widget.initialMessage);
|
||||||
|
} else {
|
||||||
|
_textController = TextEditingController();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _parseExistingMessage(Message message) {
|
||||||
|
_textController = TextEditingController(text: message.text);
|
||||||
|
|
||||||
_typingStarted = true;
|
_typingStarted = true;
|
||||||
_messageIsPresent = true;
|
_messageIsPresent = true;
|
||||||
|
|
||||||
widget.editMessage.attachments.forEach((attachment) {
|
message.attachments?.forEach((attachment) {
|
||||||
if (attachment.type == 'image') {
|
if (attachment.type == 'image') {
|
||||||
_attachments.add(_SendingAttachment(
|
_attachments.add(_SendingAttachment(
|
||||||
type: FileType.image,
|
type: FileType.image,
|
||||||
@@ -868,9 +881,6 @@ class _MessageInputState extends State<MessageInput> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
_textController = TextEditingController();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
Reference in New Issue
Block a user