1
0
Fork 0
mirror of https://github.com/mautrix/whatsapp.git synced 2026-05-14 17:56:53 -04:00

Compare commits

...

1 commit

Author SHA1 Message Date
Rajeh Taher
31344c4507 client,connector: Support external whatsmeow event handlers 2025-10-07 23:14:32 +03:00
3 changed files with 12 additions and 0 deletions

View file

@ -73,6 +73,11 @@ func (wa *WhatsAppConnector) LoadUserLogin(ctx context.Context, login *bridgev2.
log := w.UserLogin.Log.With().Str("component", "whatsmeow").Logger() log := w.UserLogin.Log.With().Str("component", "whatsmeow").Logger()
w.Client = whatsmeow.NewClient(w.Device, waLog.Zerolog(log)) w.Client = whatsmeow.NewClient(w.Device, waLog.Zerolog(log))
w.Client.AddEventHandlerWithSuccessStatus(w.handleWAEvent) w.Client.AddEventHandlerWithSuccessStatus(w.handleWAEvent)
if wa.ExternalEventHandler != nil {
w.Client.AddEventHandler(func(evt any) {
wa.ExternalEventHandler(w.Client, evt)
})
}
w.Client.SynchronousAck = true w.Client.SynchronousAck = true
if bridgev2.PortalEventBuffer == 0 { if bridgev2.PortalEventBuffer == 0 {
w.Client.EnableDecryptedEventBuffer = true w.Client.EnableDecryptedEventBuffer = true

View file

@ -57,6 +57,8 @@ type WhatsAppConnector struct {
mediaEditCache MediaEditCache mediaEditCache MediaEditCache
mediaEditCacheLock sync.RWMutex mediaEditCacheLock sync.RWMutex
stopMediaEditCacheLoop atomic.Pointer[context.CancelFunc] stopMediaEditCacheLoop atomic.Pointer[context.CancelFunc]
ExternalEventHandler func(client *whatsmeow.Client, rawEvt any)
} }
func init() { func init() {

View file

@ -128,6 +128,11 @@ func (wl *WALogin) Start(ctx context.Context) (*bridgev2.LoginStep, error) {
wl.Client.EnableAutoReconnect = false wl.Client.EnableAutoReconnect = false
wl.Client.DisableLoginAutoReconnect = true wl.Client.DisableLoginAutoReconnect = true
wl.EventHandlerID = wl.Client.AddEventHandler(wl.handleEvent) wl.EventHandlerID = wl.Client.AddEventHandler(wl.handleEvent)
if wl.Main.ExternalEventHandler != nil {
wl.Client.AddEventHandler(func(evt any) {
wl.Main.ExternalEventHandler(wl.Client, evt)
})
}
if err := wl.Main.updateProxy(ctx, wl.Client, true); err != nil { if err := wl.Main.updateProxy(ctx, wl.Client, true); err != nil {
return nil, err return nil, err
} }