MessageLogger: color the edit-history (edited) tag like Discord's native one
This commit is contained in:
parent
c7037387a9
commit
c1bc18a3df
1 changed files with 35 additions and 6 deletions
|
|
@ -2,6 +2,7 @@ import { ReactNative } from "@vendetta/metro/common";
|
|||
import { after, before } from "@vendetta/patcher";
|
||||
import { waitFor } from "@shared/lib/waitFor";
|
||||
import { rawFind, rawFindByName } from "@shared/lib/rawFind";
|
||||
import { resolveSemanticColorSafe } from "@shared/lib/color";
|
||||
import { editHistory, fakedMessages } from "./fluxIntercept";
|
||||
|
||||
const TAG = "[MessageLogger]";
|
||||
|
|
@ -10,11 +11,38 @@ function textNode(text: string) {
|
|||
return { content: text, type: "text" };
|
||||
}
|
||||
|
||||
// Confirmed live: message.content in the row JSON is an array of {content, type} rich-text nodes,
|
||||
// not a plain string. Old versions get an inline "(edited)" tag of their own here, stacked above
|
||||
// the current content - the current version keeps Discord's own native "(edited)" tag rather than
|
||||
// getting a second one from here, since that already renders correctly on a genuinely-edited
|
||||
// message with no help needed.
|
||||
// Confirmed live via the decompiled Discord bundle: Discord's own "(edited)" tag isn't a plain text
|
||||
// node - it's colored through a dedicated `editedColor` field on the row that only applies to ONE
|
||||
// tag per row, which our per-history-entry tags can't use (there can be several, one per past
|
||||
// version). role-color-everywhere already found the workaround for coloring arbitrary text nodes on
|
||||
// this bridge: wrap the node in a `{type: "link", target: "usernameOnClick", ...}` shell and set a
|
||||
// `linkColor` inside it - text nodes themselves don't support a color field, but this wrapper does.
|
||||
// TEXT_MUTED is the same semantic token Discord's own muted/secondary text (timestamps, the real
|
||||
// edited tag) uses, confirmed live: resolves to #8a8a9a on this build's theme.
|
||||
function editedTagNode() {
|
||||
const color = resolveSemanticColorSafe(["TEXT_MUTED"], "#949BA4");
|
||||
return {
|
||||
type: "link",
|
||||
target: "usernameOnClick",
|
||||
context: {
|
||||
username: 1,
|
||||
usernameOnClick: {
|
||||
action: "0",
|
||||
userId: "0",
|
||||
linkColor: ReactNative.processColor(color),
|
||||
messageChannelId: "0",
|
||||
},
|
||||
medium: true,
|
||||
},
|
||||
content: [textNode(" (edited)")],
|
||||
};
|
||||
}
|
||||
|
||||
// message.content in the row JSON is an array of {content, type} rich-text nodes, not a plain
|
||||
// string (confirmed live). Old versions get their own muted-colored "(edited)" tag stacked above
|
||||
// the current content - the current version keeps Discord's own native tag rather than getting a
|
||||
// second one from here, since that already renders correctly on a genuinely-edited message with no
|
||||
// help needed.
|
||||
function applyEditHistory(message: any) {
|
||||
const history = editHistory.get(message.id);
|
||||
if (!history?.length) return;
|
||||
|
|
@ -23,7 +51,8 @@ function applyEditHistory(message: any) {
|
|||
const nodes: any[] = [];
|
||||
for (const oldContent of history) {
|
||||
nodes.push(textNode(oldContent || "(empty)"));
|
||||
nodes.push(textNode(" (edited)\n"));
|
||||
nodes.push(editedTagNode());
|
||||
nodes.push(textNode("\n"));
|
||||
}
|
||||
nodes.push(...currentContent);
|
||||
message.content = nodes;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue