From a73d09a2f0d2adc7ff56e6f6004cd6ec50e202e9 Mon Sep 17 00:00:00 2001
From: Syncx <47534062+Syncxv@users.noreply.github.com>
Date: Wed, 13 Sep 2023 07:14:17 +1000
Subject: [PATCH] PreviewMessage: Add attachments (& misc changes) (#1715)
---
src/plugins/favEmojiFirst/README.md | 6 ++
.../index.ts} | 0
src/plugins/favGifSearch/README.md | 5 ++
.../index.tsx} | 2 +-
src/plugins/imageZoom/README.md | 6 ++
src/plugins/imageZoom/index.tsx | 9 +++
src/plugins/previewMessage/README.md | 5 ++
.../index.tsx} | 69 +++++++++++++++++--
src/plugins/searchReply/README.md | 5 ++
.../index.tsx} | 0
src/webpack/common/types/menu.d.ts | 9 ++-
11 files changed, 108 insertions(+), 8 deletions(-)
create mode 100644 src/plugins/favEmojiFirst/README.md
rename src/plugins/{favEmojiFirst.ts => favEmojiFirst/index.ts} (100%)
create mode 100644 src/plugins/favGifSearch/README.md
rename src/plugins/{favGifSearch.tsx => favGifSearch/index.tsx} (99%)
create mode 100644 src/plugins/imageZoom/README.md
create mode 100644 src/plugins/previewMessage/README.md
rename src/plugins/{previewMessage.tsx => previewMessage/index.tsx} (56%)
create mode 100644 src/plugins/searchReply/README.md
rename src/plugins/{searchReply.tsx => searchReply/index.tsx} (100%)
diff --git a/src/plugins/favEmojiFirst/README.md b/src/plugins/favEmojiFirst/README.md
new file mode 100644
index 00000000..dc844802
--- /dev/null
+++ b/src/plugins/favEmojiFirst/README.md
@@ -0,0 +1,6 @@
+# FavoriteEmojiFirst
+
+Puts your favorite emoji first in the emoji autocomplete.
+
+![FavEmojis](https://i.imgur.com/mEFCoZG.png)
+![Example](https://i.imgur.com/wY3Tc43.png)
diff --git a/src/plugins/favEmojiFirst.ts b/src/plugins/favEmojiFirst/index.ts
similarity index 100%
rename from src/plugins/favEmojiFirst.ts
rename to src/plugins/favEmojiFirst/index.ts
diff --git a/src/plugins/favGifSearch/README.md b/src/plugins/favGifSearch/README.md
new file mode 100644
index 00000000..c0768859
--- /dev/null
+++ b/src/plugins/favGifSearch/README.md
@@ -0,0 +1,5 @@
+# FavoriteGifSearch
+
+Adds a search bar to favorite gifs.
+
+![Screenshot](https://i.imgur.com/Bcgb7PD.png)
diff --git a/src/plugins/favGifSearch.tsx b/src/plugins/favGifSearch/index.tsx
similarity index 99%
rename from src/plugins/favGifSearch.tsx
rename to src/plugins/favGifSearch/index.tsx
index db575a03..d10c5153 100644
--- a/src/plugins/favGifSearch.tsx
+++ b/src/plugins/favGifSearch/index.tsx
@@ -87,7 +87,7 @@ export const settings = definePluginSettings({
export default definePlugin({
name: "FavoriteGifSearch",
authors: [Devs.Aria],
- description: "Adds a search bar for favorite gifs",
+ description: "Adds a search bar to favorite gifs.",
patches: [
{
diff --git a/src/plugins/imageZoom/README.md b/src/plugins/imageZoom/README.md
new file mode 100644
index 00000000..8e3b7efd
--- /dev/null
+++ b/src/plugins/imageZoom/README.md
@@ -0,0 +1,6 @@
+# ImageZoom
+
+Lets you zoom in to images and gifs. Use scroll wheel to zoom in and shift + scroll wheel to increase lens radius / size
+
+![Example](https://i.imgur.com/VJdo4aq.png)
+![ContextMenu](https://i.imgur.com/0oaRM2s.png)
diff --git a/src/plugins/imageZoom/index.tsx b/src/plugins/imageZoom/index.tsx
index 71540f2b..cca0db02 100644
--- a/src/plugins/imageZoom/index.tsx
+++ b/src/plugins/imageZoom/index.tsx
@@ -99,6 +99,15 @@ const imageContextMenuPatch: NavContextMenuPatchCallback = children => () => {
ContextMenu.close();
}}
/>
+
{
+ settings.store.nearestNeighbour = !settings.store.nearestNeighbour;
+ ContextMenu.close();
+ }}
+ />
.
*/
-import { sendBotMessage } from "@api/Commands";
+import { generateId, sendBotMessage } from "@api/Commands";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
+import { findByPropsLazy } from "@webpack";
import { Button, ButtonLooks, ButtonWrapperClasses, DraftStore, DraftType, SelectedChannelStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common";
+import { MessageAttachment } from "discord-types/general";
interface Props {
type: {
analyticsName: string;
+ isEmpty: boolean;
+ attachments: boolean;
};
}
+const UploadStore = findByPropsLazy("getUploads");
+
const getDraft = (channelId: string) => DraftStore.getDraft(channelId, DraftType.ChannelMessage);
+
+const getImageBox = (url: string): Promise<{ width: number, height: number; } | null> =>
+ new Promise(res => {
+ const img = new Image();
+ img.onload = () =>
+ res({ width: img.width, height: img.height });
+
+ img.onerror = () =>
+ res(null);
+
+ img.src = url;
+ });
+
+
+const getAttachments = async (channelId: string) =>
+ await Promise.all(
+ UploadStore.getUploads(channelId, DraftType.ChannelMessage)
+ .map(async (upload: any) => {
+ const { isImage, filename, spoiler, item: { file } } = upload;
+ const url = URL.createObjectURL(file);
+ const attachment: MessageAttachment = {
+ id: generateId(),
+ filename: spoiler ? "SPOILER_" + filename : filename,
+ // weird eh? if i give it the normal content type the preview doenst work
+ content_type: undefined,
+ size: await upload.getSize(),
+ spoiler,
+ // discord adds query params to the url, so we need to add a hash to prevent that
+ url: url + "#",
+ proxy_url: url + "#",
+ };
+
+ if (isImage) {
+ const box = await getImageBox(url);
+ if (!box) return attachment;
+
+ attachment.width = box.width;
+ attachment.height = box.height;
+ }
+
+ return attachment;
+ })
+ );
+
+
export function PreviewButton(chatBoxProps: Props) {
+ const { isEmpty, attachments } = chatBoxProps.type;
+
const channelId = SelectedChannelStore.getChannelId();
const draft = useStateFromStores([DraftStore], () => getDraft(channelId));
+
if (chatBoxProps.type.analyticsName !== "normal") return null;
- if (!draft) return null;
+
+ const hasAttachments = attachments && UploadStore.getUploads(channelId, DraftType.ChannelMessage).length > 0;
+ const hasContent = !isEmpty && draft?.length > 0;
+
+ if (!hasContent && !hasAttachments) return null;
return (
{tooltipProps => (