Fix subscriptions after logging in

This commit is contained in:
Bohdan Horbeshko 2021-12-31 18:34:04 -05:00
parent d36f4449c9
commit 462a537021

View file

@ -117,9 +117,31 @@ func (c *Client) Connect() error {
c.client = tdlibClient
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()
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
}
@ -179,32 +201,6 @@ func (c *Client) interactor() {
case client.TypeAuthorizationStateWaitPassword:
log.Warn("Waiting for 2FA password...")
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
}
}
}