Closed neo2701 closed 1 year ago
Do you mean saving the versions history of edited messages? Adding new features such as this is not so much of my priority right now, unless more people will show demand for them. Maybe in the future
Yes, Exactly. I want to implement it myself but i couldn't found the object of edited message..
Perhaps they're sending a REVOKE
message first just like they do for deleted messages. I assume you have WADebugMode
on.
They just send this node with message tag
{
"tag": "message",
"attrs": {
"from": "62****:51@c.us",
"type": "text",
"edit": "1",
"id": "3EB07B07BB4AB8459ECF63",
"sender_lid": "***.1@c.us",
"notify": "Neo",
"t": "1686930292"
},
"content": [
{
"tag": "enc",
"attrs": {
"v": "2",
"type": "pkmsg",
"decrypt-fail": "hide"
},
"content": {}
},
{
"tag": "device-identity",
"content": {}
}
]
}
Sure, but what does the encrypted protobuf contain?
Just found out that the WAProto
is very outdated 😂
I tried to update it from Baileys repo but it seems to break some function.
I see new MESSAGE_EDIT
protocol on Baileys WAProto
{
"stack": "Error: Failed to execute 'createElement' on 'Document': The tag name provided ('107') is not a valid name.\n at document.createElement (https://web.whatsapp.com/app.ab3cb96ce8b0b5e2ac7c.js:93:816907)\n at nodeToElement (chrome-extension://dgnhgkkblbdlgkebhopdhjfnliemgipp/core/utils.js:43:26)\n at nodeToElement (chrome-extension://dgnhgkkblbdlgkebhopdhjfnliemgipp/core/utils.js:52:29)\n at nodeToElement (chrome-extension://dgnhgkkblbdlgkebhopdhjfnliemgipp/core/utils.js:52:29)\n at nodeToElement (chrome-extension://dgnhgkkblbdlgkebhopdhjfnliemgipp/core/utils.js:52:29)\n at nodeToElement (chrome-extension://dgnhgkkblbdlgkebhopdhjfnliemgipp/core/utils.js:52:29)\n at printNode (chrome-extension://dgnhgkkblbdlgkebhopdhjfnliemgipp/core/interception.js:439:38)\n at Object.promise (chrome-extension://dgnhgkkblbdlgkebhopdhjfnliemgipp/core/interception.js:128:13)"
}
How to fix Error on this function?
function nodeToElement(node) {
if (!node.tag) {
var element = document.createElement("unknown");
element.innerHTML = node.toString();
return element;
}
console.log(node.tag);
if (node.tag == "0") node.tag = "zero"; // prevent "The tag name provided ('0') is not a valid name."
if (node.tag == "1") node.tag = "one"; // prevent "The tag name provided ('1') is not a valid name."
var element = document.createElement(node.tag);
for (var attribute in node.attrs) {
element.setAttribute(attribute, node.attrs[attribute]);
}
if (node.content) {
if (Array.isArray(node.content)) {
for (var subNode of node.content) {
element.appendChild(nodeToElement(subNode));
}
} else {
element.appendChild(nodeToElement(node.content));
}
}
return element;
}
file : /core/utils.js:43:26
Oh, the if (node.tag == "0") node.tag = "zero"
was just a dirtry hack I wrote to make exactly this error go away (numbers can't be tag names).
It'll be better to auto-detect all numbers, but for now you can add if (node.tag == "107")
or whatever
I see new MESSAGE_EDIT protocol on Baileys WAProto
Makes perfect sense, I'll update it
function numberstowords(number) {
var units = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"];
number = number.toString();
var result = "";
for (var i = 0; i < number.length; i++) {
result += units[number[i]];
}
return result;
}
function nodeToElement(node) {
if (!node.tag) {
var element = document.createElement("unknown");
element.innerHTML = node.toString();
return element;
}
if (node.tag == "0") node.tag = "zero"; // prevent "The tag name provided ('0') is not a valid name."
if (node.tag == "1") node.tag = "one"; // prevent "The tag name provided ('1') is not a valid name."
// if (node.tag == "107") node.tag = "onezeroseven"; // prevent "The tag name provided ('107') is not a valid name."
if (isNaN(node.tag) == false) node.tag = numberstowords(node.tag);
var element = document.createElement(node.tag);
for (var attribute in node.attrs) {
element.setAttribute(attribute, node.attrs[attribute]);
}
if (node.content) {
if (Array.isArray(node.content)) {
for (var subNode of node.content) {
element.appendChild(nodeToElement(subNode));
}
} else {
element.appendChild(nodeToElement(node.content));
}
}
return element;
}
Hahaha, it works after i did that
NodeHandler.checkForEditedMessageNode = function (message, messageId, remoteJid) {
//
// Check if this is a message edit node
//
var messageEditValue = ProtocolMessage.Type.MESSAGE_EDIT.value;
if (message && message.editedMessage.message.protocolMessage.type == messageEditValue) {
var editedMessageId = message.editedMessage.message.protocolMessage.key.id;
if (saveEditedMsgsHookEnabled) {
onEditedMessageBlocked(message, remoteJid, messageId, editedMessageId);
}
return true;
}
return false;
};
That function works too, but i can't do the UI.
Nice :) I agree, the UI is the more creative part. We do already have a context-menu detection in the code, so maybe you could add "Show original message" option or so when you open the context menu of a message
An alternative is to block the edited version entirely (which you seem to actually do), but this is probably not something everybody would want to happen. In this case, adding the UI option is easy
@neo2701 You are more than welcome to open a PR (even without UI)
Hi, can u implement feature for saving message for edited message? I tried to create it but didn't find the edited message on received message. Thanks!