diff --git a/src/allActivities/webpackModules/icons.tsx b/src/allActivities/webpackModules/icons.tsx index 62f991b..e42acde 100644 --- a/src/allActivities/webpackModules/icons.tsx +++ b/src/allActivities/webpackModules/icons.tsx @@ -7,12 +7,10 @@ import { ApplicationStore, GameStore, UserStore } from "@moonlight-mod/wp/common // FIXME: mappings const { ActivityTypes, PlatformTypes } = spacepack.require("discord/Constants"); -const useUserProfileActivity = spacepack.findByCode('("use-user-' + 'profile-activity")')[0].exports.Z; -const ConnectionPlatforms = spacepack.findByExports("getByUrl", "get", "isSupported")[0].exports.Z; -const UserProfileActivityCard = spacepack.findByCode('location:"' + 'UserProfileActivityCard",')[0].exports.Z; +const useUserProfileActivity = spacepack.findByCode(`${'("use-user-profile-activity")'}`)[0].exports.Z; +const ConnectionPlatforms = spacepack.findByCode("getByUrl(", "get(", `${"isSupported:"}`)[0].exports.Z; +const UserProfileActivityCard = spacepack.findByCode(`${'location:"UserProfileActivityCard",'}`)[0].exports.Z; -// findByExports is unreliable for whatever reason and causes every other reload of the client to fail???????????? -//const ActivityClasses = spacepack.findByExports("multipleIconWrapper", "headerIcon")[0].exports; const ActivityClasses = spacepack.findByCode( "applicationStreamingPreviewWrapper:" + '"applicationStreamingPreviewWrapper_' )[0].exports; diff --git a/src/chatTweaks/index.ts b/src/chatTweaks/index.ts index dc5c9a3..0f3ea07 100644 --- a/src/chatTweaks/index.ts +++ b/src/chatTweaks/index.ts @@ -78,7 +78,7 @@ export const patches: Patch[] = [ replace: { match: /=>null!=(\i)&&\i&&null==/, replacement: (_, isOwner) => - `=>null!=(${isOwner}=require("chatTweaks_ownerCrown").default(arguments[0]))&&${isOwner}&&null==` + `=>null!=(${isOwner}=require("chatTweaks_ownerCrown")?.default?.(arguments[0]))&&${isOwner}&&null==` } }, @@ -90,6 +90,16 @@ export const patches: Patch[] = [ replacement: (_, linkCheck) => `if((moonlight.getConfigOption("chatTweaks","noMaskedLinkPaste")??true)?false:${linkCheck}){` } + }, + + // double click edit/reply + { + find: ',role:"article",children:[', + replace: { + match: "}),ref:", + replacement: + '}),onDoubleClick:(event)=>require("chatTweaks_doubleClick")?.default?.(arguments[0].childrenMessageContent.props,event),ref:' + } } ]; @@ -97,5 +107,8 @@ export const webpackModules: Record = { ownerCrown: { dependencies: [{ ext: "common", id: "stores" }, { ext: "spacepack", id: "spacepack" }, { id: "discord/Constants" }] }, - noReplyPing: {} + noReplyPing: {}, + doubleClick: { + dependencies: [{ ext: "common", id: "stores" }, { ext: "spacepack", id: "spacepack" }, { id: "discord/Dispatcher" }] + } }; diff --git a/src/chatTweaks/manifest.json b/src/chatTweaks/manifest.json index e53fb51..4ef9b52 100644 --- a/src/chatTweaks/manifest.json +++ b/src/chatTweaks/manifest.json @@ -1,7 +1,7 @@ { "$schema": "https://moonlight-mod.github.io/manifest.schema.json", "id": "chatTweaks", - "version": "1.0.3", + "version": "1.0.4", "meta": { "name": "Chat Tweaks", "tagline": "Various tweaks to chatting. Every feature togglable.", @@ -81,6 +81,26 @@ "type": "boolean", "default": true, "advice": "none" + }, + "doubleClickEdit": { + "displayName": "Double click own messages to edit", + "type": "boolean", + "default": true, + "advice": "none" + }, + "doubleClickReply": { + "displayName": "Double click messages to reply", + "description": "If edit is enabled, hold shift to reply to your own messages", + "type": "boolean", + "default": true, + "advice": "none" + }, + "doubleClickSwapSelf": { + "displayName": "Double Click Edit/Reply -> Swap Self", + "description": "Hold shift to edit instead of reply", + "type": "boolean", + "default": false, + "advice": "none" } }, "apiLevel": 2 diff --git a/src/chatTweaks/webpackModules/doubleClick.ts b/src/chatTweaks/webpackModules/doubleClick.ts new file mode 100644 index 0000000..0f92cfd --- /dev/null +++ b/src/chatTweaks/webpackModules/doubleClick.ts @@ -0,0 +1,69 @@ +import spacepack from "@moonlight-mod/wp/spacepack_spacepack"; +import Dispatcher from "@moonlight-mod/wp/discord/Dispatcher"; +import { UserStore, ChannelStore } from "@moonlight-mod/wp/common_stores"; + +const { startEditMessage } = spacepack.findByCode("startEditMessage(", "trackInvite:")[0].exports.Z; +const canReplyToMessage = spacepack.findFunctionByStrings( + spacepack.findByCode(".REPLYABLE.has(")[0].exports, + ".getCurrentUser()" +); +const replyToMessage = spacepack.findFunctionByStrings( + spacepack.findByCode(`${',source:"message-actions"}'}`)[0].exports, + ".TEXTAREA_FOCUS)" +); + +type EditData = { + messageId?: string; +}; + +let isEditing = false, + editData: EditData = {}; + +Dispatcher.subscribe("MESSAGE_START_EDIT", (event) => { + isEditing = true; + editData = event; +}); +Dispatcher.subscribe("MESSAGE_END_EDIT", (event) => { + isEditing = false; + editData = {}; +}); + +export default function onDobuleClick({ message }: { message: any }, event: MouseEvent) { + const allowEdit = moonlight.getConfigOption("chatTweaks", "doubleClickEdit") ?? true; + const allowReply = moonlight.getConfigOption("chatTweaks", "doubleClickReply") ?? true; + const swapSelf = moonlight.getConfigOption("chatTweaks", "doubleClickSwapSelf") ?? false; + + const self = UserStore.getCurrentUser(); + const channel = ChannelStore.getChannel(message.channel_id); + + let reply = false; + let edit = false; + + if (message.author.id === self.id) { + if (event.shiftKey) { + if (swapSelf && allowEdit) { + edit = true; + } else if (allowReply) { + reply = true; + } + } else if (!event.shiftKey) { + if (swapSelf && allowReply) { + reply = true; + } else { + edit = true; + } + } + } else if (allowReply) { + reply = true; + } + + if (reply === true) { + if (canReplyToMessage!(channel, message)) { + replyToMessage!(channel, message, event); + } + } else if (edit === true) { + if (isEditing === false || (isEditing && editData.messageId !== message.id)) { + startEditMessage(message.channel_id, message.id, message.content); + } + } +}