跳到主要内容

列表

client.lists API 用于创建和管理列表、添加或移除账号,以及读取列表时间线。

获取列表

所有列表

final lists = await client.lists.fetch();
for (final list in lists) {
print('${list.id}: ${list.title}');
}

返回已认证用户拥有的所有列表,类型为 List<MastodonList>

单个列表

final list = await client.lists.fetchById('42');
print(list.title);
print(list.repliesPolicy); // "followed" | "list" | "none"
print(list.exclusive); // true 表示主页时间线排除列表成员

创建列表

final list = await client.lists.create(
title: 'Developer friends',
repliesPolicy: 'list', // 显示列表成员之间的回复
exclusive: false,
);
print(list.id);

repliesPolicy 接受:

  • followed — 显示对查看者所关注用户的回复
  • list — 显示对其他列表成员的回复
  • none — 隐藏所有回复

exclusivetrue 时,列表成员的帖子将从主页时间线中排除。

更新列表

final updated = await client.lists.update(
'42',
title: 'Close friends',
repliesPolicy: 'followed',
exclusive: true,
);

删除列表

await client.lists.delete('42');

管理账号

获取列表中的账号

final page = await client.lists.fetchAccounts(
'42',
limit: 40,
);

for (final account in page.items) {
print(account.acct);
}

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

MastodonPage<MastodonAccount>? page = await client.lists.fetchAccounts('42');

while (page != null && page.nextMaxId != null) {
page = await client.lists.fetchAccounts(
'42',
maxId: page.nextMaxId,
);
for (final account in page.items) {
print(account.acct);
}
}

分页参数:

参数说明
limit最大结果数(默认:40,上限:80;传 0 获取全部)
maxId返回比此 ID 更旧的结果
sinceId返回比此 ID 更新的结果
minId返回紧接此 ID 之后的结果(顺序翻页)

添加账号

添加的账号必须是已认证用户所关注的。

await client.lists.addAccounts(
'42',
accountIds: ['100', '101', '102'],
);

移除账号

await client.lists.removeAccounts(
'42',
accountIds: ['101'],
);

MastodonList 模型

字段类型说明
idString列表内部 ID
titleString列表标题
repliesPolicyString回复显示策略(followed / list / none
exclusivebool列表成员是否从主页时间线排除