Files
stream-chat-flutter/docusaurus/docs/Flutter/stream_chat/threads_and_replies.mdx
T
2021-06-17 15:06:01 +05:30

54 lines
1.9 KiB
Plaintext

---
id: threads_and_replies
sidebar_position: 19
title: Threads And Replies
---
Threads and replies provide your users with a way to go into more detail about a specific topic.
This can be very helpful to keep the conversation organized and reduce noise.
To create a thread you simply send a message with a `parent_id`. Have a look at the example below:
```dart
final reply = await channel.sendMessage(
Message(text: 'Hey, I am replying to a message!',
parentId: parentID,
showInChannel: false,
));
```
If you specify `show_in_channel`, the message will be visible both in a thread of replies as well as the main channel.
Messages inside a thread can also have reactions, attachments and mention as any other message.
### Thread Pagination
When you read a channel you do not receive messages inside threads.
The parent message includes the count of replies which it is usually what apps show as the link to the thread screen.
Reading a thread and paginating its messages works in a very similar way as paginating a channel.
```dart
// retrieve the first 20 messages inside the thread
await channel.getReplies(parentMessageId, PaginationParams(limit: 20));
// retrieve the 20 more messages before the message with id "42"
await channel.getReplies(parentMessageId, PaginationParams(limit: 20, lessThanOrEqual: '42'));
```
### Quote Message
Instead of replying in a thread, it's also possible to quote a message. Quoting a message doesn't result in the creation of a thread;
the message is quoted inline.
To quote a message, simply provide the `quoted_message_id` field when sending a message:
```dart
// Create the initial message
await channel.sendMessage(Message(id: 'first_message_id', text: 'The initial message' ));
// Quote the initial message
final res = await channel.sendMessage(Message(
id: 'message_with_quoted_message',
text: 'This is the first message that quotes another message',
quotedMessageId: 'first_message_id',
));
```