Updated to whatsmeow commit 0b502af

This commit is contained in:
Peter Pudaite 2025-05-29 11:42:19 +01:00
parent 89b0fa90cd
commit 1fb3ba8723
5 changed files with 29 additions and 18 deletions

View File

@ -4,6 +4,7 @@
package bwhatsapp
import (
"context"
"fmt"
"mime"
"strings"
@ -242,7 +243,8 @@ func (b *Bwhatsapp) handleImageMessage(msg *events.Message) {
b.Log.Debugf("Trying to download %s with type %s", filename, imsg.GetMimetype())
data, err := b.wc.Download(imsg)
// Fix: Add context.Background() as first parameter
data, err := b.wc.Download(context.Background(), imsg)
if err != nil {
b.Log.Errorf("Download image failed: %s", err)
@ -309,7 +311,8 @@ func (b *Bwhatsapp) handleVideoMessage(msg *events.Message) {
b.Log.Debugf("Trying to download %s with size %#v and type %s", filename, imsg.GetFileLength(), imsg.GetMimetype())
data, err := b.wc.Download(imsg)
// Fix: Add context.Background() as first parameter
data, err := b.wc.Download(context.Background(), imsg)
if err != nil {
b.Log.Errorf("Download video failed: %s", err)
@ -366,7 +369,8 @@ func (b *Bwhatsapp) handleAudioMessage(msg *events.Message) {
b.Log.Debugf("Trying to download %s with size %#v and type %s", filename, imsg.GetFileLength(), imsg.GetMimetype())
data, err := b.wc.Download(imsg)
// Fix: Add context.Background() as first parameter
data, err := b.wc.Download(context.Background(), imsg)
if err != nil {
b.Log.Errorf("Download video failed: %s", err)
@ -420,7 +424,8 @@ func (b *Bwhatsapp) handleDocumentMessage(msg *events.Message) {
b.Log.Debugf("Trying to download %s with extension %s and type %s", filename, fileExt, imsg.GetMimetype())
data, err := b.wc.Download(imsg)
// Fix: Add context.Background() as first parameter
data, err := b.wc.Download(context.Background(), imsg)
if err != nil {
b.Log.Errorf("Download document message failed: %s", err)
@ -451,4 +456,4 @@ func (b *Bwhatsapp) handleDelete(messageInfo *proto.ProtocolMessage) {
b.Log.Debugf("<= Sending message from %s to gateway", b.Account)
b.Log.Debugf("<= Message is %#v", rmsg)
b.Remote <- rmsg
}
}

View File

@ -4,6 +4,7 @@
package bwhatsapp
import (
"context"
"fmt"
"strings"
@ -14,6 +15,7 @@ import (
"go.mau.fi/whatsmeow/store"
"go.mau.fi/whatsmeow/store/sqlstore"
"go.mau.fi/whatsmeow/types"
waLog "go.mau.fi/whatsmeow/util/log"
)
type ProfilePicInfo struct {
@ -23,11 +25,13 @@ type ProfilePicInfo struct {
}
func (b *Bwhatsapp) reloadContacts() {
if _, err := b.wc.Store.Contacts.GetAllContacts(); err != nil {
// Fix: Add context.Background() as first parameter
if _, err := b.wc.Store.Contacts.GetAllContacts(context.Background()); err != nil {
b.Log.Errorf("error on update of contacts: %v", err)
}
allcontacts, err := b.wc.Store.Contacts.GetAllContacts()
// Fix: Add context.Background() as first parameter
allcontacts, err := b.wc.Store.Contacts.GetAllContacts(context.Background())
if err != nil {
b.Log.Errorf("error on update of contacts: %v", err)
}
@ -134,18 +138,20 @@ func isGroupJid(identifier string) bool {
}
func isPrivateJid(identifier string) bool {
return strings.HasSuffix(identifier, "@s.whatsapp.net")
return strings.HasSuffix(identifier, "@s.whatsapp.net")
}
func (b *Bwhatsapp) getDevice() (*store.Device, error) {
device := &store.Device{}
storeContainer, err := sqlstore.New("sqlite", "file:"+b.Config.GetString("sessionfile")+".db?_pragma=foreign_keys(1)&_pragma=busy_timeout=10000", nil)
// Fix: Add context.Background() as first parameter and waLog.Noop logger
storeContainer, err := sqlstore.New(context.Background(), "sqlite", "file:"+b.Config.GetString("sessionfile")+".db?_pragma=foreign_keys(1)&_pragma=busy_timeout=10000", waLog.Noop)
if err != nil {
return device, fmt.Errorf("failed to connect to database: %v", err)
}
device, err = storeContainer.GetFirstDevice()
// Fix: Add context.Background() as first parameter
device, err = storeContainer.GetFirstDevice(context.Background())
if err != nil {
return device, fmt.Errorf("failed to get device: %v", err)
}
@ -210,4 +216,4 @@ func getMessageIdFormat(jid types.JID, messageID string) string {
// we're crafting our own JID str as AD JID format messes with how stuff looks on a webclient
jidStr := fmt.Sprintf("%s@%s", jid.User, jid.Server)
return fmt.Sprintf("%s/%s", jidStr, messageID)
}
}

View File

@ -122,7 +122,8 @@ func (b *Bwhatsapp) Connect() error {
b.Log.Infoln("WhatsApp connection successful")
b.contacts, err = b.wc.Store.Contacts.GetAllContacts()
// Fix: Add context.Background() as first parameter
b.contacts, err = b.wc.Store.Contacts.GetAllContacts(context.Background())
if err != nil {
return errors.New("failed to get contacts: " + err.Error())
}
@ -176,7 +177,6 @@ func (b *Bwhatsapp) Disconnect() error {
// Required implementation of the Bridger interface
// https://github.com/42wim/matterbridge/blob/2cfd880cdb0df29771bf8f31df8d990ab897889d/bridge/bridge.go#L11-L16
func (b *Bwhatsapp) JoinChannel(channel config.ChannelInfo) error {
// Check if this is a private chat JID
if isPrivateJid(channel.Name) {
// For private chats, validate the JID format but don't require group membership
@ -184,12 +184,12 @@ func (b *Bwhatsapp) JoinChannel(channel config.ChannelInfo) error {
if err != nil {
return fmt.Errorf("invalid WhatsApp private chat JID format: %s", err)
}
// Optionally verify that the contact exists in the contacts list
if _, exists := b.contacts[jid]; !exists {
b.Log.Warnf("Private chat contact %s not found in contacts list, but will attempt to bridge anyway", channel.Name)
}
b.Log.Infof("Configured private chat channel: %s", channel.Name)
return nil
}
@ -472,4 +472,4 @@ func (b *Bwhatsapp) sendMessage(rmsg config.Message, message *proto.Message) (st
_, err := b.wc.SendMessage(context.Background(), groupJID, message, whatsmeow.SendRequestExtra{ID: ID})
return getMessageIdFormat(*b.wc.Store.ID, ID), err
}
}

2
go.mod
View File

@ -46,7 +46,7 @@ require (
github.com/writeas/go-strip-markdown v2.0.1+incompatible
github.com/yaegashi/msgraph.go v0.1.4
github.com/zfjagann/golang-ring v0.0.0-20220330170733-19bcea1b6289
go.mau.fi/whatsmeow v0.0.0-20240821142752-3d63c6fcc1a7
go.mau.fi/whatsmeow v0.0.0-20250527134344-0b502af800ee
golang.org/x/image v0.19.0
golang.org/x/oauth2 v0.22.0
golang.org/x/text v0.17.0

2
vendor/modules.txt vendored
View File

@ -490,7 +490,7 @@ go.mau.fi/libsignal/util/optional
go.mau.fi/util/jsontime
go.mau.fi/util/random
go.mau.fi/util/retryafter
# go.mau.fi/whatsmeow v0.0.0-20240821142752-3d63c6fcc1a7
# go.mau.fi/whatsmeow v0.0.0-20250527134344-0b502af800ee
## explicit; go 1.21
go.mau.fi/whatsmeow
go.mau.fi/whatsmeow/appstate