misskey/packages/frontend/src/pages/admin/custom-emojis-grid.impl.ts

100 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-01-21 02:39:52 +00:00
import * as Misskey from 'misskey-js';
2024-01-27 03:02:50 +00:00
export interface IGridItem {
2024-01-21 02:39:52 +00:00
readonly id?: string;
2024-01-27 03:02:50 +00:00
readonly fileId?: string;
readonly url: string;
name: string;
category: string;
aliases: string;
license: string;
isSensitive: boolean;
localOnly: boolean;
roleIdsThatCanBeUsedThisEmojiAsReaction: string;
}
export class GridItem implements IGridItem {
readonly id?: string;
readonly fileId?: string;
readonly url: string;
2024-01-21 02:39:52 +00:00
2024-01-29 00:35:26 +00:00
public checked: boolean;
2024-01-21 02:39:52 +00:00
public name: string;
public category: string;
2024-01-22 01:37:44 +00:00
public aliases: string;
2024-01-21 02:39:52 +00:00
public license: string;
public isSensitive: boolean;
public localOnly: boolean;
public roleIdsThatCanBeUsedThisEmojiAsReaction: string;
private readonly origin: string;
2024-01-22 01:37:44 +00:00
constructor(
2024-01-21 02:39:52 +00:00
id: string | undefined,
2024-01-27 03:02:50 +00:00
fileId: string | undefined,
url: string,
2024-01-21 02:39:52 +00:00
name: string,
category: string,
2024-01-22 01:37:44 +00:00
aliases: string,
2024-01-21 02:39:52 +00:00
license: string,
isSensitive: boolean,
localOnly: boolean,
roleIdsThatCanBeUsedThisEmojiAsReaction: string,
) {
this.id = id;
2024-01-27 03:02:50 +00:00
this.fileId = fileId;
2024-01-21 02:39:52 +00:00
this.url = url;
2024-01-29 00:35:26 +00:00
this.checked = true;
2024-01-21 02:39:52 +00:00
this.aliases = aliases;
this.name = name;
this.category = category;
this.license = license;
this.isSensitive = isSensitive;
this.localOnly = localOnly;
this.roleIdsThatCanBeUsedThisEmojiAsReaction = roleIdsThatCanBeUsedThisEmojiAsReaction;
this.origin = JSON.stringify(this);
}
2024-01-27 03:02:50 +00:00
static fromEmojiDetailed(it: Misskey.entities.EmojiDetailed): GridItem {
2024-01-23 06:34:52 +00:00
return new GridItem(
it.id,
undefined,
2024-01-27 03:02:50 +00:00
it.url,
2024-01-23 06:34:52 +00:00
it.name,
it.category ?? '',
it.aliases.join(', '),
it.license ?? '',
it.isSensitive,
it.localOnly,
it.roleIdsThatCanBeUsedThisEmojiAsReaction.join(', '),
);
2024-01-21 02:39:52 +00:00
}
2024-01-27 03:02:50 +00:00
static fromDriveFile(it: Misskey.entities.DriveFile): GridItem {
return new GridItem(
undefined,
it.id,
it.url,
it.name.replace(/\.[a-zA-Z0-9]+$/, ''),
'',
'',
'',
it.isSensitive,
false,
'',
);
}
2024-01-21 02:39:52 +00:00
public get edited(): boolean {
const { origin, ..._this } = this;
return JSON.stringify(_this) !== origin;
}
2024-01-22 01:37:44 +00:00
2024-01-23 06:34:52 +00:00
public asRecord(): Record<string, never> {
return this as Record<string, never>;
2024-01-22 01:37:44 +00:00
}
2024-01-21 02:39:52 +00:00
}