Skip to content

Commit 0e9c7e4

Browse files
committed
fix(main): Clean up warnings and move on from deprecated waProto
1 parent 7f13c31 commit 0e9c7e4

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

mdtest/main.go

+21-13
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ import (
3131
"go.mau.fi/whatsmeow"
3232
"go.mau.fi/whatsmeow/appstate"
3333
waBinary "go.mau.fi/whatsmeow/binary"
34-
waProto "go.mau.fi/whatsmeow/binary/proto"
34+
"go.mau.fi/whatsmeow/proto/waCommon"
35+
"go.mau.fi/whatsmeow/proto/waCompanionReg"
36+
"go.mau.fi/whatsmeow/proto/waE2E"
3537
"go.mau.fi/whatsmeow/store"
3638
"go.mau.fi/whatsmeow/store/sqlstore"
3739
"go.mau.fi/whatsmeow/types"
@@ -58,7 +60,7 @@ func main() {
5860
}
5961
if *requestFullSync {
6062
store.DeviceProps.RequireFullSync = proto.Bool(true)
61-
store.DeviceProps.HistorySyncConfig = &waProto.DeviceProps_HistorySyncConfig{
63+
store.DeviceProps.HistorySyncConfig = &waCompanionReg.DeviceProps_HistorySyncConfig{
6264
FullSyncDaysLimit: proto.Uint32(3650),
6365
FullSyncSizeMbLimit: proto.Uint32(102400),
6466
StorageQuotaMb: proto.Uint32(102400),
@@ -265,7 +267,7 @@ func handleCmd(cmd string, args []string) {
265267
}
266268
resp, err := cli.IsOnWhatsApp(args)
267269
if err != nil {
268-
log.Errorf("Failed to check if users are on WhatsApp:", err)
270+
log.Errorf("Failed to check if users are on WhatsApp: %s", err.Error())
269271
} else {
270272
for _, item := range resp {
271273
if item.VerifiedName != nil {
@@ -346,6 +348,7 @@ func handleCmd(cmd string, args []string) {
346348
}
347349
case "mediaconn":
348350
conn, err := cli.DangerousInternals().RefreshMediaConn(false)
351+
349352
if err != nil {
350353
log.Errorf("Failed to get media connection: %v", err)
351354
} else {
@@ -629,21 +632,26 @@ func handleCmd(cmd string, args []string) {
629632
for _, item := range resp {
630633
if action == whatsmeow.ParticipantChangeAdd && item.Error == 403 && item.AddRequest != nil {
631634
log.Infof("Participant is private: %d %s %s %v", item.Error, item.JID, item.AddRequest.Code, item.AddRequest.Expiration)
632-
cli.SendMessage(context.TODO(), item.JID, &waProto.Message{
633-
GroupInviteMessage: &waProto.GroupInviteMessage{
635+
resp, err := cli.SendMessage(context.TODO(), item.JID, &waE2E.Message{
636+
GroupInviteMessage: &waE2E.GroupInviteMessage{
634637
InviteCode: proto.String(item.AddRequest.Code),
635638
InviteExpiration: proto.Int64(item.AddRequest.Expiration.Unix()),
636639
GroupJID: proto.String(jid.String()),
637640
GroupName: proto.String("Test group"),
638641
Caption: proto.String("This is a test group"),
639642
},
640643
})
644+
if err != nil {
645+
log.Errorf("Error sending group invite: %v", err)
646+
} else {
647+
log.Infof("Group Invite sent (server timestamp: %s)", resp.Timestamp)
648+
}
641649
} else if item.Error == 409 {
642-
log.Infof("Participant already in group: %d %s %+v", item.Error, item.JID)
650+
log.Infof("Participant already in group: %d %s", item.Error, item.JID)
643651
} else if item.Error == 0 {
644-
log.Infof("Added participant: %d %s %+v", item.Error, item.JID)
652+
log.Infof("Added participant: %d %s", item.Error, item.JID)
645653
} else {
646-
log.Infof("Unknown status: %d %s %+v", item.Error, item.JID)
654+
log.Infof("Unknown status: %d %s", item.Error, item.JID)
647655
}
648656
}
649657
case "getrequestparticipant":
@@ -707,7 +715,7 @@ func handleCmd(cmd string, args []string) {
707715
if !ok {
708716
return
709717
}
710-
msg := &waProto.Message{Conversation: proto.String(strings.Join(args[1:], " "))}
718+
msg := &waE2E.Message{Conversation: proto.String(strings.Join(args[1:], " "))}
711719
resp, err := cli.SendMessage(context.Background(), recipient, msg)
712720
if err != nil {
713721
log.Errorf("Error sending message: %v", err)
@@ -760,9 +768,9 @@ func handleCmd(cmd string, args []string) {
760768
if reaction == "remove" {
761769
reaction = ""
762770
}
763-
msg := &waProto.Message{
764-
ReactionMessage: &waProto.ReactionMessage{
765-
Key: &waProto.MessageKey{
771+
msg := &waE2E.Message{
772+
ReactionMessage: &waE2E.ReactionMessage{
773+
Key: &waCommon.MessageKey{
766774
RemoteJID: proto.String(recipient.String()),
767775
FromMe: proto.Bool(fromMe),
768776
ID: proto.String(messageID),
@@ -817,7 +825,7 @@ func handleCmd(cmd string, args []string) {
817825
log.Errorf("Failed to upload file: %v", err)
818826
return
819827
}
820-
msg := &waProto.Message{ImageMessage: &waProto.ImageMessage{
828+
msg := &waE2E.Message{ImageMessage: &waE2E.ImageMessage{
821829
Caption: proto.String(strings.Join(args[2:], " ")),
822830
URL: proto.String(uploaded.URL),
823831
DirectPath: proto.String(uploaded.DirectPath),

0 commit comments

Comments
 (0)