Merge pull request #39 from GetStream/feature/messageInputInitialMessage
add initialMessage property to MessageInput
This commit is contained in:
+40
-30
@@ -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,40 +843,46 @@ 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) {
|
||||||
_typingStarted = true;
|
_parseExistingMessage(widget.initialMessage);
|
||||||
_messageIsPresent = true;
|
|
||||||
|
|
||||||
widget.editMessage.attachments.forEach((attachment) {
|
|
||||||
if (attachment.type == 'image') {
|
|
||||||
_attachments.add(_SendingAttachment(
|
|
||||||
type: FileType.image,
|
|
||||||
url: attachment.imageUrl ??
|
|
||||||
attachment.assetUrl ??
|
|
||||||
attachment.thumbUrl ??
|
|
||||||
attachment.ogScrapeUrl,
|
|
||||||
uploaded: true,
|
|
||||||
));
|
|
||||||
} else if (attachment.type == 'video') {
|
|
||||||
_attachments.add(_SendingAttachment(
|
|
||||||
type: FileType.video,
|
|
||||||
url: attachment.assetUrl,
|
|
||||||
uploaded: true,
|
|
||||||
));
|
|
||||||
} else if (attachment.type != 'giphy') {
|
|
||||||
_attachments.add(_SendingAttachment(
|
|
||||||
type: FileType.any,
|
|
||||||
url: attachment.assetUrl,
|
|
||||||
uploaded: true,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
_textController = TextEditingController();
|
_textController = TextEditingController();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _parseExistingMessage(Message message) {
|
||||||
|
_textController = TextEditingController(text: message.text);
|
||||||
|
|
||||||
|
_typingStarted = true;
|
||||||
|
_messageIsPresent = true;
|
||||||
|
|
||||||
|
message.attachments?.forEach((attachment) {
|
||||||
|
if (attachment.type == 'image') {
|
||||||
|
_attachments.add(_SendingAttachment(
|
||||||
|
type: FileType.image,
|
||||||
|
url: attachment.imageUrl ??
|
||||||
|
attachment.assetUrl ??
|
||||||
|
attachment.thumbUrl ??
|
||||||
|
attachment.ogScrapeUrl,
|
||||||
|
uploaded: true,
|
||||||
|
));
|
||||||
|
} else if (attachment.type == 'video') {
|
||||||
|
_attachments.add(_SendingAttachment(
|
||||||
|
type: FileType.video,
|
||||||
|
url: attachment.assetUrl,
|
||||||
|
uploaded: true,
|
||||||
|
));
|
||||||
|
} else if (attachment.type != 'giphy') {
|
||||||
|
_attachments.add(_SendingAttachment(
|
||||||
|
type: FileType.any,
|
||||||
|
url: attachment.assetUrl,
|
||||||
|
uploaded: true,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_commandsOverlay?.remove();
|
_commandsOverlay?.remove();
|
||||||
|
|||||||
Reference in New Issue
Block a user