Renamed Hooks

160-regression
rcorniere 4 years ago
parent 477a2b114c
commit 7850d07d37

@ -139,10 +139,10 @@ type Client struct {
ErrorHandler func(error) ErrorHandler func(error)
// Post connection hook. This will be executed on first connection // 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) // Post resume hook. This will be executed after the client resumes a lost connection using StreamManagement (XEP-0198)
PostReconnectHook func() error PostResumeHook func() error
} }
/* /*
@ -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. // Connect establishes a first time connection to a XMPP server.
// It calls the PostFirstConnHook // It calls the PostConnectHook
func (c *Client) Connect() error { func (c *Client) Connect() error {
err := c.connect() err := c.connect()
if err != nil { if err != nil {
@ -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 ? // 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)) err = c.sendWithWriter(c.transport, []byte(InitialPresence))
// Execute the post first connection hook. Typically this holds "ask for roster" and this type of actions. // Execute the post first connection hook. Typically this holds "ask for roster" and this type of actions.
if c.PostFirstConnHook != nil { if c.PostConnectHook != nil {
err = c.PostFirstConnHook() err = c.PostConnectHook()
if err != nil { if err != nil {
return err return err
} }
@ -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 // Execute post reconnect hook. This can be different from the first connection hook, and not trigger roster retrival
// for example. // for example.
if c.PostReconnectHook != nil { if c.PostResumeHook != nil {
err = c.PostReconnectHook() err = c.PostResumeHook()
} }
return err return err
} }

@ -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. // 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() { go func() {
hookChan <- struct{}{} hookChan <- struct{}{}
}() }()
@ -486,7 +486,7 @@ func Test_ClientPostReconnectHook(t *testing.T) {
t.Errorf("connect create XMPP client: %s", err) t.Errorf("connect create XMPP client: %s", err)
} }
client.PostReconnectHook = func() error { client.PostResumeHook = func() error {
go func() { go func() {
hookChan <- struct{}{} hookChan <- struct{}{}
}() }()

Loading…
Cancel
Save