mirror of
https://github.com/mautrix/whatsapp.git
synced 2025-03-14 14:15:38 +00:00
dependencies: update whatsmeow for apns push
This commit is contained in:
parent
171e3a7b6b
commit
5b1effcd51
4 changed files with 33 additions and 9 deletions
4
go.mod
4
go.mod
|
@ -9,10 +9,9 @@ require (
|
|||
github.com/gorilla/websocket v1.5.0
|
||||
github.com/lib/pq v1.10.9
|
||||
github.com/rs/zerolog v1.33.0
|
||||
github.com/tidwall/gjson v1.18.0
|
||||
go.mau.fi/util v0.8.6-0.20250227184636-7ff63b0b9d95
|
||||
go.mau.fi/webp v0.2.0
|
||||
go.mau.fi/whatsmeow v0.0.0-20250306135213-ae5c492c5067
|
||||
go.mau.fi/whatsmeow v0.0.0-20250311112832-01523b1e7109
|
||||
golang.org/x/image v0.24.0
|
||||
golang.org/x/net v0.35.0
|
||||
golang.org/x/sync v0.11.0
|
||||
|
@ -33,6 +32,7 @@ require (
|
|||
github.com/rogpeppe/go-internal v1.10.0 // indirect
|
||||
github.com/rs/xid v1.6.0 // indirect
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
|
||||
github.com/tidwall/gjson v1.18.0 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.1 // indirect
|
||||
github.com/tidwall/sjson v1.2.5 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -70,8 +70,8 @@ go.mau.fi/util v0.8.6-0.20250227184636-7ff63b0b9d95 h1:5EfVWWjU2Hte9uE6B/hBgvjnV
|
|||
go.mau.fi/util v0.8.6-0.20250227184636-7ff63b0b9d95/go.mod h1:Ycug9mrbztlahHPEJ6H5r8Nu/xqZaWbE5vPHVWmfz6M=
|
||||
go.mau.fi/webp v0.2.0 h1:QVMenHw7JDb4vall5sV75JNBQj9Hw4u8AKbi1QetHvg=
|
||||
go.mau.fi/webp v0.2.0/go.mod h1:VSg9MyODn12Mb5pyG0NIyNFhujrmoFSsZBs8syOZD1Q=
|
||||
go.mau.fi/whatsmeow v0.0.0-20250306135213-ae5c492c5067 h1:ScfoS96E8XvYp/FWHK+iN2TCifR5gTbkkltQ9bYDCRQ=
|
||||
go.mau.fi/whatsmeow v0.0.0-20250306135213-ae5c492c5067/go.mod h1:6hRrUtDWI2wTRClOd6m17GwrFE2a8/p5R4pjJsIVn+U=
|
||||
go.mau.fi/whatsmeow v0.0.0-20250311112832-01523b1e7109 h1:/B6T0f6dmPKmld8uuZEhDTINJltxSBrUYA4ECsUQ9pE=
|
||||
go.mau.fi/whatsmeow v0.0.0-20250311112832-01523b1e7109/go.mod h1:6hRrUtDWI2wTRClOd6m17GwrFE2a8/p5R4pjJsIVn+U=
|
||||
go.mau.fi/zeroconfig v0.1.3 h1:As9wYDKmktjmNZW5i1vn8zvJlmGKHeVxHVIBMXsm4kM=
|
||||
go.mau.fi/zeroconfig v0.1.3/go.mod h1:NcSJkf180JT+1IId76PcMuLTNa1CzsFFZ0nBygIQM70=
|
||||
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
|
||||
|
|
|
@ -18,13 +18,14 @@ package connector
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/tidwall/gjson"
|
||||
"go.mau.fi/util/random"
|
||||
"go.mau.fi/whatsmeow"
|
||||
waBinary "go.mau.fi/whatsmeow/binary"
|
||||
"go.mau.fi/whatsmeow/proto/waHistorySync"
|
||||
|
@ -148,7 +149,15 @@ func (wa *WhatsAppClient) RegisterPushNotifications(ctx context.Context, pushTyp
|
|||
P256DH: meta.PushKeys.P256DH,
|
||||
}
|
||||
case bridgev2.PushTypeAPNs:
|
||||
pc = &whatsmeow.APNsPushConfig{Token: token}
|
||||
meta := wa.UserLogin.Metadata.(*waid.UserLoginMetadata)
|
||||
if meta.APNSEncKey == nil {
|
||||
meta.APNSEncKey = random.Bytes(32)
|
||||
err := wa.UserLogin.Save(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to save push enc key: %w", err)
|
||||
}
|
||||
}
|
||||
pc = &whatsmeow.APNsPushConfig{Token: token, MsgIDEncKey: meta.APNSEncKey}
|
||||
default:
|
||||
return fmt.Errorf("unsupported push type %s", pushType)
|
||||
}
|
||||
|
@ -188,6 +197,19 @@ func (wa *WhatsAppClient) notifyOfflineSyncWaiter(err error) {
|
|||
}
|
||||
}
|
||||
|
||||
type PushNotificationData struct {
|
||||
PN string `json:"pn"`
|
||||
EncIV string `json:"enc_iv"`
|
||||
EncPayload string `json:"enc_p"`
|
||||
EncTag string `json:"enc_t"`
|
||||
EncTimeMicros uint64 `json:"enc_c"`
|
||||
// TODO unencrypted message ID field
|
||||
}
|
||||
|
||||
type wrappedPushNotificationData struct {
|
||||
Data PushNotificationData `json:"data"`
|
||||
}
|
||||
|
||||
func (wa *WhatsAppClient) ConnectBackground(ctx context.Context, params *bridgev2.ConnectBackgroundParams) error {
|
||||
if wa.Client == nil {
|
||||
return bridgev2.ErrNotLoggedIn
|
||||
|
@ -215,9 +237,10 @@ func (wa *WhatsAppClient) ConnectBackground(ctx context.Context, params *bridgev
|
|||
return ctx.Err()
|
||||
case err = <-wa.offlineSyncWaiter:
|
||||
if err == nil {
|
||||
pn := gjson.GetBytes(params.RawData, "data.pn").Str
|
||||
if pn != "" {
|
||||
pnErr := wa.sendPNData(ctx, pn)
|
||||
var data wrappedPushNotificationData
|
||||
err = json.Unmarshal(params.RawData, &data)
|
||||
if err == nil && data.Data.PN != "" {
|
||||
pnErr := wa.sendPNData(ctx, data.Data.PN)
|
||||
if pnErr != nil {
|
||||
zerolog.Ctx(ctx).Err(pnErr).Msg("Failed to send PN data")
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ type UserLoginMetadata struct {
|
|||
PhoneLastPinged jsontime.Unix `json:"phone_last_pinged"`
|
||||
Timezone string `json:"timezone"`
|
||||
PushKeys *PushKeys `json:"push_keys,omitempty"`
|
||||
APNSEncKey []byte `json:"apns_enc_key,omitempty"`
|
||||
|
||||
HistorySyncPortalsNeedCreating bool `json:"history_sync_portals_need_creating,omitempty"`
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue