@@ -8,6 +8,7 @@ package whatsmeow
8
8
9
9
import (
10
10
"context"
11
+ "slices"
11
12
"sync"
12
13
"sync/atomic"
13
14
"time"
@@ -58,10 +59,10 @@ type qrChannel struct {
58
59
stopQRs chan struct {}
59
60
}
60
61
61
- func (qrc * qrChannel ) emitQRs (evt * events. QR ) {
62
+ func (qrc * qrChannel ) emitQRs (codes [] string ) {
62
63
var nextCode string
63
64
for {
64
- if len (evt . Codes ) == 0 {
65
+ if len (codes ) == 0 {
65
66
if atomic .CompareAndSwapUint32 (& qrc .closed , 0 , 1 ) {
66
67
qrc .log .Debugf ("Ran out of QR codes, closing channel with status %s and disconnecting client" , QRChannelTimeout )
67
68
qrc .output <- QRChannelTimeout
@@ -77,10 +78,10 @@ func (qrc *qrChannel) emitQRs(evt *events.QR) {
77
78
return
78
79
}
79
80
timeout := 20 * time .Second
80
- if len (evt . Codes ) == 6 {
81
+ if len (codes ) == 6 {
81
82
timeout = 60 * time .Second
82
83
}
83
- nextCode , evt . Codes = evt . Codes [0 ], evt . Codes [1 :]
84
+ nextCode , codes = codes [0 ], codes [1 :]
84
85
qrc .log .Debugf ("Emitting QR code %s" , nextCode )
85
86
select {
86
87
case qrc .output <- QRChannelItem {Code : nextCode , Timeout : timeout , Event : QRChannelEventCode }:
@@ -118,7 +119,7 @@ func (qrc *qrChannel) handleEvent(rawEvt interface{}) {
118
119
switch evt := rawEvt .(type ) {
119
120
case * events.QR :
120
121
qrc .log .Debugf ("Received QR code event, starting to emit codes to channel" )
121
- go qrc .emitQRs (evt )
122
+ go qrc .emitQRs (slices . Clone ( evt . Codes ) )
122
123
return
123
124
case * events.QRScannedWithoutMultidevice :
124
125
qrc .log .Debugf ("QR code scanned without multidevice enabled" )
0 commit comments