|
| 1 | +import { type Account } from "./account"; |
| 2 | +import { type AccountWarning } from "./account-warning"; |
| 3 | +import { type RelationshipSeveranceEvent } from "./relationship-severance-event"; |
| 4 | +import { type Report } from "./report"; |
| 5 | +import { type Status } from "./status"; |
| 6 | + |
| 7 | +export interface GroupedNotificationsResults { |
| 8 | + /** Accounts referenced by grouped notifications. */ |
| 9 | + accounts: Account[]; |
| 10 | + /** Partial accounts referenced by grouped notifications. Those are only returned when requesting grouped notifications with `expand_accounts=partial_avatars`. */ |
| 11 | + partialAccounts?: PartialAccountWithAvatar[]; |
| 12 | + /** Statuses referenced by grouped notifications. */ |
| 13 | + statuses: Status[]; |
| 14 | + /** The grouped notifications themselves. */ |
| 15 | + notificationGroups: NotificationGroup[]; |
| 16 | +} |
| 17 | + |
| 18 | +/** These are stripped-down versions of {@link Account} that only contain what is necessary to display a list of avatars, as well as a few other useful properties. The aim is to cut back on expensive server-side serialization and reduce the network payload size of notification groups. */ |
| 19 | +export type PartialAccountWithAvatar = Pick< |
| 20 | + Account, |
| 21 | + "id" | "acct" | "url" | "avatar" | "avatarStatic" | "locked" | "bot" |
| 22 | +>; |
| 23 | + |
| 24 | +interface BaseNotificationGroup<T> { |
| 25 | + /** Group key identifying the grouped notifications. Should be treated as an opaque value. */ |
| 26 | + groupKey: string; |
| 27 | + /** Total number of individual notifications that are part of this notification group. */ |
| 28 | + notificationsCount: number; |
| 29 | + /** The type of event that resulted in the notifications in this group. */ |
| 30 | + type: T; |
| 31 | + /** ID of the most recent notification in the group. */ |
| 32 | + mostRecentNotificationId: string; |
| 33 | + /** ID of the oldest notification from this group represented within the current page. This is only returned when paginating through notification groups. Useful when polling new notifications. */ |
| 34 | + pageMinId?: string; |
| 35 | + /** ID of the newest notification from this group represented within the current page. This is only returned when paginating through notification groups. Useful when polling new notifications. */ |
| 36 | + pageMaxId?: string; |
| 37 | + /** Date at which the most recent notification from this group within the current page has been created. This is only returned when paginating through notification groups. */ |
| 38 | + latestPageNotificationAt?: string; |
| 39 | + /** IDs of some of the accounts who most recently triggered notifications in this group. */ |
| 40 | + sampleAccountIds: string; |
| 41 | + /** ID of the Status that was the object of the notification. Attached when type of the notification is favourite, reblog, status, mention, poll, or update. */ |
| 42 | + statusId?: undefined | null; |
| 43 | + /** Report that was the object of the notification. Attached when type of the notification is admin.report. */ |
| 44 | + report?: undefined | null; |
| 45 | + /** Summary of the event that caused follow relationships to be severed. Attached when type of the notification is severed_relationships. */ |
| 46 | + event?: undefined | null; |
| 47 | + /** Moderation warning that caused the notification. Attached when type of the notification is moderation_warning. */ |
| 48 | + moderationWarning?: undefined | null; |
| 49 | +} |
| 50 | + |
| 51 | +type NotificationGroupPlain<T> = BaseNotificationGroup<T>; |
| 52 | + |
| 53 | +type NotificationGroupWithStatusId<T> = BaseNotificationGroup<T> & { |
| 54 | + /** ID of the Status that was the object of the notification. Attached when type of the notification is favourite, reblog, status, mention, poll, or update. */ |
| 55 | + statusId: string; |
| 56 | +}; |
| 57 | + |
| 58 | +type NotificationGroupWithReport<T> = BaseNotificationGroup<T> & { |
| 59 | + /** Report that was the object of the notification. Attached when type of the notification is admin.report. */ |
| 60 | + report: Report; |
| 61 | +}; |
| 62 | + |
| 63 | +type NotificationGroupWithEvent<T> = BaseNotificationGroup<T> & { |
| 64 | + /** Summary of the event that caused follow relationships to be severed. Attached when type of the notification is severed_relationships. */ |
| 65 | + event: RelationshipSeveranceEvent; |
| 66 | +}; |
| 67 | + |
| 68 | +type NotificationGroupWithModerationWarning<T> = BaseNotificationGroup<T> & { |
| 69 | + /** Moderation warning that caused the notification. Attached when type of the notification is moderation_warning. */ |
| 70 | + moderationWarning: AccountWarning; |
| 71 | +}; |
| 72 | + |
| 73 | +/** Someone mentioned you in their status */ |
| 74 | +export type MentionNotificationGroup = NotificationGroupWithStatusId<"mention">; |
| 75 | + |
| 76 | +/** Someone you enabled notifications for has posted a status */ |
| 77 | +export type StatusNotificationGroup = NotificationGroupWithStatusId<"status">; |
| 78 | + |
| 79 | +/** Someone boosted one of your statuses */ |
| 80 | +export type ReblogNotificationGroup = NotificationGroupWithStatusId<"reblog">; |
| 81 | + |
| 82 | +/** Someone followed you */ |
| 83 | +export type FollowNotificationGroup = NotificationGroupPlain<"follow">; |
| 84 | + |
| 85 | +/** Someone requested to follow you */ |
| 86 | +export type FollowRequestNotificationGroup = |
| 87 | + NotificationGroupPlain<"follow_request">; |
| 88 | + |
| 89 | +/** Someone favourited one of your statuses */ |
| 90 | +export type FavouriteNotificationGroup = |
| 91 | + NotificationGroupWithStatusId<"favourite">; |
| 92 | + |
| 93 | +/** A poll you have voted in or created has ended */ |
| 94 | +export type PollNotificationGroup = NotificationGroupWithStatusId<"poll">; |
| 95 | + |
| 96 | +/** A status you interacted with has been edited */ |
| 97 | +export type UpdateNotificationGroup = NotificationGroupWithStatusId<"update">; |
| 98 | + |
| 99 | +/** Someone signed up (optionally sent to admins) */ |
| 100 | +export type AdminSignUpNotificationGroup = |
| 101 | + NotificationGroupPlain<"admin.sign_up">; |
| 102 | + |
| 103 | +/** A new report has been filed */ |
| 104 | +export type AdminReportNotificationGroup = |
| 105 | + NotificationGroupWithReport<"admin.report">; |
| 106 | + |
| 107 | +/** Some of your follow relationships have been severed as a result of a moderation or block event */ |
| 108 | +export type SeveredRelationshipsNotificationGroup = |
| 109 | + NotificationGroupWithEvent<"severed_relationships">; |
| 110 | + |
| 111 | +/** A moderator has taken action against your account or has sent you a warning */ |
| 112 | +export type ModerationWarningNotificationGroup = |
| 113 | + NotificationGroupWithModerationWarning<"moderation_warning">; |
| 114 | + |
| 115 | +/** Group key identifying the grouped notifications. Should be treated as an opaque value. */ |
| 116 | +export type NotificationGroup = |
| 117 | + | MentionNotificationGroup |
| 118 | + | StatusNotificationGroup |
| 119 | + | ReblogNotificationGroup |
| 120 | + | FollowNotificationGroup |
| 121 | + | FollowRequestNotificationGroup |
| 122 | + | FavouriteNotificationGroup |
| 123 | + | PollNotificationGroup |
| 124 | + | UpdateNotificationGroup |
| 125 | + | AdminSignUpNotificationGroup |
| 126 | + | AdminReportNotificationGroup |
| 127 | + | SeveredRelationshipsNotificationGroup |
| 128 | + | ModerationWarningNotificationGroup; |
| 129 | + |
| 130 | +export type NotificationGroupType = NotificationGroup["type"]; |
0 commit comments