Skip to content

Commit

Permalink
feat: 激しい動きを含むカスタム絵文字を手動で指定できるように
Browse files Browse the repository at this point in the history
  • Loading branch information
kakkokari-gtyih committed Aug 11, 2024
1 parent 9b379b7 commit 8b53982
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 1 deletion.
14 changes: 14 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10172,6 +10172,20 @@ export interface Locale extends ILocale {
*/
"native": string;
};
"_hana": {
/**
* 激しい動きあり
*/
"hasMovement": string;
/**
* 激しい動きを含むカスタム絵文字のアニメーションだけを止める
*/
"stopAnimatingCustomEmojisWithMovement": string;
/**
* 激しい動きを含むとモデレーターが判断したものだけ、アニメーションを停止します。その他の絵文字(動きがゆるいもの等)は通常通りアニメーションされます。絵文字のアニメーションを完全に停止させたい場合は、「アニメーション画像を再生しない」を利用してください。
*/
"stopAnimatingCustomEmojisWithMovementDescription": string;
};
}
declare const locales: {
[lang: string]: Locale;
Expand Down
5 changes: 5 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2712,3 +2712,8 @@ _contextMenu:
app: "アプリケーション"
appWithShift: "Shiftキーでアプリケーション"
native: "ブラウザのUI"

_hana:
hasMovement: "激しい動きあり"
stopAnimatingCustomEmojisWithMovement: "激しい動きを含むカスタム絵文字のアニメーションだけを止める"
stopAnimatingCustomEmojisWithMovementDescription: "激しい動きを含むとモデレーターが判断したものだけ、アニメーションを停止します。その他の絵文字(動きがゆるいもの等)は通常通りアニメーションされます。絵文字のアニメーションを完全に停止させたい場合は、「アニメーション画像を再生しない」を利用してください。"
11 changes: 11 additions & 0 deletions packages/backend/migration/1723367092501-EmojiHasMovement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class EmojiHasMovement1723367092501 {
name = 'EmojiHasMovement1723367092501'

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "emoji" ADD "hasMovement" boolean NOT NULL DEFAULT false`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "emoji" DROP COLUMN "hasMovement"`);
}
}
4 changes: 4 additions & 0 deletions packages/backend/src/core/CustomEmojiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
isSensitive: boolean;
localOnly: boolean;
roleIdsThatCanBeUsedThisEmojiAsReaction: MiRole['id'][];
hasMovement: boolean;
}, moderator?: MiUser): Promise<MiEmoji> {
const emoji = await this.emojisRepository.insertOne({
id: this.idService.gen(),
Expand All @@ -82,6 +83,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
isSensitive: data.isSensitive,
localOnly: data.localOnly,
roleIdsThatCanBeUsedThisEmojiAsReaction: data.roleIdsThatCanBeUsedThisEmojiAsReaction,
hasMovement: data.hasMovement,
});

if (data.host == null) {
Expand Down Expand Up @@ -112,6 +114,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
isSensitive?: boolean;
localOnly?: boolean;
roleIdsThatCanBeUsedThisEmojiAsReaction?: MiRole['id'][];
hasMovement?: boolean;
}, moderator?: MiUser): Promise<void> {
const emoji = await this.emojisRepository.findOneByOrFail({ id: id });
const sameNameEmoji = await this.emojisRepository.findOneBy({ name: data.name, host: IsNull() });
Expand All @@ -129,6 +132,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
publicUrl: data.driveFile != null ? (data.driveFile.webpublicUrl ?? data.driveFile.url) : undefined,
type: data.driveFile != null ? (data.driveFile.webpublicType ?? data.driveFile.type) : undefined,
roleIdsThatCanBeUsedThisEmojiAsReaction: data.roleIdsThatCanBeUsedThisEmojiAsReaction ?? undefined,
hasMovement: data.hasMovement,
});

this.localEmojisCache.refresh();
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/core/entities/EmojiEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export class EmojiEntityService {
localOnly: emoji.localOnly ? true : undefined,
isSensitive: emoji.isSensitive ? true : undefined,
roleIdsThatCanBeUsedThisEmojiAsReaction: emoji.roleIdsThatCanBeUsedThisEmojiAsReaction.length > 0 ? emoji.roleIdsThatCanBeUsedThisEmojiAsReaction : undefined,

hasMovement: emoji.hasMovement,
};
}

Expand Down Expand Up @@ -62,6 +64,8 @@ export class EmojiEntityService {
isSensitive: emoji.isSensitive,
localOnly: emoji.localOnly,
roleIdsThatCanBeUsedThisEmojiAsReaction: emoji.roleIdsThatCanBeUsedThisEmojiAsReaction,

hasMovement: emoji.hasMovement,
};
}

Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/models/Emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@ export class MiEmoji {
array: true, length: 128, default: '{}',
})
public roleIdsThatCanBeUsedThisEmojiAsReaction: string[];

@Column('boolean', {
default: false,
})
public hasMovement: boolean;
}
10 changes: 10 additions & 0 deletions packages/backend/src/models/json-schema/emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export const packedEmojiSimpleSchema = {
format: 'id',
},
},

hasMovement: {
type: 'boolean',
optional: true, nullable: false,
},
},
} as const;

Expand Down Expand Up @@ -102,5 +107,10 @@ export const packedEmojiDetailedSchema = {
format: 'id',
},
},

hasMovement: {
type: 'boolean',
optional: true, nullable: false,
},
},
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class ImportCustomEmojisProcessorService {
isSensitive: emojiInfo.isSensitive,
localOnly: emojiInfo.localOnly,
roleIdsThatCanBeUsedThisEmojiAsReaction: [],
hasMovement: emojiInfo.hasMovement,
});
}

Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/emoji/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const paramDef = {
roleIdsThatCanBeUsedThisEmojiAsReaction: { type: 'array', items: {
type: 'string',
} },
hasMovement: { type: 'boolean' },
},
required: ['name', 'fileId'],
} as const;
Expand Down Expand Up @@ -88,6 +89,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
isSensitive: ps.isSensitive ?? false,
localOnly: ps.localOnly ?? false,
roleIdsThatCanBeUsedThisEmojiAsReaction: ps.roleIdsThatCanBeUsedThisEmojiAsReaction ?? [],
hasMovement: ps.hasMovement ?? false,
}, me);

return this.emojiEntityService.packDetailed(emoji);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
isSensitive: emoji.isSensitive,
localOnly: emoji.localOnly,
roleIdsThatCanBeUsedThisEmojiAsReaction: emoji.roleIdsThatCanBeUsedThisEmojiAsReaction,
hasMovement: emoji.hasMovement,
}, me);

return this.emojiEntityService.packDetailed(addedEmoji);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const paramDef = {
roleIdsThatCanBeUsedThisEmojiAsReaction: { type: 'array', items: {
type: 'string',
} },
hasMovement: { type: 'boolean' },
},
anyOf: [
{ required: ['id'] },
Expand Down Expand Up @@ -103,6 +104,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
isSensitive: ps.isSensitive,
localOnly: ps.localOnly,
roleIdsThatCanBeUsedThisEmojiAsReaction: ps.roleIdsThatCanBeUsedThisEmojiAsReaction,
hasMovement: ps.hasMovement,
}, me);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #key>{{ i18n.ts.localOnly }}</template>
<template #value>{{ emoji.localOnly ? i18n.ts.yes : i18n.ts.no }}</template>
</MkKeyValue>
<MkKeyValue>
<template #key>{{ i18n.ts._hana.hasMovement }}</template>
<template #value>{{ emoji.hasMovement ? i18n.ts.yes : i18n.ts.no }}</template>
</MkKeyValue>
<MkKeyValue>
<template #key>{{ i18n.ts.license }}</template>
<template #value><Mfm :text="emoji.license ?? i18n.ts.none"/></template>
Expand Down
10 changes: 9 additions & 1 deletion packages/frontend/src/components/global/MkCustomEmoji.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SPDX-License-Identifier: AGPL-3.0-only
import { computed, inject, ref } from 'vue';
import { getProxiedImageUrl, getStaticImageUrl } from '@/scripts/media-proxy.js';
import { defaultStore } from '@/store.js';
import { hanaStore } from '@/hana/store.js';
import { customEmojisMap } from '@/custom-emojis.js';
import * as os from '@/os.js';
import { misskeyApiGet } from '@/scripts/misskey-api.js';
Expand Down Expand Up @@ -63,6 +64,13 @@ const rawUrl = computed(() => {
return props.host ? `/emoji/${customEmojiName.value}@${props.host}.webp` : `/emoji/${customEmojiName.value}.webp`;
});

const shouldStopAnimatingByHanaHasMovement = computed(() => {
return (
hanaStore.reactiveState.stopAnimatingEmojisWithMovement.value &&
customEmojisMap.get(customEmojiName.value)?.hasMovement
);
});

const url = computed(() => {
if (rawUrl.value == null) return undefined;

Expand All @@ -75,7 +83,7 @@ const url = computed(() => {
false,
true,
);
return defaultStore.reactiveState.disableShowingAnimatedImages.value
return (defaultStore.reactiveState.disableShowingAnimatedImages.value || shouldStopAnimatingByHanaHasMovement.value)
? getStaticImageUrl(proxied)
: proxied;
});
Expand Down
12 changes: 12 additions & 0 deletions packages/frontend/src/hana/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { markRaw } from 'vue';
import { Storage } from '@/pizzax.js';

/**
* はなみすきー独自のデータ用
*/
export const hanaStore = markRaw(new Storage('hanaMain', {
stopAnimatingEmojisWithMovement: {
where: 'device',
default: true,
},
}));
3 changes: 3 additions & 0 deletions packages/frontend/src/pages/emoji-edit-dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkFolder>
<MkSwitch v-model="isSensitive">isSensitive</MkSwitch>
<MkSwitch v-model="localOnly">{{ i18n.ts.localOnly }}</MkSwitch>
<MkSwitch v-model="hasMovement">{{ i18n.ts._hana.hasMovement }}</MkSwitch>
<MkButton v-if="emoji" danger @click="del()"><i class="ti ti-trash"></i> {{ i18n.ts.delete }}</MkButton>
</div>
</MkSpacer>
Expand Down Expand Up @@ -108,6 +109,7 @@ const localOnly = ref(props.emoji ? props.emoji.localOnly : false);
const roleIdsThatCanBeUsedThisEmojiAsReaction = ref(props.emoji ? props.emoji.roleIdsThatCanBeUsedThisEmojiAsReaction : []);
const rolesThatCanBeUsedThisEmojiAsReaction = ref<Misskey.entities.Role[]>([]);
const file = ref<Misskey.entities.DriveFile>();
const hasMovement = ref(props.emoji ? props.emoji.hasMovement : false);

watch(roleIdsThatCanBeUsedThisEmojiAsReaction, async () => {
rolesThatCanBeUsedThisEmojiAsReaction.value = (await Promise.all(roleIdsThatCanBeUsedThisEmojiAsReaction.value.map((id) => misskeyApi('admin/roles/show', { roleId: id }).catch(() => null)))).filter(x => x != null);
Expand Down Expand Up @@ -153,6 +155,7 @@ async function done() {
isSensitive: isSensitive.value,
localOnly: localOnly.value,
roleIdsThatCanBeUsedThisEmojiAsReaction: rolesThatCanBeUsedThisEmojiAsReaction.value.map(x => x.id),
hasMovement: hasMovement.value,
};

if (file.value) {
Expand Down
4 changes: 4 additions & 0 deletions packages/misskey-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4641,6 +4641,7 @@ export type components = {
localOnly?: boolean;
isSensitive?: boolean;
roleIdsThatCanBeUsedThisEmojiAsReaction?: string[];
hasMovement?: boolean;
};
EmojiDetailed: {
/** Format: id */
Expand All @@ -4655,6 +4656,7 @@ export type components = {
isSensitive: boolean;
localOnly: boolean;
roleIdsThatCanBeUsedThisEmojiAsReaction: string[];
hasMovement?: boolean;
};
Flash: {
/**
Expand Down Expand Up @@ -6956,6 +6958,7 @@ export type operations = {
isSensitive?: boolean;
localOnly?: boolean;
roleIdsThatCanBeUsedThisEmojiAsReaction?: string[];
hasMovement?: boolean;
};
};
};
Expand Down Expand Up @@ -7586,6 +7589,7 @@ export type operations = {
isSensitive?: boolean;
localOnly?: boolean;
roleIdsThatCanBeUsedThisEmojiAsReaction?: string[];
hasMovement?: boolean;
};
};
};
Expand Down

0 comments on commit 8b53982

Please sign in to comment.