gmessages/libgm/event_handler.go

34 lines
924 B
Go
Raw Normal View History

2023-06-30 11:05:33 +00:00
package libgm
2023-06-30 09:54:08 +00:00
import (
"encoding/base64"
"google.golang.org/protobuf/proto"
2023-06-30 09:54:08 +00:00
"go.mau.fi/mautrix-gmessages/libgm/binary"
)
func (c *Client) handleEventOpCode(response *Response) {
2023-06-30 11:48:50 +00:00
c.Logger.Debug().Any("res", response).Msg("got event response?")
2023-06-30 09:54:08 +00:00
eventData := &binary.Event{}
data, decryptedErr := c.cryptor.Decrypt(response.Data.EncryptedData)
2023-06-30 09:54:08 +00:00
if decryptedErr != nil {
2023-06-30 11:48:50 +00:00
panic(decryptedErr)
2023-06-30 09:54:08 +00:00
}
c.Logger.Debug().Str("protobuf_data", base64.StdEncoding.EncodeToString(data)).Msg("decrypted data")
err := proto.Unmarshal(data, eventData)
if err != nil {
panic(err)
}
2023-06-30 09:54:08 +00:00
switch evt := eventData.Event.(type) {
case *binary.Event_MessageEvent:
c.handleMessageEvent(response, evt)
case *binary.Event_ConversationEvent:
c.handleConversationEvent(response, evt)
case *binary.Event_UserAlertEvent:
c.handleUserAlertEvent(response, evt)
default:
c.Logger.Debug().Any("res", response).Msg("unknown event")
}
}