This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/dev' into dev
- Loading branch information
Showing
8 changed files
with
106 additions
and
20 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Vencord, a Discord client mod | ||
* Copyright (c) 2024 Vendicated and contributors | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
import { MessageCache, MessageStore } from "@webpack/common"; | ||
import { FluxStore } from "@webpack/types"; | ||
import { Message } from "discord-types/general"; | ||
|
||
/** | ||
* Update and re-render a message | ||
* @param channelId The channel id of the message | ||
* @param messageId The message id | ||
* @param fields The fields of the message to change. Leave empty if you just want to re-render | ||
*/ | ||
export function updateMessage(channelId: string, messageId: string, fields?: Partial<Message>) { | ||
const channelMessageCache = MessageCache.getOrCreate(channelId); | ||
if (!channelMessageCache.has(messageId)) return; | ||
|
||
// To cause a message to re-render, we basically need to create a new instance of the message and obtain a new reference | ||
// If we have fields to modify we can use the merge method of the class, otherwise we just create a new instance with the old fields | ||
const newChannelMessageCache = channelMessageCache.update(messageId, (oldMessage: any) => { | ||
return fields ? oldMessage.merge(fields) : new oldMessage.constructor(oldMessage); | ||
}); | ||
|
||
MessageCache.commit(newChannelMessageCache); | ||
(MessageStore as unknown as FluxStore).emitChange(); | ||
} |
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,37 @@ | ||
/* | ||
* 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: "MessageUpdaterAPI", | ||
description: "API for updating and re-rendering messages.", | ||
authors: [Devs.Nuckyz], | ||
|
||
patches: [ | ||
{ | ||
// Message accessories have a custom logic to decide if they should render again, so we need to make it not ignore changed message reference | ||
find: "}renderEmbeds(", | ||
replacement: { | ||
match: /(?<=this.props,\i,\[)"message",/, | ||
replace: "" | ||
} | ||
} | ||
] | ||
}); |
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
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
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