diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-05-10 21:21:50 -0400 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-05-12 21:46:03 -0400 |
| commit | 5cb0129c499e7bbf7fd34b34cdd4b51cc8086184 (patch) | |
| tree | bad3f112212ff7a45db520b60558d397c7b772c1 /packages/frontend/src/utility | |
| parent | show muted words in NoteDetailed / NoteSub components (diff) | |
| download | sharkey-5cb0129c499e7bbf7fd34b34cdd4b51cc8086184.tar.gz sharkey-5cb0129c499e7bbf7fd34b34cdd4b51cc8086184.tar.bz2 sharkey-5cb0129c499e7bbf7fd34b34cdd4b51cc8086184.zip | |
show muted words in following feed
Diffstat (limited to 'packages/frontend/src/utility')
| -rw-r--r-- | packages/frontend/src/utility/following-feed-utils.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/packages/frontend/src/utility/following-feed-utils.ts b/packages/frontend/src/utility/following-feed-utils.ts index d821a80fb0..4573f3dd7a 100644 --- a/packages/frontend/src/utility/following-feed-utils.ts +++ b/packages/frontend/src/utility/following-feed-utils.ts @@ -4,6 +4,7 @@ */ import { computed } from 'vue'; +import * as Misskey from 'misskey-js'; import type { Ref, WritableComputedRef } from 'vue'; import type { PageHeaderItem } from '@/types/page-header.js'; import type { MenuItem } from '@/types/menu.js'; @@ -13,6 +14,8 @@ import { i18n } from '@/i18n.js'; import { popupMenu } from '@/os.js'; import { prefer } from '@/preferences.js'; import { followingTab, followersTab, mutualsTab, defaultFollowingFeedState } from '@/types/following-feed.js'; +import { $i } from '@/i'; +import { checkWordMute } from '@/utility/check-word-mute'; export function followingTabName(tab: FollowingFeedTab): string; export function followingTabName(tab: FollowingFeedTab | null | undefined): null; @@ -149,3 +152,35 @@ function createDefaultStorage(): Ref<StorageInterface> { }, })); } + +export function getSoftMutedWords(note: Misskey.entities.Note): string | null { + return getMutedWords(note, $i?.mutedWords); +} + +export function getHardMutedWords(note: Misskey.entities.Note): string | null { + return getMutedWords(note, $i?.hardMutedWords); +} + +// Match the typing used by Misskey +type Mutes = (string | string[])[] | null | undefined; + +// Adapted from MkNote.ts +function getMutedWords(note: Misskey.entities.Note, mutes: Mutes): string | null { + return checkMute(note, mutes) + ?? checkMute(note.reply, mutes) + ?? checkMute(note.renote, mutes); +} + +// Adapted from check-word-mute.ts +function checkMute(note: Misskey.entities.Note | undefined | null, mutes: Mutes): string | null { + if (!note) { + return null; + } + + if (!mutes || mutes.length < 1) { + return null; + } + + const mutedWords = checkWordMute(note, $i, mutes); + return mutedWords ? mutedWords.flat(2).join(', ') : null; +} |