Skip to content

Commit

Permalink
chatTweaks: double click edit/reply
Browse files Browse the repository at this point in the history
  • Loading branch information
Cynosphere committed Jan 13, 2025
1 parent 89e5e6e commit f8cdfd7
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/allActivities/webpackModules/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 15 additions & 2 deletions src/chatTweaks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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==`
}
},

Expand All @@ -90,12 +90,25 @@ 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:'
}
}
];

export const webpackModules: Record<string, ExtensionWebpackModule> = {
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" }]
}
};
22 changes: 21 additions & 1 deletion src/chatTweaks/manifest.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down Expand Up @@ -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
Expand Down
69 changes: 69 additions & 0 deletions src/chatTweaks/webpackModules/doubleClick.ts
Original file line number Diff line number Diff line change
@@ -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<boolean>("chatTweaks", "doubleClickEdit") ?? true;
const allowReply = moonlight.getConfigOption<boolean>("chatTweaks", "doubleClickReply") ?? true;
const swapSelf = moonlight.getConfigOption<boolean>("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);
}
}
}

0 comments on commit f8cdfd7

Please sign in to comment.