mirror of
https://github.com/Vendicated/Vencord
synced 2024-09-13 04:29:24 -04:00
Merge branch 'dev' of https://github.com/Vendicated/Vencord into discord-types
This commit is contained in:
commit
56f45c04f0
9 changed files with 235 additions and 32 deletions
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "vencord",
|
||||
"private": "true",
|
||||
"version": "1.9.4",
|
||||
"version": "1.9.5",
|
||||
"description": "The cutest Discord client mod",
|
||||
"homepage": "https://github.com/Vendicated/Vencord#readme",
|
||||
"bugs": {
|
||||
|
|
|
@ -4,12 +4,14 @@
|
|||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import type { StringProperties } from "../internal";
|
||||
|
||||
// Original name: Record
|
||||
// Renamed to avoid name conflicts with TypeScripts's Record utility type.
|
||||
export declare class ImmutableRecord<
|
||||
OwnProperties extends Record<PropertyKey, unknown> = Record<PropertyKey, unknown>
|
||||
> {
|
||||
merge(collection: Partial<OwnProperties>): this;
|
||||
merge(collection: Partial<StringProperties<OwnProperties>>): this;
|
||||
set<Key extends keyof OwnProperties>(key: Key, value: OwnProperties[Key]): this;
|
||||
toJS(): OwnProperties;
|
||||
update<Key extends keyof OwnProperties>(
|
||||
|
|
|
@ -27,7 +27,7 @@ export declare class FormattedMessage<
|
|||
*/
|
||||
constructor(
|
||||
message: string,
|
||||
locales?: string | string[] /* = MessageFormat.defaultLocale */,
|
||||
locales?: string | string[] | undefined /* = MessageFormat.defaultLocale */,
|
||||
hasMarkdown?: Markdown
|
||||
);
|
||||
|
||||
|
|
|
@ -53,3 +53,6 @@ export type Stringable
|
|||
= { [Symbol.toPrimitive]: (hint: "default" | "string") => StringablePrimitive; }
|
||||
| ({ toString: () => StringablePrimitive; } | { valueOf: () => StringablePrimitive; })
|
||||
& { [Symbol.toPrimitive]?: Nullish; };
|
||||
|
||||
/** @internal */
|
||||
export type StringProperties<T> = { [Key in Exclude<keyof T, symbol>]: T[Key]; };
|
||||
|
|
100
src/plugins/messageLogger/HistoryModal.tsx
Normal file
100
src/plugins/messageLogger/HistoryModal.tsx
Normal file
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2024 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { classNameFactory } from "@api/Styles";
|
||||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import { Margins } from "@utils/margins";
|
||||
import { classes } from "@utils/misc";
|
||||
import { ModalCloseButton, ModalContent, ModalHeader, type ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
|
||||
import type { MessageRecord, MessageRecordOwnProperties } from "@vencord/discord-types";
|
||||
import { findByPropsLazy } from "@webpack";
|
||||
import { TabBar, Text, Timestamp, TooltipContainer, useState } from "@webpack/common";
|
||||
|
||||
import { parseEditContent } from ".";
|
||||
|
||||
type MLMessageRecordOwnProperties = MessageRecordOwnProperties & Pick<MLMessageRecord, "deleted" | "editHistory">;
|
||||
|
||||
interface MLMessageRecord extends MessageRecord<MLMessageRecordOwnProperties> {
|
||||
deleted: boolean;
|
||||
editHistory: { timestamp: Date; content: string; }[];
|
||||
firstEditTimestamp: Date;
|
||||
}
|
||||
|
||||
const CodeContainerClasses: Record<string, string> = findByPropsLazy("markup", "codeContainer");
|
||||
const MiscClasses: Record<string, string> = findByPropsLazy("messageContent", "markupRtl");
|
||||
|
||||
const cl = classNameFactory("vc-ml-modal-");
|
||||
|
||||
export function openHistoryModal(message: MLMessageRecord) {
|
||||
openModal(props => (
|
||||
<ErrorBoundary>
|
||||
<HistoryModal
|
||||
modalProps={props}
|
||||
message={message}
|
||||
/>
|
||||
</ErrorBoundary>
|
||||
));
|
||||
}
|
||||
|
||||
export function HistoryModal({ modalProps, message }: { modalProps: ModalProps; message: MLMessageRecord; }) {
|
||||
const [currentTab, setCurrentTab] = useState(message.editHistory.length);
|
||||
const timestamps = [message.firstEditTimestamp, ...message.editHistory.map(m => m.timestamp)];
|
||||
const contents = [...message.editHistory.map(m => m.content), message.content];
|
||||
|
||||
return (
|
||||
<ModalRoot {...modalProps} size={ModalSize.LARGE}>
|
||||
<ModalHeader className={cl("head")}>
|
||||
<Text variant="heading-lg/semibold" style={{ flexGrow: 1 }}>Message Edit History</Text>
|
||||
<ModalCloseButton onClick={modalProps.onClose} />
|
||||
</ModalHeader>
|
||||
|
||||
<ModalContent className={cl("contents")}>
|
||||
<TabBar
|
||||
type="top"
|
||||
look="brand"
|
||||
className={classes("vc-settings-tab-bar", cl("tab-bar"))}
|
||||
selectedItem={currentTab}
|
||||
onItemSelect={setCurrentTab}
|
||||
>
|
||||
{message.firstEditTimestamp.getTime() !== message.timestamp.getTime() && (
|
||||
<TooltipContainer text="This edit state was not logged so it can't be displayed.">
|
||||
<TabBar.Item
|
||||
className="vc-settings-tab-bar-item"
|
||||
id={-1}
|
||||
disabled
|
||||
>
|
||||
<Timestamp
|
||||
className={cl("timestamp")}
|
||||
timestamp={message.timestamp}
|
||||
isEdited={true}
|
||||
isInline={false}
|
||||
/>
|
||||
</TabBar.Item>
|
||||
</TooltipContainer>
|
||||
)}
|
||||
|
||||
{timestamps.map((timestamp, index) => (
|
||||
<TabBar.Item
|
||||
className="vc-settings-tab-bar-item"
|
||||
id={index}
|
||||
>
|
||||
<Timestamp
|
||||
className={cl("timestamp")}
|
||||
timestamp={timestamp}
|
||||
isEdited={true}
|
||||
isInline={false}
|
||||
/>
|
||||
</TabBar.Item>
|
||||
))}
|
||||
</TabBar>
|
||||
|
||||
<div className={classes(CodeContainerClasses.markup, MiscClasses.messageContent, Margins.top20)}>
|
||||
{parseEditContent(contents[currentTab]!, message)}
|
||||
</div>
|
||||
</ModalContent>
|
||||
</ModalRoot>
|
||||
);
|
||||
}
|
|
@ -25,23 +25,29 @@ import { Settings } from "@api/Settings";
|
|||
import { disableStyle, enableStyle } from "@api/Styles";
|
||||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import { Devs } from "@utils/constants";
|
||||
import { proxyLazy } from "@utils/lazy";
|
||||
import { Logger } from "@utils/Logger";
|
||||
import { classes } from "@utils/misc";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import type { ChannelMessages, MessageRecord, MessageRecordOwnProperties } from "@vencord/discord-types";
|
||||
import { findByPropsLazy } from "@webpack";
|
||||
import { ChannelStore, FluxDispatcher, i18n, MarkupUtils, Menu, MessageStore, Timestamp, UserStore, useStateFromStores } from "@webpack/common";
|
||||
import { type ChannelMessages, type FormattedMessage, MessageFlags, type MessageRecord, type MessageRecordOwnProperties } from "@vencord/discord-types";
|
||||
import { findByCodeLazy, findByPropsLazy } from "@webpack";
|
||||
import { ChannelStore, FluxDispatcher, i18n, MarkupUtils, Menu, MessageStore, SelectedChannelStore, Timestamp, UserStore, useStateFromStores } from "@webpack/common";
|
||||
|
||||
import overlayStyle from "./deleteStyleOverlay.css?managed";
|
||||
import textStyle from "./deleteStyleText.css?managed";
|
||||
import { openHistoryModal } from "./HistoryModal";
|
||||
|
||||
type MLMessageRecordOwnProperties = MessageRecordOwnProperties & Pick<MLMessageRecord, "deleted" | "editHistory">;
|
||||
|
||||
interface MLMessageRecord extends MessageRecord<MLMessageRecordOwnProperties> {
|
||||
deleted?: boolean;
|
||||
editHistory?: { timestamp: Date; content: string; }[];
|
||||
firstEditTimestamp?: Date;
|
||||
}
|
||||
|
||||
const styles: Record<string, string> = findByPropsLazy("edited", "communicationDisabled", "isSystemMessage");
|
||||
const getMessage: (message?: string | null, locales?: string | string[]) => FormattedMessage
|
||||
= findByCodeLazy('replace(/^\\n+|\\n+$/g,"")');
|
||||
|
||||
function addDeleteStyle() {
|
||||
if (Settings.plugins.MessageLogger!.deleteStyle === "text") {
|
||||
|
@ -132,10 +138,22 @@ const patchChannelContextMenu = ((children, { channel }) => {
|
|||
);
|
||||
}) satisfies NavContextMenuPatchCallback;
|
||||
|
||||
export function parseEditContent(content: string, message: MessageRecord) {
|
||||
return MarkupUtils.parse(content, true, {
|
||||
channelId: message.channel_id,
|
||||
messageId: message.id,
|
||||
allowLinks: true,
|
||||
allowHeading: true,
|
||||
allowList: true,
|
||||
allowEmojiLinks: true,
|
||||
viewingChannelId: SelectedChannelStore.getChannelId(),
|
||||
});
|
||||
}
|
||||
|
||||
export default definePlugin({
|
||||
name: "MessageLogger",
|
||||
description: "Temporarily logs deleted and edited messages.",
|
||||
authors: [Devs.rushii, Devs.Ven, Devs.AutumnVN, Devs.Nickyux],
|
||||
authors: [Devs.rushii, Devs.Ven, Devs.AutumnVN, Devs.Nickyux, Devs.Kyuuhachi],
|
||||
dependencies: ["MessageUpdaterAPI"],
|
||||
|
||||
contextMenus: {
|
||||
|
@ -155,13 +173,13 @@ export default definePlugin({
|
|||
() => MessageStore.getMessage(channelId, messageId) as MLMessageRecord | undefined,
|
||||
null,
|
||||
(oldMsg, newMsg) => oldMsg?.editHistory === newMsg?.editHistory
|
||||
);
|
||||
)!;
|
||||
|
||||
return (
|
||||
return Settings.plugins.MessageLogger!.inlineEdits && (
|
||||
<>
|
||||
{message!.editHistory?.map(edit => (
|
||||
{message.editHistory?.map(edit => (
|
||||
<div className="messagelogger-edited">
|
||||
{MarkupUtils.parse(edit.content)}
|
||||
{parseEditContent(edit.content, message)}
|
||||
<Timestamp
|
||||
timestamp={edit.timestamp}
|
||||
isEdited={true}
|
||||
|
@ -195,11 +213,21 @@ export default definePlugin({
|
|||
description: "Whether to log deleted messages",
|
||||
default: true,
|
||||
},
|
||||
collapseDeleted: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Whether to collapse deleted messages, similar to blocked messages",
|
||||
default: false
|
||||
},
|
||||
logEdits: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Whether to log edited messages",
|
||||
default: true,
|
||||
},
|
||||
inlineEdits: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Whether to display edit history as part of message content",
|
||||
default: true
|
||||
},
|
||||
ignoreBots: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Whether to ignore messages by bots",
|
||||
|
@ -236,17 +264,22 @@ export default definePlugin({
|
|||
const msg = channelMessages!.get(id);
|
||||
if (!msg) return;
|
||||
|
||||
const EPHEMERAL = 64;
|
||||
const shouldIgnore = data.mlDeleted ||
|
||||
(msg.flags & EPHEMERAL) === EPHEMERAL ||
|
||||
msg.hasFlag(MessageFlags.EPHEMERAL) ||
|
||||
this.shouldIgnore(msg);
|
||||
|
||||
if (shouldIgnore) {
|
||||
channelMessages = channelMessages!.remove(id);
|
||||
} else {
|
||||
channelMessages = channelMessages!.update(id, m => (m as MLMessageRecord)
|
||||
.set("deleted", true)
|
||||
.set("attachments", m.attachments.map(a => ((a as any).deleted = true, a))));
|
||||
channelMessages = channelMessages!.update(id,
|
||||
m => (m as MLMessageRecord).merge({
|
||||
deleted: true,
|
||||
attachments: m.attachments.map(a => {
|
||||
(a as any).deleted = true;
|
||||
return a;
|
||||
})
|
||||
})
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -276,6 +309,23 @@ export default definePlugin({
|
|||
(message.channel_id === "1026515880080842772" && message.author.id === "1017176847865352332");
|
||||
},
|
||||
|
||||
EditMarker({ message, className, children, ...props }: any) {
|
||||
return (
|
||||
<span
|
||||
{...props}
|
||||
className={classes("messagelogger-edit-marker", className)}
|
||||
onClick={() => { openHistoryModal(message); }}
|
||||
aria-role="button"
|
||||
>
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
|
||||
Messages: proxyLazy(() => ({
|
||||
DELETED_MESSAGE_COUNT: getMessage("{count, plural, =0 {No deleted messages} one {{count} deleted message} other {{count} deleted messages}}")
|
||||
})),
|
||||
|
||||
patches: [
|
||||
{
|
||||
// MessageStore
|
||||
|
@ -329,7 +379,8 @@ export default definePlugin({
|
|||
match: /this\.customRenderedContent=(\i)\.customRenderedContent,/,
|
||||
replace: "this.customRenderedContent = $1.customRenderedContent," +
|
||||
"this.deleted = $1.deleted || false," +
|
||||
"this.editHistory = $1.editHistory || [],"
|
||||
"this.editHistory = $1.editHistory || []," +
|
||||
"this.firstEditTimestamp = $1.firstEditTimestamp || this.editedTimestamp || this.timestamp,"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -342,7 +393,7 @@ export default definePlugin({
|
|||
// Pass through editHistory & deleted & original attachments to the "edited message" transformer
|
||||
match: /(?<=null!=\i\.edited_timestamp\)return )\i\(\i,\{reactions:(\i)\.reactions.{0,50}\}\)/,
|
||||
replace:
|
||||
"Object.assign($&,{ deleted:$1.deleted, editHistory:$1.editHistory })"
|
||||
"Object.assign($&,{ deleted:$1.deleted, editHistory:$1.editHistory, firstEditTimestamp:$1.firstEditTimestamp })"
|
||||
},
|
||||
|
||||
{
|
||||
|
@ -361,7 +412,8 @@ export default definePlugin({
|
|||
" return $2;" +
|
||||
"})())," +
|
||||
"deleted: arguments[1]?.deleted," +
|
||||
"editHistory: arguments[1]?.editHistory"
|
||||
"editHistory: arguments[1]?.editHistory," +
|
||||
"firstEditTimestamp: new Date(arguments[1]?.firstEditTimestamp ?? $2.editedTimestamp ?? $2.timestamp)"
|
||||
},
|
||||
{
|
||||
// Preserve deleted attribute on attachments
|
||||
|
@ -409,6 +461,11 @@ export default definePlugin({
|
|||
// Render editHistory in the deepest div for message content
|
||||
match: /(\)\("div",\{id:.+?children:\[)/,
|
||||
replace: "$1 (!!arguments[0].message.editHistory?.length && $self.renderEdits(arguments[0])),"
|
||||
},
|
||||
{
|
||||
// Make edit marker clickable
|
||||
match: /"span",\{(?=className:\i\.edited,)/,
|
||||
replace: "$self.EditMarker,{message:arguments[0].message,"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -438,6 +495,30 @@ export default definePlugin({
|
|||
replace: "children:arguments[0].message.deleted?[]:$1"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Message grouping
|
||||
find: "NON_COLLAPSIBLE.has(",
|
||||
replacement: {
|
||||
match: /if\((\i)\.blocked\)return \i\.\i\.MESSAGE_GROUP_BLOCKED;/,
|
||||
replace: '$&else if($1.deleted) return"MESSAGE_GROUP_DELETED";',
|
||||
},
|
||||
predicate: () => Settings.plugins.MessageLogger!.collapseDeleted
|
||||
},
|
||||
{
|
||||
// Message group rendering
|
||||
find: "Messages.NEW_MESSAGES_ESTIMATED_WITH_DATE",
|
||||
replacement: [
|
||||
{
|
||||
match: /(\i).type===\i\.\i\.MESSAGE_GROUP_BLOCKED\|\|/,
|
||||
replace: '$&$1.type==="MESSAGE_GROUP_DELETED"||',
|
||||
},
|
||||
{
|
||||
match: /(\i).type===\i\.\i\.MESSAGE_GROUP_BLOCKED\?.*?:/,
|
||||
replace: '$&$1.type==="MESSAGE_GROUP_DELETED"?$self.Messages.DELETED_MESSAGE_COUNT:',
|
||||
},
|
||||
],
|
||||
predicate: () => Settings.plugins.MessageLogger!.collapseDeleted
|
||||
}
|
||||
]
|
||||
});
|
||||
|
|
|
@ -38,3 +38,17 @@
|
|||
.theme-light .messagelogger-edited {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.messagelogger-edit-marker {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.vc-ml-modal-timestamp {
|
||||
cursor: unset;
|
||||
height: unset;
|
||||
}
|
||||
|
||||
.vc-ml-modal-tab-bar {
|
||||
flex-wrap: wrap;
|
||||
gap: 16px;
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ export default definePlugin({
|
|||
const { nick } = author;
|
||||
const prefix = withMentionPrefix ? "@" : "";
|
||||
|
||||
if (isRepliedMessage && !settings.store.inReplies || username === nick.toLowerCase())
|
||||
if (isRepliedMessage && !settings.store.inReplies || username.toLowerCase() === nick.toLowerCase())
|
||||
return <>{prefix}{nick}</>;
|
||||
|
||||
if (settings.store.mode === "user-nick")
|
||||
|
|
|
@ -30,6 +30,7 @@ import definePlugin, { OptionType } from "@utils/types";
|
|||
import type { MessageRecord } from "@vencord/discord-types";
|
||||
import { Button, ChannelStore, Forms, i18n, Menu, Text } from "@webpack/common";
|
||||
import type { MouseEvent } from "react";
|
||||
import type { Jsonify } from "type-fest";
|
||||
|
||||
const CopyIcon = () => (
|
||||
<svg
|
||||
|
@ -47,18 +48,20 @@ const sortObject = <T extends object>(obj: T): T =>
|
|||
Object.fromEntries(Object.entries(obj).sort(([k1], [k2]) => k1.localeCompare(k2))) as T;
|
||||
|
||||
function cleanMessage(message: MessageRecord) {
|
||||
const clone = sortObject(JSON.parse(JSON.stringify(message)));
|
||||
for (const key of [
|
||||
"email",
|
||||
"phone",
|
||||
"mfaEnabled",
|
||||
"personalConnectionId"
|
||||
]) delete clone.author[key];
|
||||
const clone = sortObject<Jsonify<MessageRecord>>(JSON.parse(JSON.stringify(message)));
|
||||
|
||||
const { author } = clone;
|
||||
author.email = null;
|
||||
author.mfaEnabled = false;
|
||||
author.personalConnectionId = null;
|
||||
author.phone = null;
|
||||
|
||||
// message logger added properties
|
||||
delete clone.editHistory;
|
||||
delete clone.deleted;
|
||||
clone.attachments?.forEach((a: any) => { delete a.deleted; });
|
||||
delete (clone as any).editHistory;
|
||||
delete (clone as any).deleted;
|
||||
delete (clone as any).firstEditTimestamp;
|
||||
for (const a of clone.attachments)
|
||||
delete (a as any).deleted;
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
@ -103,8 +106,8 @@ function openViewRawModal(json: string, type: string, msgContent?: string) {
|
|||
}
|
||||
|
||||
function openViewRawModalMessage(message: MessageRecord) {
|
||||
message = cleanMessage(message);
|
||||
const messageJSON = JSON.stringify(message, null, 4);
|
||||
const cleanedMessage = cleanMessage(message);
|
||||
const messageJSON = JSON.stringify(cleanedMessage, null, 4);
|
||||
|
||||
openViewRawModal(messageJSON, "Message", message.content);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue