Skip to main content

Conversations and Polls

Conversations​

The client.conversations API handles direct message conversations — threads that consist of statuses with visibility: direct.

Fetching conversations​

final page = await client.conversations.fetch(limit: 20);

for (final conversation in page.items) {
print(conversation.id);
print(conversation.unread);
print(conversation.accounts.map((a) => a.acct).join(', '));
if (conversation.lastStatus != null) {
print(conversation.lastStatus!.content);
}
}

Returns MastodonPage<MastodonConversation>. Use nextMaxId and prevMinId for pagination:

MastodonPage<MastodonConversation>? page = await client.conversations.fetch();

while (page != null && page.nextMaxId != null) {
page = await client.conversations.fetch(maxId: page.nextMaxId);
for (final conversation in page.items) {
print(conversation.id);
}
}

Pagination parameters:

ParameterDescription
limitMaximum results (default: 20, max: 40)
maxIdReturn conversations older than this ID
sinceIdReturn conversations newer than this ID
minIdReturn conversations immediately after this ID (forward pagination)

Marking a conversation as read​

final conversation = await client.conversations.markAsRead('7');
print(conversation.unread); // false

Returns the updated MastodonConversation.

Deleting a conversation​

await client.conversations.delete('7');

The MastodonConversation model​

FieldTypeDescription
idStringInternal conversation ID
unreadboolWhether the conversation has unread messages
accountsList<MastodonAccount>Participants (excluding the authenticated user)
lastStatusMastodonStatus?Most recent status in the conversation, or null

Polls​

The client.polls API lets you fetch polls and submit votes. Polls are typically attached to statuses; use status.poll to get the poll ID.

Fetching a poll​

final poll = await client.polls.fetch('34');
print(poll.votesCount);
print(poll.expired);

for (final option in poll.options) {
print('${option.title}: ${option.votesCount ?? "hidden"}');
}

Voting on a poll​

Pass a list of zero-based option indices. For single-choice polls, pass exactly one index.

// Single choice
final poll = await client.polls.vote('34', [0]);

// Multiple choices (allowed when poll.multiple == true)
final poll = await client.polls.vote('34', [0, 2]);

print(poll.voted); // true
print(poll.ownVotes); // e.g. [0, 2]

Throws MastodonAlreadyVotedException if the authenticated user has already voted.

The MastodonPoll model​

FieldTypeDescription
idStringInternal poll ID
expiresAtDateTime?Expiration timestamp
expiredboolWhether the poll has ended
multipleboolWhether multiple choices are allowed
votesCountintTotal number of votes cast
votersCountint?Number of unique voters (differs from votesCount for multiple-choice polls)
optionsList<MastodonPollOption>Available options
emojisList<MastodonCustomEmoji>Custom emojis used in option text
votedbool?Whether the authenticated user has voted
ownVotesList<int>?Indices of options the authenticated user voted for

MastodonPollOption fields:

FieldTypeDescription
titleStringOption text
votesCountint?Votes for this option; null for non-public polls