]> git.giacomolli.uk - onechat/blobdiff - whatsapp.go
Parse cron expressions and find the next time
[onechat] / whatsapp.go
index b883496aea73266c0ce87889c9e1d9895b25335a..75de73f96c57b25fb717bde9189103e5518b3937 100644 (file)
@@ -14,6 +14,7 @@ import (
        "time"
 
        "go.mau.fi/whatsmeow"
+       "go.mau.fi/whatsmeow/proto/waCompanionReg"
        "go.mau.fi/whatsmeow/proto/waE2E"
        "go.mau.fi/whatsmeow/store"
        "go.mau.fi/whatsmeow/store/sqlstore"
@@ -594,6 +595,8 @@ func (w *WhatsApp) pair(ctx, runCtx context.Context, l *TurnLoop, phone string,
                return
        }
 
+       // The server accepts only a display name of the form "Browser (OS)"
+       // with a common browser and OS, and refuses the pairing otherwise.
        code, err := client.PairPhone(ctx, phone, true, whatsmeow.PairClientChrome, "Chrome (Linux)")
        if err != nil {
                answer("WhatsApp refused the pairing: " + err.Error() + ". Check the phone number and run /whatsapp pair PHONE again.")
@@ -817,12 +820,20 @@ type WhatsAppRequest struct {
        answer func(text string)
 }
 
+// whatsappSetDeviceProps sets the device properties that the library sends at
+// the pairing. They are global values of the library, so the daemon sets them
+// once before any client exists. The phone shows the linked device with the
+// name OneChat and a desktop icon only when the platform type is known.
+func whatsappSetDeviceProps() {
+       store.SetOSInfo("OneChat", [3]uint32{0, 1, 0})
+       store.DeviceProps.PlatformType = waCompanionReg.DeviceProps_DESKTOP.Enum()
+}
+
 // whatsappNewClient returns the client of the library for device, with handle
 // as its event handler. The client tries again after a failed first connection,
 // acknowledges a message only after handle returns true, and downloads no old
-// history. The phone shows the device with the name OneChat.
+// history.
 func whatsappNewClient(device *store.Device, handle func(event any) bool) WhatsAppClient {
-       store.SetOSInfo("OneChat", [3]uint32{0, 1, 0})
        client := whatsmeow.NewClient(device, waLog.Noop)
        client.InitialAutoReconnect = true
        client.SynchronousAck = true