Fix some plugins displaying legacy discriminators (username#0000)
This commit is contained in:
parent
214c101740
commit
d7ac418e05
@ -19,6 +19,7 @@
|
|||||||
import ErrorBoundary from "@components/ErrorBoundary";
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Flex } from "@components/Flex";
|
import { Flex } from "@components/Flex";
|
||||||
import { InfoIcon, OwnerCrownIcon } from "@components/Icons";
|
import { InfoIcon, OwnerCrownIcon } from "@components/Icons";
|
||||||
|
import { getUniqueUsername } from "@utils/discord";
|
||||||
import { ModalCloseButton, ModalContent, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
|
import { ModalCloseButton, ModalContent, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
|
||||||
import { ContextMenu, FluxDispatcher, GuildMemberStore, Menu, PermissionsBits, Text, Tooltip, useEffect, UserStore, useState, useStateFromStores } from "@webpack/common";
|
import { ContextMenu, FluxDispatcher, GuildMemberStore, Menu, PermissionsBits, Text, Tooltip, useEffect, UserStore, useState, useStateFromStores } from "@webpack/common";
|
||||||
import type { Guild } from "discord-types/general";
|
import type { Guild } from "discord-types/general";
|
||||||
@ -136,7 +137,7 @@ function RolesAndUsersPermissionsComponent({ permissions, guild, modalProps, hea
|
|||||||
permission.type === PermissionType.Role
|
permission.type === PermissionType.Role
|
||||||
? role?.name || "Unknown Role"
|
? role?.name || "Unknown Role"
|
||||||
: permission.type === PermissionType.User
|
: permission.type === PermissionType.User
|
||||||
? user?.tag || "Unknown User"
|
? (user && getUniqueUsername(user)) || "Unknown User"
|
||||||
: (
|
: (
|
||||||
<Flex style={{ gap: "0.2em", justifyItems: "center" }}>
|
<Flex style={{ gap: "0.2em", justifyItems: "center" }}>
|
||||||
@owner
|
@owner
|
||||||
|
@ -16,6 +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 { getUniqueUsername, openUserProfile } from "@utils/discord";
|
||||||
import { UserUtils } from "@webpack/common";
|
import { UserUtils } from "@webpack/common";
|
||||||
|
|
||||||
import settings from "./settings";
|
import settings from "./settings";
|
||||||
@ -43,11 +44,19 @@ export async function onRelationshipRemove({ relationship: { type, id } }: Relat
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case RelationshipType.FRIEND:
|
case RelationshipType.FRIEND:
|
||||||
if (settings.store.friends)
|
if (settings.store.friends)
|
||||||
notify(`${user.tag} removed you as a friend.`, user.getAvatarURL(undefined, undefined, false));
|
notify(
|
||||||
|
`${getUniqueUsername(user)} removed you as a friend.`,
|
||||||
|
user.getAvatarURL(undefined, undefined, false),
|
||||||
|
() => openUserProfile(user.id)
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case RelationshipType.FRIEND_REQUEST:
|
case RelationshipType.FRIEND_REQUEST:
|
||||||
if (settings.store.friendRequestCancels)
|
if (settings.store.friendRequestCancels)
|
||||||
notify(`A friend request from ${user.tag} has been removed.`, user.getAvatarURL(undefined, undefined, false));
|
notify(
|
||||||
|
`A friend request from ${getUniqueUsername(user)} has been removed.`,
|
||||||
|
user.getAvatarURL(undefined, undefined, false),
|
||||||
|
() => openUserProfile(user.id)
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
import { DataStore, Notices } from "@api/index";
|
import { DataStore, Notices } from "@api/index";
|
||||||
import { showNotification } from "@api/Notifications";
|
import { showNotification } from "@api/Notifications";
|
||||||
|
import { getUniqueUsername, openUserProfile } from "@utils/discord";
|
||||||
import { ChannelStore, GuildMemberStore, GuildStore, RelationshipStore, UserStore, UserUtils } from "@webpack/common";
|
import { ChannelStore, GuildMemberStore, GuildStore, RelationshipStore, UserStore, UserUtils } from "@webpack/common";
|
||||||
|
|
||||||
import settings from "./settings";
|
import settings from "./settings";
|
||||||
@ -69,7 +70,11 @@ export async function syncAndRunChecks() {
|
|||||||
|
|
||||||
const user = await UserUtils.fetchUser(id).catch(() => void 0);
|
const user = await UserUtils.fetchUser(id).catch(() => void 0);
|
||||||
if (user)
|
if (user)
|
||||||
notify(`You are no longer friends with ${user.tag}.`, user.getAvatarURL(undefined, undefined, false));
|
notify(
|
||||||
|
`You are no longer friends with ${getUniqueUsername(user)}.`,
|
||||||
|
user.getAvatarURL(undefined, undefined, false),
|
||||||
|
() => openUserProfile(user.id)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,20 +84,25 @@ export async function syncAndRunChecks() {
|
|||||||
|
|
||||||
const user = await UserUtils.fetchUser(id).catch(() => void 0);
|
const user = await UserUtils.fetchUser(id).catch(() => void 0);
|
||||||
if (user)
|
if (user)
|
||||||
notify(`Friend request from ${user.tag} has been revoked.`, user.getAvatarURL(undefined, undefined, false));
|
notify(
|
||||||
|
`Friend request from ${getUniqueUsername(user)} has been revoked.`,
|
||||||
|
user.getAvatarURL(undefined, undefined, false),
|
||||||
|
() => openUserProfile(user.id)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function notify(text: string, icon?: string) {
|
export function notify(text: string, icon?: string, onClick?: () => void) {
|
||||||
if (settings.store.notices)
|
if (settings.store.notices)
|
||||||
Notices.showNotice(text, "OK", () => Notices.popNotice());
|
Notices.showNotice(text, "OK", () => Notices.popNotice());
|
||||||
|
|
||||||
showNotification({
|
showNotification({
|
||||||
title: "Relationship Notifier",
|
title: "Relationship Notifier",
|
||||||
body: text,
|
body: text,
|
||||||
icon
|
icon,
|
||||||
|
onClick
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +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 { openUserProfile } from "@utils/discord";
|
||||||
import { classes } from "@utils/misc";
|
import { classes } from "@utils/misc";
|
||||||
import { LazyComponent } from "@utils/react";
|
import { LazyComponent } from "@utils/react";
|
||||||
import { filters, findBulk } from "@webpack";
|
import { filters, findBulk } from "@webpack";
|
||||||
@ -24,7 +25,7 @@ import { Alerts, moment, Timestamp, UserStore } from "@webpack/common";
|
|||||||
import { Review, ReviewType } from "../entities";
|
import { Review, ReviewType } from "../entities";
|
||||||
import { deleteReview, reportReview } from "../reviewDbApi";
|
import { deleteReview, reportReview } from "../reviewDbApi";
|
||||||
import { settings } from "../settings";
|
import { settings } from "../settings";
|
||||||
import { canDeleteReview, cl, openUserProfileModal, showToast } from "../utils";
|
import { canDeleteReview, cl, showToast } from "../utils";
|
||||||
import { DeleteButton, ReportButton } from "./MessageButton";
|
import { DeleteButton, ReportButton } from "./MessageButton";
|
||||||
import ReviewBadge from "./ReviewBadge";
|
import ReviewBadge from "./ReviewBadge";
|
||||||
|
|
||||||
@ -49,7 +50,7 @@ export default LazyComponent(() => {
|
|||||||
|
|
||||||
return function ReviewComponent({ review, refetch }: { review: Review; refetch(): void; }) {
|
return function ReviewComponent({ review, refetch }: { review: Review; refetch(): void; }) {
|
||||||
function openModal() {
|
function openModal() {
|
||||||
openUserProfileModal(review.sender.discordID);
|
openUserProfile(review.sender.discordID);
|
||||||
}
|
}
|
||||||
|
|
||||||
function delReview() {
|
function delReview() {
|
||||||
|
@ -20,24 +20,13 @@ import { classNameFactory } from "@api/Styles";
|
|||||||
import { Logger } from "@utils/Logger";
|
import { Logger } from "@utils/Logger";
|
||||||
import { openModal } from "@utils/modal";
|
import { openModal } from "@utils/modal";
|
||||||
import { findByProps } from "@webpack";
|
import { findByProps } from "@webpack";
|
||||||
import { FluxDispatcher, React, SelectedChannelStore, Toasts, UserUtils } from "@webpack/common";
|
import { React, Toasts } from "@webpack/common";
|
||||||
|
|
||||||
import { Review, UserType } from "./entities";
|
import { Review, UserType } from "./entities";
|
||||||
import { settings } from "./settings";
|
import { settings } from "./settings";
|
||||||
|
|
||||||
export const cl = classNameFactory("vc-rdb-");
|
export const cl = classNameFactory("vc-rdb-");
|
||||||
|
|
||||||
export async function openUserProfileModal(userId: string) {
|
|
||||||
await UserUtils.fetchUser(userId);
|
|
||||||
|
|
||||||
await FluxDispatcher.dispatch({
|
|
||||||
type: "USER_PROFILE_MODAL_OPEN",
|
|
||||||
userId,
|
|
||||||
channelId: SelectedChannelStore.getChannelId(),
|
|
||||||
analyticsLocation: "Explosive Hotel"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function authorize(callback?: any) {
|
export function authorize(callback?: any) {
|
||||||
const { OAuth2AuthorizeModal } = findByProps("OAuth2AuthorizeModal");
|
const { OAuth2AuthorizeModal } = findByProps("OAuth2AuthorizeModal");
|
||||||
|
|
||||||
|
@ -19,13 +19,13 @@
|
|||||||
import { definePluginSettings } from "@api/Settings";
|
import { definePluginSettings } from "@api/Settings";
|
||||||
import ErrorBoundary from "@components/ErrorBoundary";
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
|
import { openUserProfile } from "@utils/discord";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { findByCodeLazy } from "@webpack";
|
import { findByCodeLazy } from "@webpack";
|
||||||
import { GuildMemberStore, React, RelationshipStore, SelectedChannelStore } from "@webpack/common";
|
import { GuildMemberStore, React, RelationshipStore } from "@webpack/common";
|
||||||
import { User } from "discord-types/general";
|
import { User } from "discord-types/general";
|
||||||
|
|
||||||
const Avatar = findByCodeLazy(".typingIndicatorRef", "svg");
|
const Avatar = findByCodeLazy(".typingIndicatorRef", "svg");
|
||||||
const openProfile = findByCodeLazy("friendToken", "USER_PROFILE_MODAL_OPEN");
|
|
||||||
|
|
||||||
const settings = definePluginSettings({
|
const settings = definePluginSettings({
|
||||||
showAvatars: {
|
showAvatars: {
|
||||||
@ -64,15 +64,7 @@ const TypingUser = ErrorBoundary.wrap(function ({ user, guildId }: Props) {
|
|||||||
<strong
|
<strong
|
||||||
role="button"
|
role="button"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
openProfile({
|
openUserProfile(user.id);
|
||||||
userId: user.id,
|
|
||||||
guildId,
|
|
||||||
channelId: SelectedChannelStore.getChannelId(),
|
|
||||||
analyticsLocation: {
|
|
||||||
page: guildId ? "Guild Channel" : "DM Channel",
|
|
||||||
section: "Profile Popout"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
style={{
|
style={{
|
||||||
display: "grid",
|
display: "grid",
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { MessageObject } from "@api/MessageEvents";
|
import { MessageObject } from "@api/MessageEvents";
|
||||||
import { findByPropsLazy, findLazy } from "@webpack";
|
import { findByCodeLazy, findByPropsLazy, findLazy } from "@webpack";
|
||||||
import { ChannelStore, ComponentDispatch, GuildStore, MaskedLink, ModalImageClasses, PrivateChannelsStore, SelectedChannelStore } from "@webpack/common";
|
import { ChannelStore, ComponentDispatch, GuildStore, MaskedLink, ModalImageClasses, PrivateChannelsStore, SelectedChannelStore, SelectedGuildStore, UserUtils } from "@webpack/common";
|
||||||
import { Guild, Message } from "discord-types/general";
|
import { Guild, Message, User } from "discord-types/general";
|
||||||
|
|
||||||
import { ImageModal, ModalRoot, ModalSize, openModal } from "./modal";
|
import { ImageModal, ModalRoot, ModalSize, openModal } from "./modal";
|
||||||
|
|
||||||
@ -99,3 +99,28 @@ export function openImageModal(url: string, props?: Partial<React.ComponentProps
|
|||||||
</ModalRoot>
|
</ModalRoot>
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const openProfile = findByCodeLazy("friendToken", "USER_PROFILE_MODAL_OPEN");
|
||||||
|
|
||||||
|
export async function openUserProfile(id: string) {
|
||||||
|
const user = await UserUtils.fetchUser(id);
|
||||||
|
if (!user) throw new Error("No such user: " + id);
|
||||||
|
|
||||||
|
const guildId = SelectedGuildStore.getGuildId();
|
||||||
|
openProfile({
|
||||||
|
userId: id,
|
||||||
|
guildId,
|
||||||
|
channelId: SelectedChannelStore.getChannelId(),
|
||||||
|
analyticsLocation: {
|
||||||
|
page: guildId ? "Guild Channel" : "DM Channel",
|
||||||
|
section: "Profile Popout"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the unique username for a user. Returns user.username for pomelo people, user.tag otherwise
|
||||||
|
*/
|
||||||
|
export function getUniqueUsername(user: User) {
|
||||||
|
return user.discriminator === "0" ? user.username : user.tag;
|
||||||
|
}
|
||||||
|
9
src/webpack/common/types/stores.d.ts
vendored
9
src/webpack/common/types/stores.d.ts
vendored
@ -20,14 +20,23 @@ import { Channel } from "discord-types/general";
|
|||||||
|
|
||||||
import { FluxDispatcher, FluxEvents } from "./utils";
|
import { FluxDispatcher, FluxEvents } from "./utils";
|
||||||
|
|
||||||
|
type GenericFunction = (...args: any[]) => any;
|
||||||
|
|
||||||
export class FluxStore {
|
export class FluxStore {
|
||||||
constructor(dispatcher: FluxDispatcher, eventHandlers?: Partial<Record<FluxEvents, (data: any) => void>>);
|
constructor(dispatcher: FluxDispatcher, eventHandlers?: Partial<Record<FluxEvents, (data: any) => void>>);
|
||||||
|
|
||||||
|
addChangeListener(callback: () => void): void;
|
||||||
|
addReactChangeListener(callback: () => void): void;
|
||||||
|
removeChangeListener(callback: () => void): void;
|
||||||
|
removeReactChangeListener(callback: () => void): void;
|
||||||
emitChange(): void;
|
emitChange(): void;
|
||||||
getDispatchToken(): string;
|
getDispatchToken(): string;
|
||||||
getName(): string;
|
getName(): string;
|
||||||
initialize(): void;
|
initialize(): void;
|
||||||
initializeIfNeeded(): void;
|
initializeIfNeeded(): void;
|
||||||
|
registerActionHandlers: GenericFunction;
|
||||||
|
syncWith: GenericFunction;
|
||||||
|
waitFor: GenericFunction;
|
||||||
__getLocalVars(): Record<string, any>;
|
__getLocalVars(): Record<string, any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user