Fix subscriptions after logging in
This commit is contained in:
parent
d36f4449c9
commit
462a537021
|
@ -117,9 +117,31 @@ func (c *Client) Connect() error {
|
||||||
|
|
||||||
c.client = tdlibClient
|
c.client = tdlibClient
|
||||||
c.locks.authorizationReady.Done()
|
c.locks.authorizationReady.Done()
|
||||||
c.online = true
|
|
||||||
|
// stage 3: if a client is succesfully created, AuthorizationStateReady is already reached
|
||||||
|
log.Warn("Authorization successful!")
|
||||||
|
|
||||||
|
c.me, err = c.client.GetMe()
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Could not retrieve me info")
|
||||||
|
} else if c.Session.Login == "" {
|
||||||
|
c.Session.Login = c.me.PhoneNumber
|
||||||
|
}
|
||||||
|
|
||||||
go c.updateHandler()
|
go c.updateHandler()
|
||||||
|
c.online = true
|
||||||
|
|
||||||
|
_, err = c.client.GetChats(&client.GetChatsRequest{
|
||||||
|
OffsetOrder: client.JsonInt64(math.MaxInt64),
|
||||||
|
Limit: chatsLimit,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Could not retrieve chats: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
gateway.SendPresence(c.xmpp, c.jid, gateway.SPType("subscribe"))
|
||||||
|
gateway.SendPresence(c.xmpp, c.jid, gateway.SPType("subscribed"))
|
||||||
|
gateway.SendPresence(c.xmpp, c.jid, gateway.SPStatus("Logged in as: "+c.Session.Login))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -179,32 +201,6 @@ func (c *Client) interactor() {
|
||||||
case client.TypeAuthorizationStateWaitPassword:
|
case client.TypeAuthorizationStateWaitPassword:
|
||||||
log.Warn("Waiting for 2FA password...")
|
log.Warn("Waiting for 2FA password...")
|
||||||
gateway.SendMessage(c.jid, "", "Please, enter 2FA passphrase via /password 12345", c.xmpp)
|
gateway.SendMessage(c.jid, "", "Please, enter 2FA passphrase via /password 12345", c.xmpp)
|
||||||
// stage 3: auth completed
|
|
||||||
case client.TypeAuthorizationStateReady:
|
|
||||||
var err error
|
|
||||||
|
|
||||||
c.locks.authorizationReady.Wait()
|
|
||||||
|
|
||||||
log.Warn("Authorization successful!")
|
|
||||||
|
|
||||||
c.me, err = c.client.GetMe()
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Could not retrieve me info")
|
|
||||||
} else if c.Session.Login == "" {
|
|
||||||
c.Session.Login = c.me.PhoneNumber
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = c.client.GetChats(&client.GetChatsRequest{
|
|
||||||
OffsetOrder: client.JsonInt64(math.MaxInt64),
|
|
||||||
Limit: chatsLimit,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Could not retrieve chats: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
gateway.SendPresence(c.xmpp, c.jid, gateway.SPStatus("Logged in "+c.Session.Login))
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue