Skip to content

Commit e49aa30

Browse files
committed
additional fix for antied, for alpha build 296
Self edit still had someissue, and generally added more safeguard and more robust props finding
1 parent 209df1d commit e49aa30

4 files changed

Lines changed: 103 additions & 34 deletions

File tree

angel/antied/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name":"Antied v1.4.2",
2+
"name":"Antied v1.4.2a",
33
"description":"Keeps deleted messages and logs edited messages, until you restart/reloads the app",
44
"main": "index.jsx",
55
"authors": [

angel/antied/patches/actionsheet.jsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { plugin } from "@vendetta";
1212
const ActionSheet = findByProps("openLazy", "hideActionSheet")
1313
const MessageStore = findByProps("getMessage", "getMessages");
1414
const ChannelStore = findByProps("getChannel", "getDMFromUserId");
15+
const ChannelMessages = findByProps("_channelMessages");
1516
const { ActionSheetRow } = findByProps("ActionSheetRow");
1617

1718
export default (deletedMessageArray) => before("openLazy", ActionSheet, ([component, args, actionMessage]) => {
@@ -41,7 +42,18 @@ export default (deletedMessageArray) => before("openLazy", ActionSheet, ([compon
4142
buttons.length - 1
4243
);
4344

44-
const originalMessage = MessageStore.getMessage(message.channel_id, message?.id)
45+
let originalMessage = null;
46+
47+
if (message?.channel_id && message?.id) {
48+
originalMessage = MessageStore.getMessage(message?.channel_id, message?.id);
49+
50+
if(!originalMessage) {
51+
const channel = ChannelMessages.get(message?.channel_id);
52+
originalMessage = channel?.get(message?.id);
53+
}
54+
}
55+
56+
if(!originalMessage) return comp;
4557

4658
const escapedBuffer = regexEscaper(storage?.inputs?.editedMessageBuffer || "`[ EDITED ]`")
4759

angel/antied/patches/flux_dispatch.js

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { instead, before, after } from "@vendetta/patcher"
22
import { getAssetIDByName } from "@vendetta/ui/assets"
33
import { findInReactTree } from "@vendetta/utils"
4-
import { findByProps } from "@vendetta/metro"
4+
import { findByProps, findByStoreName } from "@vendetta/metro"
55
import { React, FluxDispatcher } from "@vendetta/metro/common"
66
import { Forms } from "@vendetta/ui/components"
77
import { storage } from "@vendetta/plugin";
@@ -11,12 +11,28 @@ const ChannelStore = findByProps("getChannel", "getDMFromUserId");
1111
const ChannelMessages = findByProps("_channelMessages");
1212
const MessageStore = findByProps('getMessage', 'getMessages');
1313

14+
/* THIS Function Janky
15+
const altMessageStore = findByStoreName("MessageStore")
16+
const logs = altMessageStore._dispatcher.actionLogger.logs;
17+
18+
function messageGetter(authorId) {
19+
const allOcc = logs.filter(x =>
20+
x?.action?.type === "MESSAGE_UPDATE" &&
21+
x?.action?.message?.author?.id === authorId
22+
);
23+
24+
// Use .at(-1) for cleaner syntax, with a fallback to the old way
25+
const lastEntry = allOcc.at(-1);
26+
return lastEntry?.action?.message ?? null;
27+
}
28+
29+
*/
1430

1531
/*
16-
This forsaken File, ohhh maa gaaawd
32+
i kinda hated discord constant nugging the flux
1733
1834
19-
- Angelica
35+
- Angelw0lf
2036
*/
2137

2238
export default (deletedMessageArray) => before("dispatch", FluxDispatcher, (args) => {
@@ -94,26 +110,40 @@ export default (deletedMessageArray) => before("dispatch", FluxDispatcher, (args
94110

95111
// Message Update Patch
96112
if( type == "MESSAGE_UPDATE" ) {
113+
// console.log(event)
97114
if(storage.switches.enableMU == false) return args;
98115

99116
if(event?.otherPluginBypass) return args;
100117

101118
if(event?.message?.author?.bot) return args;
102119

103-
const originalMessage = MessageStore.getMessage(
104-
(event?.message?.channel_id || event?.channelId),
105-
(event?.message?.id || event?.id)
106-
);
120+
const channelId = event?.message?.channel_id ?? event?.channelId;
121+
const messageId = event?.message?.id ?? event?.id;
122+
123+
let originalMessage = null;
124+
125+
// first use existing getter;
126+
if (channelId && messageId) {
127+
originalMessage = MessageStore.getMessage(channelId, messageId);
128+
129+
if(!originalMessage) {
130+
const channel = ChannelMessages.get(channelId);
131+
originalMessage = channel?.get(messageId);
132+
}
133+
}
134+
135+
// console.log(event?.message?.content)
136+
// console.log(originalMessage?.content)
137+
138+
// if still doesnt exist then just bypass
139+
if(!originalMessage) return args;
107140

108-
const OMCheck1 = originalMessage?.author?.id;
109-
const OMCheck2 = originalMessage?.author?.username;
110-
const OMCheck3 = (!originalMessage?.content && originalMessage?.attachments?.length == 0 && originalMessage?.embeds?.length == 0);
111-
112-
if(!originalMessage || !OMCheck1 || !OMCheck2 || OMCheck3) return args;
141+
if (!originalMessage.author?.id || !originalMessage.author?.username) return args;
142+
if (!originalMessage.content && originalMessage.attachments?.length === 0 && originalMessage.embeds?.length === 0) return args;
113143

114-
if(!event?.message?.content || !originalMessage?.content) return args;
144+
if(!event?.message?.content) return args;
115145

116-
if(event?.message?.content == originalMessage?.content) return args;
146+
if(event?.message?.content == originalMessage?.content) return args;
117147

118148
if(
119149
(storage?.inputs?.ignoredUserList?.length > 0) &&

angel/antied/patches/update_rows.js

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,49 @@ import { before } from "@vendetta/patcher";
33
import { storage } from "@vendetta/plugin";
44
import { findByProps } from '@vendetta/metro';
55

6-
// const { DCDChatManager } = ReactNative.NativeModules;
7-
const rowsController = findByProps("updateRows", "getConstants")
8-
6+
const rowsController = findByProps("updateRows", "getConstants") || findByProps("updateRows");
97

108
/*
11-
Time wasted: 3 hours 10 minutes
9+
Time wasted: 3 hours 25 minutes
1210
*/
1311

14-
// export default (deletedMessagesArray) => before("updateRows", DCDChatManager, (r) => {
15-
// Should Support newer versions
1612
// Function consist of (num_1, args, bool_1, num_2, num_3)
1713
export default (deletedMessagesArray) => before("updateRows", rowsController, (r) => {
18-
19-
// added this in 1.4.2 basically for safe guard against "cannot convert undefined value to object"
20-
if (!r || r.length <= 1 || typeof r[1] !== "string") {
14+
15+
// safe guard if r returns undefined, but then again rowsController might be undefined
16+
// if it happens then "Cannot convert undefined value to object" error would occour and should be in updateRowsPatch function
17+
if (!r || r.length < 1) {
2118
return r;
2219
}
2320

21+
let isDirect = false;
2422
let rows;
2523

26-
try {
27-
rows = JSON.parse(r[1]);
28-
} catch (e) {
29-
// another safeguard for if said r[1] is empty string or invalid stringified JSON
30-
console.error("JSON Parse failed in updateRows patch. Aborting.", e);
31-
return r;
32-
}
24+
if (typeof r[1] == 'string') {
25+
// handle stringified object, happens in Stable Build
26+
try {
27+
rows = JSON.parse(r[1]);
28+
} catch (e) {
29+
console.log("[ANTIED:updateRowsPatch] JSON Parse failed in updateRows patch. Aborting.", e, "Input:", r[1]);
30+
return r;
31+
}
32+
}
33+
else if (typeof r[1] == 'object' && r[1]) {
34+
// handle Direct Object, happens in Alpha Build
35+
rows = r[1];
36+
isDirect = true;
37+
}
38+
else {
39+
// fallback if not object nor stringified object
40+
console.log("[ANTIED:updateRowsPatch] Unexpected type for r[1] in updateRows. Expected object or string, got:", typeof r[1]);
41+
return r;
42+
}
43+
44+
if(storage?.debugUpdateRows) {
45+
console.log("BEFORE")
46+
console.log(isDirect)
47+
console.log(rows)
48+
}
3349

3450
const { textColor, backgroundColor, backgroundColorAlpha, gutterColor, gutterColorAlpha } = storage.colors;
3551
const {
@@ -160,12 +176,23 @@ export default (deletedMessagesArray) => before("updateRows", rowsController, (r
160176
}
161177
})
162178

179+
if(storage?.debugUpdateRows) {
180+
console.log("AFTER")
181+
console.log(isDirect)
182+
console.log(rows)
183+
}
184+
163185

164186
// simple safeguard if modification is faulty, we didnt push the modified rows
165187
try {
166-
r[1] = JSON.stringify(rows);
188+
if(isDirect) {
189+
r[1] = rows;
190+
}
191+
else {
192+
r[1] = JSON.stringify(rows);
193+
}
167194
} catch (e) {
168-
console.error("Failed to stringify modified rows. Aborting.", e);
195+
console.log("[ANTIED:updateRowsPatch] Failed to stringify modified rows. Aborting.", e);
169196
return r; // we return as is
170197
}
171198

0 commit comments

Comments
 (0)