conversations method
Stream<ModmailConversation>
conversations({
- String? after,
- int? limit,
- List<
SubredditRef> ? otherSubreddits, - ModmailSort sort = ModmailSort.recent,
- ModmailState state = ModmailState.all,
A Stream of ModmailConversation
instances for the specified
subreddits.
after
: A base36 modmail conversation id. When provided, the limiting
begins after this conversation.
limit
: The maximum number of conversations to fetch. If not provided,
the server-side default is 25 at the time of writing.
otherSubreddits
: A list of other subreddits for which conversations
should be fetched.
sort
: Determines the order that the conversations will be sorted.
state
:
Implementation
Stream<ModmailConversation> conversations(
{String? after,
int? limit,
List<SubredditRef>? otherSubreddits,
ModmailSort sort = ModmailSort.recent,
ModmailState state = ModmailState.all}) async* {
final params = <String, String>{};
if (_subreddit.displayName != 'all') {
params['entity'] = _buildSubredditList(otherSubreddits);
}
if (after != null) {
params['after'] = after;
}
if (limit != null) {
params['limit'] = limit.toString();
}
params['sort'] = modmailSortToString(sort);
params['state'] = modmailStateToString(state);
final response = (await _subreddit.reddit
.get(apiPath['modmail_conversations'], params: params))
as Map<String, dynamic>;
final ids = (response['conversationIds'] as List).cast<String>();
for (final id in ids) {
final data = {
'conversation': response['conversations'][id],
'messages': response['messages']
};
yield ModmailConversation.parse(_subreddit.reddit, data,
convertObjects: true);
}
}