diff --git a/pkg/connector/client.go b/pkg/connector/client.go index cd52be28..85e55546 100644 --- a/pkg/connector/client.go +++ b/pkg/connector/client.go @@ -124,6 +124,7 @@ type WhatsAppClient struct { isNewLogin bool pushNamesSynced *exsync.Event lastPresence types.Presence + lastUnifiedSession atomic.Int64 blocklistLock sync.Mutex disableNewsletter bool @@ -511,6 +512,15 @@ func (wa *WhatsAppClient) updatePresence(ctx context.Context, presence types.Pre return err } +func (wa *WhatsAppClient) sendDailyUnifiedSession() { + last := wa.lastUnifiedSession.Load() + if time.Since(time.Unix(last, 0)) < 24*time.Hour || !wa.lastUnifiedSession.CompareAndSwap(last, time.Now().Unix()) { + return + } + //lint:ignore SA1019 this is supposed to be dangerous + go wa.Client.DangerousInternals().SendUnifiedSession() +} + func (wa *WhatsAppClient) DownloadImagePack(ctx context.Context, url string) (*bridgev2.ImportedImagePack, error) { return wa.Main.MsgConv.DownloadImagePack(ctx, wa.UserLogin.ID, wa.Client, url) } diff --git a/pkg/connector/handlematrix.go b/pkg/connector/handlematrix.go index fec40c3c..074439fa 100644 --- a/pkg/connector/handlematrix.go +++ b/pkg/connector/handlematrix.go @@ -141,6 +141,7 @@ func (wa *WhatsAppClient) handleConvertedMatrixMessage(ctx context.Context, msg } return nil, wrapWhatsAppError(err) } + wa.sendDailyUnifiedSession() var pickedMessageID networkid.MessageID if resp.Sender == wa.GetLID() { pickedMessageID = wrappedMsgID2