[ShowHiddenChannels] Fix last message date (#342)

main
Nico 2 years ago committed by GitHub
parent 456164253d
commit 3efc79224f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,7 +17,8 @@
*/ */
import { mergeDefaults } from "@utils/misc"; import { mergeDefaults } from "@utils/misc";
import { findByCodeLazy, findByPropsLazy, waitFor } from "@webpack"; import { findByCodeLazy, findByPropsLazy } from "@webpack";
import { SnowflakeUtils } from "@webpack/common";
import { Message } from "discord-types/general"; import { Message } from "discord-types/general";
import type { PartialDeep } from "type-fest"; import type { PartialDeep } from "type-fest";
@ -26,9 +27,6 @@ import { Argument } from "./types";
const createBotMessage = findByCodeLazy('username:"Clyde"'); const createBotMessage = findByCodeLazy('username:"Clyde"');
const MessageSender = findByPropsLazy("receiveMessage"); const MessageSender = findByPropsLazy("receiveMessage");
let SnowflakeUtils: any;
waitFor("fromTimestamp", m => SnowflakeUtils = m);
export function generateId() { export function generateId() {
return `-${SnowflakeUtils.fromTimestamp(Date.now())}`; return `-${SnowflakeUtils.fromTimestamp(Date.now())}`;
} }

@ -23,7 +23,7 @@ import { Devs } from "@utils/constants";
import { ModalContent, ModalFooter, ModalHeader, ModalRoot, ModalSize, openModal } from "@utils/modal"; import { ModalContent, ModalFooter, ModalHeader, ModalRoot, ModalSize, openModal } from "@utils/modal";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { waitFor } from "@webpack"; import { waitFor } from "@webpack";
import { Button, ChannelStore, Text } from "@webpack/common"; import { Button, ChannelStore, SnowflakeUtils, Text } from "@webpack/common";
const CONNECT = 1048576n; const CONNECT = 1048576n;
const VIEW_CHANNEL = 1024n; const VIEW_CHANNEL = 1024n;
@ -117,7 +117,7 @@ export default definePlugin({
const isHidden = this.isHiddenChannel(channel); const isHidden = this.isHiddenChannel(channel);
// check for type again, otherwise it would show it for hidden stage channels // check for type again, otherwise it would show it for hidden stage channels
if (channel.type === 0 && isHidden) { if (channel.type === 0 && isHidden) {
const lastMessageDate = channel.lastActiveTimestamp ? new Date(channel.lastActiveTimestamp).toLocaleString() : null; const lastMessageDate = channel.lastMessageId ? new Date(SnowflakeUtils.extractTimestamp(channel.lastMessageId)).toLocaleString() : null;
openModal(modalProps => ( openModal(modalProps => (
<ModalRoot size={ModalSize.SMALL} {...modalProps}> <ModalRoot size={ModalSize.SMALL} {...modalProps}>
<ModalHeader> <ModalHeader>

@ -76,6 +76,9 @@ export const TextArea = findByCodeLazy("handleSetRef", "textArea") as React.Comp
export const Select = LazyComponent(() => findByCode("optionClassName", "popoutPosition", "autoFocus", "maxVisibleItems")); export const Select = LazyComponent(() => findByCode("optionClassName", "popoutPosition", "autoFocus", "maxVisibleItems"));
export const Slider = LazyComponent(() => findByCode("closestMarkerIndex", "stickToMarkers")); export const Slider = LazyComponent(() => findByCode("closestMarkerIndex", "stickToMarkers"));
export let SnowflakeUtils: { fromTimestamp: (timestamp: number) => string, extractTimestamp: (snowflake: string) => number };
waitFor(["fromTimestamp", "extractTimestamp"], m => SnowflakeUtils = m);
export let Parser: any; export let Parser: any;
export let Alerts: { export let Alerts: {
show(alert: { show(alert: {

Loading…
Cancel
Save