-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ViewRaw plugin & MiniPopover API (#275)
Co-authored-by: Vendicated <[email protected]>
- Loading branch information
1 parent
06d32ae
commit 4760af7
Showing
9 changed files
with
319 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,6 @@ lerna-debug.log* | |
*.tsbuildinfo | ||
|
||
src/userplugins | ||
|
||
ExtensionCache/ | ||
settings/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Vencord, a modification for Discord's desktop app | ||
* Copyright (c) 2022 Vendicated and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import Logger from "@utils/Logger"; | ||
import { Channel, Message } from "discord-types/general"; | ||
import type { MouseEventHandler } from "react"; | ||
|
||
const logger = new Logger("MessagePopover"); | ||
|
||
export interface ButtonItem { | ||
key?: string, | ||
label: string, | ||
icon: React.ComponentType<any>, | ||
message: Message, | ||
channel: Channel, | ||
onClick?: MouseEventHandler<HTMLButtonElement>, | ||
onContextMenu?: MouseEventHandler<HTMLButtonElement>; | ||
} | ||
|
||
export type getButtonItem = (message: Message) => ButtonItem | null; | ||
|
||
export const buttons = new Map<string, getButtonItem>(); | ||
|
||
export function addButton( | ||
identifier: string, | ||
item: getButtonItem, | ||
) { | ||
buttons.set(identifier, item); | ||
} | ||
|
||
export function removeButton(identifier: string) { | ||
buttons.delete(identifier); | ||
} | ||
|
||
export function _buildPopoverElements( | ||
msg: Message, | ||
makeButton: (item: ButtonItem) => React.ComponentType | ||
) { | ||
const items = [] as React.ComponentType[]; | ||
|
||
for (const [identifier, getItem] of buttons.entries()) { | ||
try { | ||
const item = getItem(msg); | ||
if (item) { | ||
item.key ??= identifier; | ||
items.push(makeButton(item)); | ||
} | ||
} catch (err) { | ||
logger.error(`[${identifier}]`, err); | ||
} | ||
} | ||
|
||
return items; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Vencord, a modification for Discord's desktop app | ||
* Copyright (c) 2022 Vendicated and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { Devs } from "@utils/constants"; | ||
import definePlugin from "@utils/types"; | ||
|
||
export default definePlugin({ | ||
name: "MessagePopoverAPI", | ||
description: "API to add buttons to message popovers.", | ||
authors: [Devs.KingFish], | ||
patches: [{ | ||
find: "Messages.MESSAGE_UTILITIES_A11Y_LABEL", | ||
replacement: { | ||
match: /(message:(.).{0,100}Fragment,\{children:\[)(.{0,90}renderPopout:.{0,200}message_reaction_emoji_picker.+?return (.{1,3})\(.{0,30}"add-reaction")/, | ||
replace: "$1...Vencord.Api.MessagePopover._buildPopoverElements($2,$4),$3" | ||
} | ||
}], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.