feat(WAProto): Optimize protobuf generation for 80%+ bundle size reduction (#1665)

* chore: remove comments and veirfy from generated proto files (improve size)

* refactor: replace fromObject with create for proto message instantiation and flag no beautiful

* chore: lint issues
This commit is contained in:
João Lucas de Oliveira Lopes
2025-09-07 08:08:11 -03:00
committed by GitHub
parent 9e04cce8d3
commit 4d4339dae6
15 changed files with 19728 additions and 190249 deletions
+1 -1
View File
@@ -286,7 +286,7 @@ export const makeCommunitiesSocket = (config: SocketConfig) => {
// update the invite message to be expired
if (key.id) {
// create new invite message that is expired
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage)
inviteMessage = proto.Message.GroupInviteMessage.create(inviteMessage)
inviteMessage.inviteExpiration = 0
inviteMessage.inviteCode = ''
ev.emit('messages.update', [
+1 -1
View File
@@ -239,7 +239,7 @@ export const makeGroupsSocket = (config: SocketConfig) => {
// update the invite message to be expired
if (key.id) {
// create new invite message that is expired
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage)
inviteMessage = proto.Message.GroupInviteMessage.create(inviteMessage)
inviteMessage.inviteExpiration = 0
inviteMessage.inviteCode = ''
ev.emit('messages.update', [
+3 -3
View File
@@ -749,7 +749,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
msg.participant ??= node.attrs.participant
msg.messageTimestamp = +node.attrs.t!
const fullMsg = proto.WebMessageInfo.fromObject(msg)
const fullMsg = proto.WebMessageInfo.create(msg as proto.IWebMessageInfo)
await upsertMessage(fullMsg, 'append')
}
})
@@ -1182,7 +1182,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
? Buffer.from(plaintextNode.content, 'binary')
: Buffer.from(plaintextNode.content as Uint8Array)
const messageProto = proto.Message.decode(contentBuf)
const fullMessage = proto.WebMessageInfo.fromObject({
const fullMessage = proto.WebMessageInfo.create({
key: {
remoteJid: from,
id: child.attrs.message_id || child.attrs.server_id,
@@ -1313,7 +1313,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
msg.message = { call: { callKey: Buffer.from(call.id) } }
}
const protoMsg = proto.WebMessageInfo.fromObject(msg)
const protoMsg = proto.WebMessageInfo.create(msg)
upsertMessage(protoMsg, call.offline ? 'append' : 'notify')
}
})
+3 -3
View File
@@ -756,15 +756,15 @@ export const makeMessagesSocket = (config: SocketConfig) => {
try {
const media = await decryptMediaRetryData(result.media!, mediaKey, result.key.id!)
if (media.result !== proto.MediaRetryNotification.ResultType.SUCCESS) {
const resultStr = proto.MediaRetryNotification.ResultType[media.result!]
const resultStr = proto.MediaRetryNotification.ResultType[media.result]
throw new Boom(`Media re-upload failed by device (${resultStr})`, {
data: media,
statusCode: getStatusCodeForMediaRetry(media.result!) || 404
statusCode: getStatusCodeForMediaRetry(media.result) || 404
})
}
content.directPath = media.directPath
content.url = getUrlFromDirectPath(content.directPath!)
content.url = getUrlFromDirectPath(content.directPath)
logger.debug({ directPath: media.directPath, key: result.key }, 'media update successful')
} catch (err: any) {
+1 -1
View File
@@ -223,7 +223,7 @@ export const makeSocket = (config: SocketConfig) => {
let helloMsg: proto.IHandshakeMessage = {
clientHello: { ephemeral: ephemeralKeyPair.public }
}
helloMsg = proto.HandshakeMessage.fromObject(helloMsg)
helloMsg = proto.HandshakeMessage.create(helloMsg)
logger.info({ browser, helloMsg }, 'connected to WA')