feat(typingIndicator): Option to not show indicator for blocked users (#513)

This commit is contained in:
fawn 2023-03-19 08:13:17 +00:00 committed by GitHub
parent 0fb79b763d
commit 17c3496542
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 10 deletions

View file

@ -19,7 +19,8 @@
import { debounce } from "@utils/debounce"; import { debounce } from "@utils/debounce";
import { Margins } from "@utils/margins"; import { Margins } from "@utils/margins";
import { makeCodeblock } from "@utils/misc"; import { makeCodeblock } from "@utils/misc";
import { canonicalizeMatch, canonicalizeReplace, ReplaceFn } from "@utils/patches"; import { canonicalizeMatch, canonicalizeReplace } from "@utils/patches";
import { ReplaceFn } from "@utils/types";
import { search } from "@webpack"; import { search } from "@webpack";
import { Button, Clipboard, Forms, Parser, React, Switch, Text, TextInput } from "@webpack/common"; import { Button, Clipboard, Forms, Parser, React, Switch, Text, TextInput } from "@webpack/common";

View file

@ -22,7 +22,7 @@ import { Devs } from "@utils/constants";
import { LazyComponent } from "@utils/misc"; import { LazyComponent } from "@utils/misc";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { find, findLazy, findStoreLazy } from "@webpack"; import { find, findLazy, findStoreLazy } from "@webpack";
import { ChannelStore, GuildMemberStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common"; import { ChannelStore, GuildMemberStore, RelationshipStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common";
import { buildSeveralUsers } from "./typingTweaks"; import { buildSeveralUsers } from "./typingTweaks";
@ -57,9 +57,9 @@ function TypingIndicator({ channelId }: { channelId: string; }) {
if (isChannelMuted) return null; if (isChannelMuted) return null;
} }
delete typingUsers[UserStore.getCurrentUser().id]; const myId = UserStore.getCurrentUser().id;
const typingUsersArray = Object.keys(typingUsers); const typingUsersArray = Object.keys(typingUsers).filter(id => id !== myId && !(RelationshipStore.isBlocked(id) && !settings.store.includeBlockedUsers));
let tooltipText: string; let tooltipText: string;
switch (typingUsersArray.length) { switch (typingUsersArray.length) {
@ -108,13 +108,18 @@ const settings = definePluginSettings({
type: OptionType.BOOLEAN, type: OptionType.BOOLEAN,
description: "Whether to show the typing indicator for muted channels.", description: "Whether to show the typing indicator for muted channels.",
default: false default: false
},
includeBlockedUsers: {
type: OptionType.BOOLEAN,
description: "Whether to show the typing indicator for blocked users.",
default: false
} }
}); });
export default definePlugin({ export default definePlugin({
name: "TypingIndicator", name: "TypingIndicator",
description: "Adds an indicator if someone is typing on a channel.", description: "Adds an indicator if someone is typing on a channel.",
authors: [Devs.Nuckyz], authors: [Devs.Nuckyz, Devs.obscurity],
settings, settings,
patches: [ patches: [

View file

@ -16,9 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { PatchReplacement } from "./types"; import { PatchReplacement, ReplaceFn } from "./types";
export type ReplaceFn = (match: string, ...groups: string[]) => string;
export function canonicalizeMatch(match: RegExp | string) { export function canonicalizeMatch(match: RegExp | string) {
if (typeof match === "string") return match; if (typeof match === "string") return match;

View file

@ -19,13 +19,13 @@
import { Command } from "@api/Commands"; import { Command } from "@api/Commands";
import { Promisable } from "type-fest"; import { Promisable } from "type-fest";
import type { ReplaceFn } from "./patches";
// exists to export default definePlugin({...}) // exists to export default definePlugin({...})
export default function definePlugin<P extends PluginDef>(p: P & Record<string, any>) { export default function definePlugin<P extends PluginDef>(p: P & Record<string, any>) {
return p; return p;
} }
export type ReplaceFn = (match: string, ...groups: string[]) => string;
export interface PatchReplacement { export interface PatchReplacement {
match: string | RegExp; match: string | RegExp;
replace: string | ReplaceFn; replace: string | ReplaceFn;