Remove unnecessary QR image generation

This commit is contained in:
Tulir Asokan 2023-06-30 13:43:54 +03:00
parent 766f16d113
commit 13f47319b2
3 changed files with 6 additions and 43 deletions

View file

@ -1,22 +1,5 @@
package events
type QRCODE_UPDATED struct {
Image []byte
Height int
Width int
googleUrl string
}
func NewQrCodeUpdated(image []byte, height int, width int, googleUrl string) *QRCODE_UPDATED {
return &QRCODE_UPDATED{
Image: image,
Height: height,
Width: width,
googleUrl: googleUrl,
}
}
func (q *QRCODE_UPDATED) GetGoogleUrl() string {
return q.googleUrl
URL string
}

View file

@ -7,6 +7,7 @@ import (
"go.mau.fi/mautrix-gmessages/libgm/binary"
"go.mau.fi/mautrix-gmessages/libgm/crypto"
"go.mau.fi/mautrix-gmessages/libgm/events"
"go.mau.fi/mautrix-gmessages/libgm/payload"
"go.mau.fi/mautrix-gmessages/libgm/util"
)
@ -16,7 +17,6 @@ type Pairer struct {
KeyData *crypto.JWK
ticker *time.Ticker
tickerTime time.Duration
qrCodePx int
pairingKey []byte
}
@ -35,17 +35,12 @@ func (c *Client) NewPairer(keyData *crypto.JWK, refreshQrCodeTime int) (*Pairer,
p := &Pairer{
client: c,
KeyData: keyData,
qrCodePx: 214,
tickerTime: time.Duration(refreshQrCodeTime) * time.Second,
}
c.pairer = p
return p, nil
}
func (p *Pairer) SetQRCodePx(pixels int) {
p.qrCodePx = pixels
}
func (p *Pairer) RegisterPhoneRelay() (*binary.RegisterPhoneRelayResponse, error) {
body, _, err := payload.RegisterPhoneRelay(p.KeyData)
if err != nil {
@ -69,11 +64,11 @@ func (p *Pairer) RegisterPhoneRelay() (*binary.RegisterPhoneRelayResponse, error
return nil, err3
}
p.pairingKey = res.GetPairingKey()
qrCode, qrErr := p.GenerateQRCode(p.qrCodePx)
url, qrErr := p.GenerateQRCodeData()
if qrErr != nil {
return nil, qrErr
}
p.client.triggerEvent(qrCode)
p.client.triggerEvent(&events.QRCODE_UPDATED{URL: url})
p.startRefreshRelayTask()
return res, err
}
@ -115,11 +110,11 @@ func (p *Pairer) RefreshPhoneRelay() {
}
p.pairingKey = res.GetPairKey()
p.client.Logger.Debug().Any("res", res).Msg("RefreshPhoneRelayResponse")
qrCode, qrErr := p.GenerateQRCode(p.qrCodePx)
url, qrErr := p.GenerateQRCodeData()
if qrErr != nil {
log.Fatal(qrErr)
}
p.client.triggerEvent(qrCode)
p.client.triggerEvent(&events.QRCODE_UPDATED{URL: url})
}
func (p *Pairer) GetWebEncryptionKey() {

View file

@ -3,10 +3,7 @@ package textgapi
import (
"go.mau.fi/mautrix-gmessages/libgm/binary"
"go.mau.fi/mautrix-gmessages/libgm/crypto"
"go.mau.fi/mautrix-gmessages/libgm/events"
"go.mau.fi/mautrix-gmessages/libgm/util"
"github.com/skip2/go-qrcode"
)
func (p *Pairer) GenerateQRCodeData() (string, error) {
@ -22,15 +19,3 @@ func (p *Pairer) GenerateQRCodeData() (string, error) {
cData := crypto.Base64Encode(encodedUrlData)
return util.QR_CODE_URL + cData, nil
}
func (p *Pairer) GenerateQRCode(size int) (*events.QRCODE_UPDATED, error) {
data, err1 := p.GenerateQRCodeData()
if err1 != nil {
return nil, err1
}
png, err2 := qrcode.Encode(data, qrcode.Highest, size)
if err2 != nil {
return nil, err2
}
return events.NewQrCodeUpdated(png, size, size, data), nil
}