跳到主要内容

对话与投票

对话

client.conversations API 处理对话会话——由 visibility: direct 帖子组成的话题线程。

获取会话列表

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);
}
}

返回 MastodonPage<MastodonConversation>。使用 nextMaxIdprevMinId 进行分页:

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);
}
}

分页参数:

参数说明
limit最大结果数(默认:20,上限:40)
maxId返回比此 ID 更旧的会话
sinceId返回比此 ID 更新的会话
minId返回紧接此 ID 之后的会话(顺序翻页)

将会话标记为已读

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

返回更新后的 MastodonConversation

删除会话

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

MastodonConversation 模型

字段类型说明
idString会话内部 ID
unreadbool是否有未读消息
accountsList<MastodonAccount>参与者(不含已认证用户)
lastStatusMastodonStatus?会话中最新的帖子,或 null

投票

client.polls API 用于获取投票和提交投票选项。投票通常附加在帖子上,可通过 status.poll 获取投票 ID。

获取投票

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"}');
}

参与投票

传入从 0 开始的选项索引列表。单选投票只传一个索引。

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

// 多选(当 poll.multiple == true 时允许)
final poll = await client.polls.vote('34', [0, 2]);

print(poll.voted); // true
print(poll.ownVotes); // 例如 [0, 2]

如果已认证用户已投过票,则抛出 MastodonAlreadyVotedException

MastodonPoll 模型

字段类型说明
idString投票内部 ID
expiresAtDateTime?到期时间戳
expiredbool投票是否已结束
multiplebool是否允许多选
votesCountint总投票数
votersCountint?唯一投票人数(多选时与 votesCount 不同)
optionsList<MastodonPollOption>可选项列表
emojisList<MastodonCustomEmoji>选项文字中使用的自定义表情
votedbool?已认证用户是否已投票
ownVotesList<int>?已认证用户投票的选项索引

MastodonPollOption 字段:

字段类型说明
titleString选项文字
votesCountint?该选项的票数;非公开投票时为 null