알림
client.notifications API는 알림 조회, 삭제, 정책 관리 기능을 제공합니다.
알림 조회
목록 조회
final page = await client.notifications.fetch(limit: 20);
for (final n in page.items) {
print('${n.type}: ${n.account?.displayName}');
}
타입별 필터링
// 멘션과 좋아요만
final page = await client.notifications.fetch(
types: ['mention', 'favourite'],
);
// 팔로우를 제외한 모든 알림
final page = await client.notifications.fetch(
excludeTypes: ['follow'],
);
단일 알림 조회
final notification = await client.notifications.fetchById('12345');
알림 유형별 세부 정보
일부 v1 알림에는 추가 세부 정보가 포함됩니다.
final event = notification.relationshipSeveranceEvent; // severed_relationships
final report = notification.report; // admin.report
final wasFiltered = notification.filtered; // Mastodon 4.3+
서버는 값이 true일 때만 키를 포함하므로 filtered의 기본값은 false입니다.
그룹화된 v2 알림에서는 관계 단절 정보를 group.event, 신고를 group.report로
제공하지만 알림별 filtered 필드는 없습니다.
읽지 않은 알림 수 (Mastodon 4.3+)
final count = await client.notifications.fetchUnreadCount();
print(count.count);
알림 삭제
단일 삭제
await client.notifications.dismiss('12345');
전체 삭제
await client.notifications.clear();
알림 정책 (Mastodon 4.3+)
현재 정책 조회
final policy = await client.notifications.fetchPolicy();
print(policy.forNotFollowing); // accept, filter, drop
정책 업데이트
await client.notifications.updatePolicy(policy);
알림 요청 (Mastodon 4.3+)
정책 조건에 맞는 계정의 필터링된 알림은 요청으로 수집됩니다.
요청 목록 조회
final page = await client.notifications.fetchRequests(limit: 20);
수락 / 거절
// 단건
await client.notifications.acceptRequest('12345');
await client.notifications.dismissRequest('12345');
// 일괄
await client.notifications.acceptRequests(['1', '2', '3']);
await client.notifications.dismissRequests(['4', '5']);
병합 상태 확인
final merged = await client.notifications.checkRequestsMerged();
if (merged) {
// 수락된 요청이 알림 목록에 병합됨
}
그룹화된 알림 (v2)
그룹화된 알림 API를 사용하려면 client.groupedNotifications를 사용합니다:
final result = await client.groupedNotifications.fetch(limit: 20);
for (final group in result.notificationGroups) {
print('${group.type}: ${group.notificationsCount} notifications');
}