Some More Fixes

This commit is contained in:
thororen1234 2024-06-20 12:35:05 -04:00
parent c8acee8955
commit a5cc68d9a2
6 changed files with 50 additions and 24 deletions

View file

@ -211,6 +211,13 @@ export function getOldestMessage(loggedMessageIds: LoggedMessages) {
return oldestMessage ?? null;
}
export function getMessage(channelId: string, messageId: string) {
const messags = Object.values(savedLoggedMessages)
.filter(m => !Array.isArray(m) && m.message != null) as MessageRecord[];
return messags.find(m => m.message.channel_id === channelId && m.message.id === messageId);
}
export async function deleteOldestMessageWithoutSaving(loggedMessages: LoggedMessages) {
const oldestMessage = getOldestMessage(loggedMessages);
if (!oldestMessage || !oldestMessage.message) {

View file

@ -21,7 +21,7 @@ import { openUserProfile } from "@utils/discord";
import { copyWithToast } from "@utils/misc";
import { closeAllModals, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
import { LazyComponent, useAwaiter } from "@utils/react";
import { find, findByCode, findByPropsLazy } from "@webpack";
import { find, findByCode, findByCodeLazy } from "@webpack";
import { Alerts, Button, ChannelStore, ContextMenuApi, FluxDispatcher, Menu, NavigationRouter, React, TabBar, Text, TextInput, useCallback, useMemo, useRef, useState } from "@webpack/common";
import { User } from "discord-types/general";
@ -61,7 +61,7 @@ export interface ChildrenAccProops {
showClydeAiEmbeds: boolean;
}
const ChannelRecords = findByPropsLazy("PrivateChannelRecord");
const PrivateChannelRecord = findByCodeLazy(".is_message_request_timestamp,");
const MessagePreview = LazyComponent<MessagePreviewProps>(() => find(m => m?.type?.toString().includes("previewLinkTarget:") && !m?.type?.toString().includes("HAS_THREAD")));
const ChildrenAccessories = LazyComponent<ChildrenAccProops>(() => findByCode("channelMessageProps:{message:"));
@ -448,7 +448,7 @@ function LMessage({ log, isGroupStart, forceUpdate, }: LMessageProps) {
childrenAccessories={
<ChildrenAccessories
channelMessageProps={{
channel: ChannelStore.getChannel(message.channel_id) || new ChannelRecords.PrivateChannelRecord({ id: "" }),
channel: ChannelStore.getChannel(message.channel_id) || new PrivateChannelRecord({ id: "" }),
message,
compact: false,
groupId: "1",

View file

@ -37,7 +37,7 @@ import { openLogModal } from "./components/LogsModal";
import { addMessage, loggedMessages, MessageLoggerStore, removeLog } from "./LoggedMessageManager";
import * as LoggedMessageManager from "./LoggedMessageManager";
import { LoadMessagePayload, LoggedAttachment, LoggedMessage, LoggedMessageJSON, MessageCreatePayload, MessageDeleteBulkPayload, MessageDeletePayload, MessageUpdatePayload } from "./types";
import { addToXAndRemoveFromOpposite, cleanUpCachedMessage, cleanupUserObject, doesBlobUrlExist, getNative, isGhostPinged, ListType, mapEditHistory, reAddDeletedMessages, removeFromX } from "./utils";
import { addToXAndRemoveFromOpposite, cleanUpCachedMessage, cleanupUserObject, doesBlobUrlExist, getNative, isGhostPinged, ListType, mapEditHistory, messageJsonToMessageClass, reAddDeletedMessages, removeFromX } from "./utils";
import { DEFAULT_IMAGE_CACHE_DIR } from "./utils/constants";
import { shouldIgnore } from "./utils/index";
import { LimitedMap } from "./utils/LimitedMap";
@ -594,8 +594,8 @@ export default definePlugin({
{
find: "THREAD_STARTER_MESSAGE?null===",
replacement: {
match: /(attachments: \i\(.{1,500})deleted:.{1,50},editHistory:.{1,30},/,
replace: "$1deleted: $self.getDeleted(...arguments),editHistory: $self.getEdited(...arguments),"
match: / deleted:\i\.deleted, editHistory:\i\.editHistory,/,
replace: "deleted:$self.getDeleted(...arguments), editHistory:$self.getEdited(...arguments),"
}
},
@ -637,7 +637,7 @@ export default definePlugin({
{
find: "Using PollReferenceMessageContext without",
replacement: {
match: /\i\.(?:default\.)?focusMessage\(/,
match: /(?:\i\.)?\i\.(?:default\.)?focusMessage\(/,
replace: "!(arguments[0]?.message?.deleted || arguments[0]?.message?.editHistory?.length > 0) && $&"
}
},
@ -747,10 +747,23 @@ export default definePlugin({
},
async start() {
this.oldGetMessage = MessageStore.getMessage;
// we have to do this because the original message logger fetches the message from the store now
MessageStore.getMessage = (channelId: string, messageId: string) => {
const MLMessage = LoggedMessageManager.getMessage(channelId, messageId);
if (MLMessage?.message) return messageJsonToMessageClass(MLMessage);
return this.oldGetMessage(channelId, messageId);
};
Native.init();
const { imageCacheDir, logsDir } = await Native.getSettings();
settings.store.imageCacheDir = imageCacheDir;
settings.store.logsDir = logsDir;
},
stop() {
MessageStore.getMessage = this.oldGetMessage;
}
});

View file

@ -18,7 +18,7 @@
import { get, set } from "@api/DataStore";
import { PluginNative } from "@utils/types";
import { findByPropsLazy, findLazy } from "@webpack";
import { findByCodeLazy, findLazy } from "@webpack";
import { ChannelStore, moment, UserStore } from "@webpack/common";
import { LOGGED_MESSAGES_KEY, MessageLoggerStore } from "../LoggedMessageManager";
@ -29,7 +29,7 @@ import { memoize } from "./memoize";
const MessageClass: any = findLazy(m => m?.prototype?.isEdited);
const AuthorClass = findLazy(m => m?.prototype?.getAvatarURL);
const embedModule = findByPropsLazy("sanitizeEmbed");
const sanitizeEmbed = findByCodeLazy('"embed_"),');
export function getGuildIdByChannel(channel_id: string) {
return ChannelStore.getChannel(channel_id)?.guild_id;
@ -104,7 +104,7 @@ export const messageJsonToMessageClass = memoize((log: { message: LoggedMessageJ
message.author = new AuthorClass(message.author);
message.author.nick = message.author.globalName ?? message.author.username;
message.embeds = message.embeds.map(e => embedModule.sanitizeEmbed(message.channel_id, message.id, e));
message.embeds = message.embeds.map(e => sanitizeEmbed(message.channel_id, message.id, e));
if (message.poll)
message.poll.expiry = moment(message.poll.expiry);