2024-03-13 13:37:18 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2024-02-06 07:45:21 +00:00
|
|
|
import * as Misskey from 'misskey-js';
|
2024-09-09 11:57:36 +00:00
|
|
|
import { UnicodeEmojiDef } from '@@/js/emojilist.js';
|
2024-02-06 07:45:21 +00:00
|
|
|
|
2024-03-02 04:28:10 +00: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 01:22:23 +00:00
|
|
|
|
2024-03-02 04:28:10 +00:00
|
|
|
const roleIdsThatCanBeUsedThisEmojiAsReaction = emoji.roleIdsThatCanBeUsedThisEmojiAsReaction ?? [];
|
|
|
|
return !(emoji.localOnly && note.user.host !== me.host)
|
2024-02-06 07:45:21 +00:00
|
|
|
&& !(emoji.isSensitive && (note.reactionAcceptance === 'nonSensitiveOnly' || note.reactionAcceptance === 'nonSensitiveOnlyForLocalLikeOnlyForRemote'))
|
|
|
|
&& (roleIdsThatCanBeUsedThisEmojiAsReaction.length === 0 || me.roles.some(role => roleIdsThatCanBeUsedThisEmojiAsReaction.includes(role.id)));
|
|
|
|
}
|