1
0
Fork 0
forked from gitea/nas

Merge remote-tracking branch 'parent/main' into upstream-20241126

This commit is contained in:
KMY 2024-11-26 12:56:31 +09:00
commit 8a075ba4c6
303 changed files with 7495 additions and 4498 deletions

View file

@ -1,5 +1,5 @@
import type { RecordOf } from 'immutable';
import { List, Record as ImmutableRecord } from 'immutable';
import { List as ImmutableList, Record as ImmutableRecord } from 'immutable';
import escapeTextContentForBrowser from 'escape-html';
@ -79,9 +79,9 @@ export interface AccountShape
extends Required<
Omit<ApiAccountJSON, 'emojis' | 'fields' | 'roles' | 'moved'>
> {
emojis: List<CustomEmoji>;
fields: List<AccountField>;
roles: List<AccountRole>;
emojis: ImmutableList<CustomEmoji>;
fields: ImmutableList<AccountField>;
roles: ImmutableList<AccountRole>;
display_name_html: string;
note_emojified: string;
note_plain: string | null;
@ -102,8 +102,8 @@ export const accountDefaultValues: AccountShape = {
display_name: '',
display_name_html: '',
server_features: AccountServerFeaturesFactory(),
emojis: List<CustomEmoji>(),
fields: List<AccountField>(),
emojis: ImmutableList<CustomEmoji>(),
fields: ImmutableList<AccountField>(),
group: false,
header: '',
header_static: '',
@ -114,7 +114,7 @@ export const accountDefaultValues: AccountShape = {
note: '',
note_emojified: '',
note_plain: 'string',
roles: List<AccountRole>(),
roles: ImmutableList<AccountRole>(),
uri: '',
url: '',
username: '',
@ -173,11 +173,15 @@ export function createAccountFromServerJSON(serverJSON: ApiAccountJSON) {
return AccountFactory({
...accountJSON,
moved: moved?.id,
fields: List(
fields: ImmutableList(
serverJSON.fields.map((field) => createAccountField(field, emojiMap)),
),
emojis: List(serverJSON.emojis.map((emoji) => CustomEmojiFactory(emoji))),
roles: List(serverJSON.roles?.map((role) => AccountRoleFactory(role))),
emojis: ImmutableList(
serverJSON.emojis.map((emoji) => CustomEmojiFactory(emoji)),
),
roles: ImmutableList(
serverJSON.roles?.map((role) => AccountRoleFactory(role)),
),
display_name_html: emojify(
escapeTextContentForBrowser(displayName),
emojiMap,

View file

@ -0,0 +1,33 @@
import type { RecordOf } from 'immutable';
import { Record } from 'immutable';
import type { ApiAntennaJSON } from 'mastodon/api_types/antennas';
type AntennaShape = Required<ApiAntennaJSON>; // no changes from server shape
export type Antenna = RecordOf<AntennaShape>;
const AntennaFactory = Record<AntennaShape>({
id: '',
title: '',
stl: false,
ltl: false,
insert_feeds: false,
with_media_only: false,
ignore_reblog: false,
accounts_count: 0,
domains_count: 0,
tags_count: 0,
keywords_count: 0,
list: null,
domains: undefined,
keywords: undefined,
tags: undefined,
exclude_domains: undefined,
exclude_keywords: undefined,
exclude_tags: undefined,
list_id: undefined,
});
export function createAntenna(attributes: Partial<AntennaShape>) {
return AntennaFactory(attributes);
}

View file

@ -0,0 +1,18 @@
import type { RecordOf } from 'immutable';
import { Record } from 'immutable';
import type { ApiBookmarkCategoryJSON } from 'mastodon/api_types/bookmark_categories';
type BookmarkCategoryShape = Required<ApiBookmarkCategoryJSON>; // no changes from server shape
export type BookmarkCategory = RecordOf<BookmarkCategoryShape>;
const BookmarkCategoryFactory = Record<BookmarkCategoryShape>({
id: '',
title: '',
});
export function createBookmarkCategory(
attributes: Partial<BookmarkCategoryShape>,
) {
return BookmarkCategoryFactory(attributes);
}

View file

@ -0,0 +1,16 @@
import type { RecordOf } from 'immutable';
import { Record } from 'immutable';
import type { ApiCircleJSON } from 'mastodon/api_types/circles';
type CircleShape = Required<ApiCircleJSON>; // no changes from server shape
export type Circle = RecordOf<CircleShape>;
const CircleFactory = Record<CircleShape>({
id: '',
title: '',
});
export function createCircle(attributes: Partial<CircleShape>) {
return CircleFactory(attributes);
}

View file

@ -0,0 +1,19 @@
import type { RecordOf } from 'immutable';
import { Record } from 'immutable';
import type { ApiListJSON } from 'mastodon/api_types/lists';
type ListShape = Required<ApiListJSON>; // no changes from server shape
export type List = RecordOf<ListShape>;
const ListFactory = Record<ListShape>({
id: '',
title: '',
exclusive: false,
replies_policy: 'list',
notify: false,
});
export function createList(attributes: Partial<ListShape>) {
return ListFactory(attributes);
}

View file

@ -19,6 +19,7 @@ export const NOTIFICATIONS_GROUP_MAX_AVATARS = 8;
interface BaseNotificationGroup
extends Omit<BaseNotificationGroupJSON, 'sample_account_ids'> {
sampleAccountIds: string[];
partial: boolean;
}
interface BaseNotificationWithStatus<Type extends NotificationWithStatusType>
@ -187,6 +188,7 @@ export function createNotificationGroupFromJSON(
return {
statusId: statusId ?? undefined,
sampleAccountIds,
partial: false,
...groupWithoutStatus,
};
}
@ -210,6 +212,7 @@ export function createNotificationGroupFromJSON(
statusId: statusId ?? undefined,
sampleAccountIds,
emojiReactionGroups: groups,
partial: false,
...groupWithoutStatus,
};
}
@ -218,12 +221,14 @@ export function createNotificationGroupFromJSON(
return {
report: createReportFromJSON(report),
sampleAccountIds,
partial: false,
...groupWithoutTargetAccount,
};
}
case 'severed_relationships':
return {
...group,
partial: false,
event: createAccountRelationshipSeveranceEventFromJSON(group.event),
sampleAccountIds,
};
@ -231,6 +236,7 @@ export function createNotificationGroupFromJSON(
const { moderation_warning, ...groupWithoutModerationWarning } = group;
return {
...groupWithoutModerationWarning,
partial: false,
moderationWarning: createAccountWarningFromJSON(moderation_warning),
sampleAccountIds,
};
@ -239,6 +245,7 @@ export function createNotificationGroupFromJSON(
const { annual_report, ...groupWithoutAnnualReport } = group;
return {
...groupWithoutAnnualReport,
partial: false,
annualReport: createAnnualReportEventFromJSON(annual_report),
sampleAccountIds,
};
@ -246,6 +253,7 @@ export function createNotificationGroupFromJSON(
default:
return {
sampleAccountIds,
partial: false,
...group,
};
}
@ -253,17 +261,17 @@ export function createNotificationGroupFromJSON(
export function createNotificationGroupFromNotificationJSON(
notification: ApiNotificationJSON,
) {
): NotificationGroup {
const group = {
sampleAccountIds: [notification.account.id],
group_key: notification.group_key,
notifications_count: 1,
type: notification.type,
most_recent_notification_id: notification.id,
page_min_id: notification.id,
page_max_id: notification.id,
latest_page_notification_at: notification.created_at,
} as NotificationGroup;
partial: true,
};
switch (notification.type) {
case 'favourite':
@ -273,16 +281,22 @@ export function createNotificationGroupFromNotificationJSON(
case 'status_reference':
case 'poll':
case 'update':
return { ...group, statusId: notification.status?.id };
return {
...group,
type: notification.type,
statusId: notification.status?.id,
};
case 'list_status':
return {
...group,
type: notification.type,
statusId: notification.status?.id,
list: notification.list,
};
case 'emoji_reaction':
return {
...group,
type: notification.type,
statusId: notification.status?.id,
emojiReactionGroups: createEmojiReactionGroupsFromJSON(
notification.emoji_reaction,
@ -290,10 +304,15 @@ export function createNotificationGroupFromNotificationJSON(
),
};
case 'admin.report':
return { ...group, report: createReportFromJSON(notification.report) };
return {
...group,
type: notification.type,
report: createReportFromJSON(notification.report),
};
case 'severed_relationships':
return {
...group,
type: notification.type,
event: createAccountRelationshipSeveranceEventFromJSON(
notification.event,
),
@ -301,11 +320,15 @@ export function createNotificationGroupFromNotificationJSON(
case 'moderation_warning':
return {
...group,
type: notification.type,
moderationWarning: createAccountWarningFromJSON(
notification.moderation_warning,
),
};
default:
return group;
return {
...group,
type: notification.type,
};
}
}