Skip to content

Commit

Permalink
Renamed Hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
rcorniere committed Mar 10, 2020
1 parent 477a2b1 commit 7850d07
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ type Client struct {
ErrorHandler func(error)

// Post connection hook. This will be executed on first connection
PostFirstConnHook func() error
PostConnectHook func() error

// Post resume hook. This will be executed after the client resumes a lost connection using StreamManagement (XEP-0198)
PostReconnectHook func() error
PostResumeHook func() error
}

/*
Expand Down Expand Up @@ -213,7 +213,7 @@ func NewClient(config *Config, r *Router, errorHandler func(error)) (c *Client,
}

// Connect establishes a first time connection to a XMPP server.
// It calls the PostFirstConnHook
// It calls the PostConnectHook
func (c *Client) Connect() error {
err := c.connect()
if err != nil {
Expand All @@ -223,8 +223,8 @@ func (c *Client) Connect() error {
// Do we need an option to avoid that or do we rely on client to send the presence itself ?
err = c.sendWithWriter(c.transport, []byte(InitialPresence))
// Execute the post first connection hook. Typically this holds "ask for roster" and this type of actions.
if c.PostFirstConnHook != nil {
err = c.PostFirstConnHook()
if c.PostConnectHook != nil {
err = c.PostConnectHook()
if err != nil {
return err
}
Expand Down Expand Up @@ -287,8 +287,8 @@ func (c *Client) Resume() error {
}
// Execute post reconnect hook. This can be different from the first connection hook, and not trigger roster retrival
// for example.
if c.PostReconnectHook != nil {
err = c.PostReconnectHook()
if c.PostResumeHook != nil {
err = c.PostResumeHook()
}
return err
}
Expand Down
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func Test_ClientPostConnectHook(t *testing.T) {
}

// The post connection client hook should just write to a channel that we will read later.
client.PostFirstConnHook = func() error {
client.PostConnectHook = func() error {
go func() {
hookChan <- struct{}{}
}()
Expand Down Expand Up @@ -486,7 +486,7 @@ func Test_ClientPostReconnectHook(t *testing.T) {
t.Errorf("connect create XMPP client: %s", err)
}

client.PostReconnectHook = func() error {
client.PostResumeHook = func() error {
go func() {
hookChan <- struct{}{}
}()
Expand Down

0 comments on commit 7850d07

Please sign in to comment.