Change more stuff

This commit is contained in:
Tulir Asokan 2023-07-01 18:19:57 +03:00
parent a0fcf0c275
commit 6e7143d532
2 changed files with 21 additions and 0 deletions

View file

@ -70,6 +70,9 @@ func NewClient(devicePair *DevicePair, cryptor *crypto.Cryptor, logger zerolog.L
} }
func (c *Client) SetEventHandler(eventHandler EventHandler) { func (c *Client) SetEventHandler(eventHandler EventHandler) {
if eventHandler == nil {
eventHandler = func(_ interface{}) {}
}
c.evHandler = eventHandler c.evHandler = eventHandler
} }
@ -124,6 +127,19 @@ func (c *Client) Reconnect(rpcKey []byte) error {
return nil 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{}) { func (c *Client) triggerEvent(evt interface{}) {
if c.evHandler != nil { if c.evHandler != nil {
c.evHandler(evt) c.evHandler(evt)

View file

@ -159,6 +159,11 @@ func (r *RPC) sendInitialData() error {
return err return err
} }
_, convErr := r.client.Conversations.List(25)
if convErr != nil {
return convErr
}
evtData := events.NewClientReady(sessionResponse) evtData := events.NewClientReady(sessionResponse)
r.client.triggerEvent(evtData) r.client.triggerEvent(evtData)
r.client.sessionHandler.startAckInterval() r.client.sessionHandler.startAckInterval()