Skip to content

Commit

Permalink
update whatsmeow to 20240625 from tulir/whatsmeow@6acab59
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Jul 6, 2024
1 parent 2a78189 commit 5d65540
Show file tree
Hide file tree
Showing 20 changed files with 2,195 additions and 1,038 deletions.
2 changes: 1 addition & 1 deletion lib/common/src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

#pragma once

#define NCHAT_VERSION "5.1.1"
#define NCHAT_VERSION "5.1.2"
34 changes: 21 additions & 13 deletions lib/wmchat/go/ext/whatsmeow/mdtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import (
"go.mau.fi/whatsmeow"
"go.mau.fi/whatsmeow/appstate"
waBinary "go.mau.fi/whatsmeow/binary"
waProto "go.mau.fi/whatsmeow/binary/proto"
"go.mau.fi/whatsmeow/proto/waCommon"
"go.mau.fi/whatsmeow/proto/waCompanionReg"
"go.mau.fi/whatsmeow/proto/waE2E"
"go.mau.fi/whatsmeow/store"
"go.mau.fi/whatsmeow/store/sqlstore"
"go.mau.fi/whatsmeow/types"
Expand All @@ -58,7 +60,7 @@ func main() {
}
if *requestFullSync {
store.DeviceProps.RequireFullSync = proto.Bool(true)
store.DeviceProps.HistorySyncConfig = &waProto.DeviceProps_HistorySyncConfig{
store.DeviceProps.HistorySyncConfig = &waCompanionReg.DeviceProps_HistorySyncConfig{
FullSyncDaysLimit: proto.Uint32(3650),
FullSyncSizeMbLimit: proto.Uint32(102400),
StorageQuotaMb: proto.Uint32(102400),
Expand Down Expand Up @@ -265,7 +267,7 @@ func handleCmd(cmd string, args []string) {
}
resp, err := cli.IsOnWhatsApp(args)
if err != nil {
log.Errorf("Failed to check if users are on WhatsApp:", err)
log.Errorf("Failed to check if users are on WhatsApp: %s", err.Error())
} else {
for _, item := range resp {
if item.VerifiedName != nil {
Expand Down Expand Up @@ -346,6 +348,7 @@ func handleCmd(cmd string, args []string) {
}
case "mediaconn":
conn, err := cli.DangerousInternals().RefreshMediaConn(false)

if err != nil {
log.Errorf("Failed to get media connection: %v", err)
} else {
Expand Down Expand Up @@ -629,21 +632,26 @@ func handleCmd(cmd string, args []string) {
for _, item := range resp {
if action == whatsmeow.ParticipantChangeAdd && item.Error == 403 && item.AddRequest != nil {
log.Infof("Participant is private: %d %s %s %v", item.Error, item.JID, item.AddRequest.Code, item.AddRequest.Expiration)
cli.SendMessage(context.TODO(), item.JID, &waProto.Message{
GroupInviteMessage: &waProto.GroupInviteMessage{
resp, err := cli.SendMessage(context.TODO(), item.JID, &waE2E.Message{
GroupInviteMessage: &waE2E.GroupInviteMessage{
InviteCode: proto.String(item.AddRequest.Code),
InviteExpiration: proto.Int64(item.AddRequest.Expiration.Unix()),
GroupJID: proto.String(jid.String()),
GroupName: proto.String("Test group"),
Caption: proto.String("This is a test group"),
},
})
if err != nil {
log.Errorf("Error sending group invite: %v", err)
} else {
log.Infof("Group Invite sent (server timestamp: %s)", resp.Timestamp)
}
} else if item.Error == 409 {
log.Infof("Participant already in group: %d %s %+v", item.Error, item.JID)
log.Infof("Participant already in group: %d %s", item.Error, item.JID)
} else if item.Error == 0 {
log.Infof("Added participant: %d %s %+v", item.Error, item.JID)
log.Infof("Added participant: %d %s", item.Error, item.JID)
} else {
log.Infof("Unknown status: %d %s %+v", item.Error, item.JID)
log.Infof("Unknown status: %d %s", item.Error, item.JID)
}
}
case "getrequestparticipant":
Expand Down Expand Up @@ -707,7 +715,7 @@ func handleCmd(cmd string, args []string) {
if !ok {
return
}
msg := &waProto.Message{Conversation: proto.String(strings.Join(args[1:], " "))}
msg := &waE2E.Message{Conversation: proto.String(strings.Join(args[1:], " "))}
resp, err := cli.SendMessage(context.Background(), recipient, msg)
if err != nil {
log.Errorf("Error sending message: %v", err)
Expand Down Expand Up @@ -760,9 +768,9 @@ func handleCmd(cmd string, args []string) {
if reaction == "remove" {
reaction = ""
}
msg := &waProto.Message{
ReactionMessage: &waProto.ReactionMessage{
Key: &waProto.MessageKey{
msg := &waE2E.Message{
ReactionMessage: &waE2E.ReactionMessage{
Key: &waCommon.MessageKey{
RemoteJID: proto.String(recipient.String()),
FromMe: proto.Bool(fromMe),
ID: proto.String(messageID),
Expand Down Expand Up @@ -817,7 +825,7 @@ func handleCmd(cmd string, args []string) {
log.Errorf("Failed to upload file: %v", err)
return
}
msg := &waProto.Message{ImageMessage: &waProto.ImageMessage{
msg := &waE2E.Message{ImageMessage: &waE2E.ImageMessage{
Caption: proto.String(strings.Join(args[2:], " ")),
URL: proto.String(uploaded.URL),
DirectPath: proto.String(uploaded.DirectPath),
Expand Down
52 changes: 37 additions & 15 deletions lib/wmchat/go/ext/whatsmeow/proto/parse-proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,10 @@ function flattenWithBlankLines(...items) {
.flatMap(item => item)
}

function protoifyChildren(container) {
function protoifyChildren(container, proto3) {
return flattenWithBlankLines(
...Object.values(container.enums).map(protoifyEnum),
...Object.values(container.messages).map(protoifyMessage),
...Object.values(container.messages).map(msg => protoifyMessage(msg, proto3)),
)
}

Expand All @@ -289,6 +289,14 @@ function protoifyEnum(enumDef) {

const {TYPES, TYPE_MASK, FLAGS} = requireModule("WAProtoConst")

function mapFieldTypeName(ref, parentModule, parentPath) {
if (typeof ref === "object") {
return fieldTypeName(TYPES.MESSAGE, ref, parentModule, parentPath)
} else {
return fieldTypeName(ref, undefined, parentModule, parentPath)
}
}

function fieldTypeName(typeID, typeRef, parentModule, parentPath) {
switch (typeID) {
case TYPES.INT32:
Expand Down Expand Up @@ -323,6 +331,8 @@ function fieldTypeName(typeID, typeRef, parentModule, parentPath) {
namePath.push(...typeRef.__path__.slice(pathStartIndex))
namePath.push(typeRef.__name__)
return namePath.join(".")
case TYPES.MAP:
return `map<${mapFieldTypeName(typeRef[0], parentModule, parentPath)}, ${mapFieldTypeName(typeRef[1], parentModule, parentPath)}>`
case TYPES.FIXED64:
return "fixed64"
case TYPES.SFIXED64:
Expand Down Expand Up @@ -374,16 +384,19 @@ function fixFieldName(name) {
.replace("Sha256", "SHA256")
}

function protoifyField(name, [index, flags, typeRef], parentModule, parentPath, isOneOf) {
function protoifyField(name, [index, flags, typeRef], parentModule, parentPath, isOneOf, proto3) {
const preflags = []
const postflags = [""]
const isMap = (flags & TYPE_MASK) === TYPES.MAP
if (!isOneOf) {
if ((flags & FLAGS.REPEATED) !== 0) {
preflags.push("repeated")
} else if ((flags & FLAGS.REQUIRED) === 0) {
preflags.push("optional")
} else {
preflags.push("required")
} else if (!proto3) {
if ((flags & FLAGS.REQUIRED) === 0) {
preflags.push("optional")
} else {
preflags.push("required")
}
}
}
preflags.push(fieldTypeName(flags & TYPE_MASK, typeRef, parentModule, parentPath))
Expand All @@ -393,12 +406,12 @@ function protoifyField(name, [index, flags, typeRef], parentModule, parentPath,
return `${preflags.join(" ")} ${fixFieldName(name)} = ${index}${postflags.join(" ")};`
}

function protoifyFields(fields, parentModule, parentPath, isOneOf) {
return Object.entries(fields).map(([name, definition]) => protoifyField(name, definition, parentModule, parentPath, isOneOf))
function protoifyFields(fields, parentModule, parentPath, isOneOf, proto3) {
return Object.entries(fields).map(([name, definition]) => protoifyField(name, definition, parentModule, parentPath, isOneOf, proto3))
}

function protoifyMessage(message) {
const sections = [protoifyChildren(message)]
function protoifyMessage(message, proto3) {
const sections = [protoifyChildren(message, proto3)]
const spec = message.message
const fullMessagePath = message.__path__.concat([message.__name__])
for (const [name, fieldNames] of Object.entries(spec.__oneofs__ ?? {})) {
Expand All @@ -407,24 +420,33 @@ function protoifyMessage(message) {
delete spec[fieldName]
return [fieldName, def]
}))
sections.push([`oneof ${name} ` + "{", ...indent(protoifyFields(fields, message.__module__, fullMessagePath, true)), "}"])
sections.push([`oneof ${name} ` + "{", ...indent(protoifyFields(fields, message.__module__, fullMessagePath, true, proto3)), "}"])
}
if (spec.__reserved__) {
console.warn("Found reserved keys:", message.__name__, spec.__reserved__)
}
delete spec.__oneofs__
delete spec.__reserved__
sections.push(protoifyFields(spec, message.__module__, fullMessagePath, false))
sections.push(protoifyFields(spec, message.__module__, fullMessagePath, false, proto3))
return [`message ${message.__name__} ` + "{", ...indent(flattenWithBlankLines(...sections)), "}"]
}

function goPackageName(name) {
return name.replace(/^WA/, "wa").replace("WebProtobufs", "").replace("Protobufs", "")
}

const needsProto3 = {
"WAWebProtobufsReporting": true
}

function protoifyModule(module) {
const output = []
output.push(`syntax = "proto2";`)
const proto3 = needsProto3[module.__name__]
if (proto3) {
output.push(`syntax = "proto3";`)
} else {
output.push(`syntax = "proto2";`)
}
output.push(`package ${module.__name__};`)
output.push(`option go_package = "go.mau.fi/whatsmeow/proto/${goPackageName(module.__name__)}";`)
output.push("")
Expand All @@ -434,7 +456,7 @@ function protoifyModule(module) {
}
output.push("")
}
const children = protoifyChildren(module)
const children = protoifyChildren(module, proto3)
children.push("")
return output.concat(children)
}
Expand Down
Loading

0 comments on commit 5d65540

Please sign in to comment.