2024-03-13 22:37:18 +09:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2024-02-06 16:45:21 +09:00
|
|
|
import * as Misskey from 'misskey-js';
|
2024-02-24 10:22:23 +09:00
|
|
|
import { UnicodeEmojiDef } from './emojilist.js';
|
2024-02-06 16:45:21 +09:00
|
|
|
|
2024-03-02 13:28:10 +09:00
|
|
|
export function checkReactionPermissions(me: Misskey.entities.MeDetailed, note: Misskey.entities.Note, emoji: Misskey.entities.EmojiSimple | UnicodeEmojiDef | string): boolean {
|
|
|
|
if (typeof emoji === 'string') return true; // UnicodeEmojiDefにも無い絵文字であれば文字列で来る。Unicode絵文字であることには変わりないので常にリアクション可能とする;
|
|
|
|
if ('char' in emoji) return true; // UnicodeEmojiDefなら常にリアクション可能
|
2024-02-24 10:22:23 +09:00
|
|
|
|
2024-03-02 13:28:10 +09:00
|
|
|
const roleIdsThatCanBeUsedThisEmojiAsReaction = emoji.roleIdsThatCanBeUsedThisEmojiAsReaction ?? [];
|
|
|
|
return !(emoji.localOnly && note.user.host !== me.host)
|
2024-02-06 16:45:21 +09:00
|
|
|
&& !(emoji.isSensitive && (note.reactionAcceptance === 'nonSensitiveOnly' || note.reactionAcceptance === 'nonSensitiveOnlyForLocalLikeOnlyForRemote'))
|
|
|
|
&& (roleIdsThatCanBeUsedThisEmojiAsReaction.length === 0 || me.roles.some(role => roleIdsThatCanBeUsedThisEmojiAsReaction.includes(role.id)));
|
|
|
|
}
|