diff --git a/libgm/client.go b/libgm/client.go index 710ae5f..fc71474 100644 --- a/libgm/client.go +++ b/libgm/client.go @@ -70,6 +70,9 @@ func NewClient(devicePair *DevicePair, cryptor *crypto.Cryptor, logger zerolog.L } func (c *Client) SetEventHandler(eventHandler EventHandler) { + if eventHandler == nil { + eventHandler = func(_ interface{}) {} + } c.evHandler = eventHandler } @@ -124,6 +127,19 @@ func (c *Client) Reconnect(rpcKey []byte) error { return nil } +func (c *Client) Disconnect() { + c.rpc.CloseConnection() + c.http.CloseIdleConnections() +} + +func (c *Client) IsConnected() bool { + return c.rpc != nil +} + +func (c *Client) IsLoggedIn() bool { + return c.devicePair != nil +} + func (c *Client) triggerEvent(evt interface{}) { if c.evHandler != nil { c.evHandler(evt) diff --git a/libgm/rpc.go b/libgm/rpc.go index 775932d..4ff51e7 100644 --- a/libgm/rpc.go +++ b/libgm/rpc.go @@ -159,6 +159,11 @@ func (r *RPC) sendInitialData() error { return err } + _, convErr := r.client.Conversations.List(25) + if convErr != nil { + return convErr + } + evtData := events.NewClientReady(sessionResponse) r.client.triggerEvent(evtData) r.client.sessionHandler.startAckInterval()