From e31788541a458bd8efd96db2de645b9a1c421bb4 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 12 Mar 2022 20:05:57 +0200 Subject: [PATCH] Check for WhatsApp web updates on bridge startup --- go.mod | 2 +- go.sum | 4 ++-- main.go | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 8f2a162..074655b 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/prometheus/client_golang v1.11.1 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/tidwall/gjson v1.14.0 - go.mau.fi/whatsmeow v0.0.0-20220309134402-6c95a0dfb20d + go.mau.fi/whatsmeow v0.0.0-20220312175208-0c4681a6ff52 golang.org/x/image v0.0.0-20220302094943-723b81ca9867 golang.org/x/net v0.0.0-20220225172249-27dd8689420f google.golang.org/protobuf v1.27.1 diff --git a/go.sum b/go.sum index af07327..e31783d 100644 --- a/go.sum +++ b/go.sum @@ -122,8 +122,8 @@ github.com/tidwall/sjson v1.2.4 h1:cuiLzLnaMeBhRmEv00Lpk3tkYrcxpmbU81tAY4Dw0tc= github.com/tidwall/sjson v1.2.4/go.mod h1:098SZ494YoMWPmMO6ct4dcFnqxwj9r/gF0Etp19pSNM= go.mau.fi/libsignal v0.0.0-20220308120827-0d87a03fd7c7 h1:L09XYQRGJwC6KbJumz3cD/6JTUAPNZHfnu8hroqm1KE= go.mau.fi/libsignal v0.0.0-20220308120827-0d87a03fd7c7/go.mod h1:LjEYzdnRUcRArJJUUHQUfMU1A+WzEM73qBTirXluuaY= -go.mau.fi/whatsmeow v0.0.0-20220309134402-6c95a0dfb20d h1:pjPvv93XTsXVFMypsIdSYisbsAPDZLJ4y11XL1sqQ7k= -go.mau.fi/whatsmeow v0.0.0-20220309134402-6c95a0dfb20d/go.mod h1:nH4IwHZf+Ks61nM5p71jZqLXiT0NpG+0uR/WqzCqHH8= +go.mau.fi/whatsmeow v0.0.0-20220312175208-0c4681a6ff52 h1:CVJ4dVzluwsUFI8zBLQBlrtYHuMcEYM6oLeAbplCrI4= +go.mau.fi/whatsmeow v0.0.0-20220312175208-0c4681a6ff52/go.mod h1:nH4IwHZf+Ks61nM5p71jZqLXiT0NpG+0uR/WqzCqHH8= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= diff --git a/main.go b/main.go index fbb2681..6a68b01 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ import ( _ "embed" "errors" "fmt" + "net/http" "os" "os/signal" "strconv" @@ -30,6 +31,7 @@ import ( "google.golang.org/protobuf/proto" + "go.mau.fi/whatsmeow" waProto "go.mau.fi/whatsmeow/binary/proto" "go.mau.fi/whatsmeow/store" "go.mau.fi/whatsmeow/store/sqlstore" @@ -318,6 +320,7 @@ func (bridge *Bridge) Start() { go bridge.AS.Start() bridge.Log.Debugln("Starting event processor") go bridge.EventProcessor.Start() + go bridge.CheckWhatsAppUpdate() go bridge.UpdateBotProfile() if bridge.Crypto != nil { go bridge.Crypto.Start() @@ -334,6 +337,26 @@ func (bridge *Bridge) Start() { bridge.AS.Ready = true } +func (bridge *Bridge) CheckWhatsAppUpdate() { + bridge.Log.Debugfln("Checking for WhatsApp web update") + resp, err := whatsmeow.CheckUpdate(http.DefaultClient) + if err != nil { + bridge.Log.Warnfln("Failed to check for WhatsApp web update: %v", err) + return + } + if store.GetWAVersion() == resp.ParsedVersion { + bridge.Log.Debugfln("Bridge is using latest WhatsApp web protocol") + } else if store.GetWAVersion().LessThan(resp.ParsedVersion) { + if resp.IsBelowHard || resp.IsBelowSoft || resp.IsBroken { + bridge.Log.Warnfln("Bridge is using outdated WhatsApp web protocol and may no longer function (%s, latest is %s)", store.GetWAVersion(), resp.ParsedVersion) + } else { + bridge.Log.Debugfln("Bridge is using outdated WhatsApp web protocol (%s, latest is %s)", store.GetWAVersion(), resp.ParsedVersion) + } + } else { + bridge.Log.Debugfln("Bridge is using newer than latest WhatsApp web protocol") + } +} + func (bridge *Bridge) Loop() { for { bridge.SleepAndDeleteUpcoming()