From 7c275adfc898e4c971918005af20c5b48fbb542d Mon Sep 17 00:00:00 2001 From: notfire Date: Sun, 30 Mar 2025 14:33:29 -0400 Subject: [PATCH] add emoji reaction filtering --- README.md | 3 ++ .../emoji_reactions/emoji_reactions.js | 48 +++++++++++++++++-- .../emoji_reactions/emoji_reactions.vue | 2 +- src/components/notification/notification.js | 27 +++++++++++ src/components/notification/notification.vue | 2 +- .../settings_modal/tabs/filtering_tab.js | 4 +- .../settings_modal/tabs/filtering_tab.vue | 17 +++++++ src/i18n/en.json | 2 + src/modules/config.js | 1 + src/modules/instance.js | 1 + 10 files changed, 99 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 867373f4..57c5407d 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,9 @@ - polls can now have up to 20 options instead of 4 - polls can now last anywhere from 1 second to 1000 years - optional alternate gravestone when using websockets that still shows post content but removes buttons +- filters for reactions: + - matching by regex, domain-specific, or catch-all + - filters the actual reactions to post as well as notifications --- diff --git a/src/components/emoji_reactions/emoji_reactions.js b/src/components/emoji_reactions/emoji_reactions.js index 94464bf4..94aa3734 100644 --- a/src/components/emoji_reactions/emoji_reactions.js +++ b/src/components/emoji_reactions/emoji_reactions.js @@ -2,6 +2,8 @@ import UserAvatar from '../user_avatar/user_avatar.vue' import UserListPopover from '../user_list_popover/user_list_popover.vue' import StillImage from '../still-image/still-image.vue' +import { toRaw } from 'vue' + const EMOJI_REACTION_COUNT_CUTOFF = 12 const findEmojiByReplacement = (state, replacement) => { @@ -24,11 +26,6 @@ const EmojiReactions = { tooManyReactions () { return this.status.emoji_reactions.length > EMOJI_REACTION_COUNT_CUTOFF }, - emojiReactions () { - return this.showAll - ? this.status.emoji_reactions - : this.status.emoji_reactions.slice(0, EMOJI_REACTION_COUNT_CUTOFF) - }, showMoreString () { return `+${this.status.emoji_reactions.length - EMOJI_REACTION_COUNT_CUTOFF}` }, @@ -44,9 +41,50 @@ const EmojiReactions = { }, loggedIn () { return !!this.$store.state.users.currentUser + }, + filteredReactions () { + // this is fucking Jank. + var finalReacts = this.emojiReactions() + var tempList = [] + var reactionsFilterItems = this.$store.getters.mergedConfig.reactionsFilterItems.split("\n") + if (reactionsFilterItems.length > 0 && finalReacts.length > 0) { + reactionsFilterItems.forEach((item) => { + var toPush = [] + finalReacts.forEach((react) => { + var rawReact = toRaw(react)["name"] + + if ( + // match regex + // >1 check is to prevent = just disabling all emoji reacts + item.charAt(0) == "=" && item.length > 1 && rawReact.match(item.substring(1)) + // match everything explicit, if there's an @ + || rawReact == item.match(/.*@.*/) ? item : null + // match everything else + || (rawReact.match(/.*@.*/) ? rawReact.split("@")[0] : rawReact) == item + ) { + toPush.push(react) + } + }) + + toPush.forEach((nice) => { + tempList.push(nice) + }) + }) + } + + tempList.forEach((item) => { + finalReacts.splice(finalReacts.indexOf(item), 1) + }) + + return finalReacts } }, methods: { + emojiReactions () { + return this.showAll + ? this.status.emoji_reactions + : this.status.emoji_reactions.slice(0, EMOJI_REACTION_COUNT_CUTOFF) + }, toggleShowAll () { this.showAll = !this.showAll }, diff --git a/src/components/emoji_reactions/emoji_reactions.vue b/src/components/emoji_reactions/emoji_reactions.vue index aab9f42e..c083625f 100644 --- a/src/components/emoji_reactions/emoji_reactions.vue +++ b/src/components/emoji_reactions/emoji_reactions.vue @@ -1,7 +1,7 @@ diff --git a/src/i18n/en.json b/src/i18n/en.json index 6a4e90db..5fcc477e 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -686,6 +686,7 @@ "notification_setting_hide_if_cw": "Hide the contents of push notifications if under a Content Warning", "notification_setting_hide_notification_contents": "Hide the sender and contents of push notifications", "notification_setting_privacy": "Privacy", + "notification_setting_reactions": "Reactions", "notification_setting_sounds": "Sounds", "notification_visibility": "Types of notifications to show", "notification_visibility_bites": "Bites", @@ -719,6 +720,7 @@ }, "profile_tab": "Profile", "radii_help": "Set up interface edge rounding (in pixels)", + "reactions_filter": "Filter reactions by name", "recurse_search": "When searching, run searches until no results are found anymore", "recurse_search_limit": "Number of posts to stop recurse searching at (>300 will cause massive performance issues)", "refresh_token": "Refresh token", diff --git a/src/modules/config.js b/src/modules/config.js index c54d95ce..daa27d73 100644 --- a/src/modules/config.js +++ b/src/modules/config.js @@ -124,6 +124,7 @@ export const defaultState = { boostsFollowDefVis: false, searchPaginationLimit: 40, sillyFeatures: false, + reactionsFilterItems: '', recurseSearch: false, recurseSearchLimit: 100, renderMisskeyMarkdown: undefined, diff --git a/src/modules/instance.js b/src/modules/instance.js index 5715e87b..85dcab9a 100644 --- a/src/modules/instance.js +++ b/src/modules/instance.js @@ -80,6 +80,7 @@ const defaultState = { deletePostsStreaming: true, searchPaginationLimit: 40, sillyFeatures: false, + reactionsFilterItems: '', recurseSearch: false, recurseSearchLimit: 100, renderMisskeyMarkdown: true,