TypingIndicator: support threads
This commit is contained in:
parent
18d63af241
commit
2f1e86f333
2 changed files with 22 additions and 14 deletions
|
@ -21,8 +21,8 @@ import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { LazyComponent } from "@utils/react";
|
import { LazyComponent } from "@utils/react";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { find, findLazy, findStoreLazy } from "@webpack";
|
import { find, findStoreLazy } from "@webpack";
|
||||||
import { ChannelStore, GuildMemberStore, RelationshipStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common";
|
import { ChannelStore, GuildMemberStore, i18n, RelationshipStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common";
|
||||||
|
|
||||||
import { buildSeveralUsers } from "../typingTweaks";
|
import { buildSeveralUsers } from "../typingTweaks";
|
||||||
|
|
||||||
|
@ -36,10 +36,9 @@ const ThreeDots = LazyComponent(() => {
|
||||||
const TypingStore = findStoreLazy("TypingStore");
|
const TypingStore = findStoreLazy("TypingStore");
|
||||||
const UserGuildSettingsStore = findStoreLazy("UserGuildSettingsStore");
|
const UserGuildSettingsStore = findStoreLazy("UserGuildSettingsStore");
|
||||||
|
|
||||||
const Formatters = findLazy(m => m.Messages?.SEVERAL_USERS_TYPING);
|
|
||||||
|
|
||||||
function getDisplayName(guildId: string, userId: string) {
|
function getDisplayName(guildId: string, userId: string) {
|
||||||
return GuildMemberStore.getNick(guildId, userId) ?? UserStore.getUser(userId).username;
|
const user = UserStore.getUser(userId);
|
||||||
|
return GuildMemberStore.getNick(guildId, userId) ?? (user as any).globalName ?? user.username;
|
||||||
}
|
}
|
||||||
|
|
||||||
function TypingIndicator({ channelId }: { channelId: string; }) {
|
function TypingIndicator({ channelId }: { channelId: string; }) {
|
||||||
|
@ -51,7 +50,7 @@ function TypingIndicator({ channelId }: { channelId: string; }) {
|
||||||
const oldKeys = Object.keys(old);
|
const oldKeys = Object.keys(old);
|
||||||
const currentKeys = Object.keys(current);
|
const currentKeys = Object.keys(current);
|
||||||
|
|
||||||
return oldKeys.length === currentKeys.length && JSON.stringify(oldKeys) === JSON.stringify(currentKeys);
|
return oldKeys.length === currentKeys.length && currentKeys.every(key => old[key] != null);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -70,21 +69,21 @@ function TypingIndicator({ channelId }: { channelId: string; }) {
|
||||||
switch (typingUsersArray.length) {
|
switch (typingUsersArray.length) {
|
||||||
case 0: break;
|
case 0: break;
|
||||||
case 1: {
|
case 1: {
|
||||||
tooltipText = Formatters.Messages.ONE_USER_TYPING.format({ a: getDisplayName(guildId, typingUsersArray[0]) });
|
tooltipText = i18n.Messages.ONE_USER_TYPING.format({ a: getDisplayName(guildId, typingUsersArray[0]) });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2: {
|
case 2: {
|
||||||
tooltipText = Formatters.Messages.TWO_USERS_TYPING.format({ a: getDisplayName(guildId, typingUsersArray[0]), b: getDisplayName(guildId, typingUsersArray[1]) });
|
tooltipText = i18n.Messages.TWO_USERS_TYPING.format({ a: getDisplayName(guildId, typingUsersArray[0]), b: getDisplayName(guildId, typingUsersArray[1]) });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 3: {
|
case 3: {
|
||||||
tooltipText = Formatters.Messages.THREE_USERS_TYPING.format({ a: getDisplayName(guildId, typingUsersArray[0]), b: getDisplayName(guildId, typingUsersArray[1]), c: getDisplayName(guildId, typingUsersArray[2]) });
|
tooltipText = i18n.Messages.THREE_USERS_TYPING.format({ a: getDisplayName(guildId, typingUsersArray[0]), b: getDisplayName(guildId, typingUsersArray[1]), c: getDisplayName(guildId, typingUsersArray[2]) });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
tooltipText = Settings.plugins.TypingTweaks.enabled
|
tooltipText = Settings.plugins.TypingTweaks.enabled
|
||||||
? buildSeveralUsers({ a: getDisplayName(guildId, typingUsersArray[0]), b: getDisplayName(guildId, typingUsersArray[1]), count: typingUsersArray.length - 2 })
|
? buildSeveralUsers({ a: getDisplayName(guildId, typingUsersArray[0]), b: getDisplayName(guildId, typingUsersArray[1]), count: typingUsersArray.length - 2 })
|
||||||
: Formatters.Messages.SEVERAL_USERS_TYPING;
|
: i18n.Messages.SEVERAL_USERS_TYPING;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,11 +91,10 @@ function TypingIndicator({ channelId }: { channelId: string; }) {
|
||||||
if (typingUsersArray.length > 0) {
|
if (typingUsersArray.length > 0) {
|
||||||
return (
|
return (
|
||||||
<Tooltip text={tooltipText!}>
|
<Tooltip text={tooltipText!}>
|
||||||
{({ onMouseLeave, onMouseEnter }) => (
|
{props => (
|
||||||
<div
|
<div
|
||||||
|
{...props}
|
||||||
style={{ marginLeft: 6, height: 16, display: "flex", alignItems: "center", zIndex: 0, cursor: "pointer" }}
|
style={{ marginLeft: 6, height: 16, display: "flex", alignItems: "center", zIndex: 0, cursor: "pointer" }}
|
||||||
onMouseLeave={onMouseLeave}
|
|
||||||
onMouseEnter={onMouseEnter}
|
|
||||||
>
|
>
|
||||||
<ThreeDots dotRadius={3} themed={true} />
|
<ThreeDots dotRadius={3} themed={true} />
|
||||||
</div>
|
</div>
|
||||||
|
@ -128,12 +126,22 @@ export default definePlugin({
|
||||||
settings,
|
settings,
|
||||||
|
|
||||||
patches: [
|
patches: [
|
||||||
|
// Normal channel
|
||||||
{
|
{
|
||||||
find: "UNREAD_IMPORTANT:",
|
find: "UNREAD_IMPORTANT:",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /channel:(\i).{0,100}?channelEmoji,.{0,250}?\.children.{0,50}?:null/,
|
match: /channel:(\i).{0,100}?channelEmoji,.{0,250}?\.children.{0,50}?:null/,
|
||||||
replace: "$&,$self.TypingIndicator($1.id)"
|
replace: "$&,$self.TypingIndicator($1.id)"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
// Theads
|
||||||
|
{
|
||||||
|
// This is the thread "spine" that shows in the left
|
||||||
|
find: "M11 9H4C2.89543 9 2 8.10457 2 7V1C2 0.447715 1.55228 0 1 0C0.447715 0 0 0.447715 0 1V7C0 9.20914 1.79086 11 4 11H11C11.5523 11 12 10.5523 12 10C12 9.44771 11.5523 9 11 9Z",
|
||||||
|
replacement: {
|
||||||
|
match: /mentionsCount:\i.+?null(?<=channel:(\i).+?)/,
|
||||||
|
replace: "$&,$self.TypingIndicator($1.id)"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
2
src/webpack/common/types/utils.d.ts
vendored
2
src/webpack/common/types/utils.d.ts
vendored
|
@ -159,5 +159,5 @@ export interface i18n {
|
||||||
|
|
||||||
loadPromise: Promise<void>;
|
loadPromise: Promise<void>;
|
||||||
|
|
||||||
Messages: Record<i18nMessages, string>;
|
Messages: Record<i18nMessages, any>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue