Relogin fix
This commit is contained in:
parent
05a9aca537
commit
18b5bc0935
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@ config.yml
|
||||||
telegabber
|
telegabber
|
||||||
sessions/
|
sessions/
|
||||||
session.dat
|
session.dat
|
||||||
|
session.dat.new
|
||||||
|
|
|
@ -42,7 +42,16 @@ var sessionDB *SessionsYamlDB
|
||||||
|
|
||||||
// SessionMarshaller implementation for YamlDB
|
// SessionMarshaller implementation for YamlDB
|
||||||
func SessionMarshaller() ([]byte, error) {
|
func SessionMarshaller() ([]byte, error) {
|
||||||
return yaml.Marshal(sessionDB.Data)
|
cleanedMap := SessionsMap{}
|
||||||
|
emptySessionsMap(&cleanedMap)
|
||||||
|
|
||||||
|
for jid, session := range sessionDB.Data.Sessions {
|
||||||
|
if session.Login != "" {
|
||||||
|
cleanedMap.Sessions[jid] = session
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return yaml.Marshal(&cleanedMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadSessions restores TDlib sessions from the previous run
|
// LoadSessions restores TDlib sessions from the previous run
|
||||||
|
|
|
@ -159,8 +159,12 @@ func (c *Client) ProcessTransportCommand(cmdline string) string {
|
||||||
cmd, args := parseCommand(cmdline)
|
cmd, args := parseCommand(cmdline)
|
||||||
switch cmd {
|
switch cmd {
|
||||||
case "login", "code", "password":
|
case "login", "code", "password":
|
||||||
if cmd == "login" && c.Session.Login != "" {
|
if cmd == "login" {
|
||||||
return ""
|
if c.Session.Login != "" {
|
||||||
|
return ""
|
||||||
|
} else if !c.Online() {
|
||||||
|
c.Connect()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
|
@ -184,15 +188,16 @@ func (c *Client) ProcessTransportCommand(cmdline string) string {
|
||||||
}
|
}
|
||||||
// sign out
|
// sign out
|
||||||
case "logout":
|
case "logout":
|
||||||
_, err := c.client.LogOut()
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "Logout error").Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
for id := range c.cache.chats {
|
for id := range c.cache.chats {
|
||||||
c.unsubscribe(id)
|
c.unsubscribe(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err := c.client.LogOut()
|
||||||
|
if err != nil {
|
||||||
|
c.forceClose()
|
||||||
|
return errors.Wrap(err, "Logout error").Error()
|
||||||
|
}
|
||||||
|
|
||||||
c.Session.Login = ""
|
c.Session.Login = ""
|
||||||
// set @username
|
// set @username
|
||||||
case "setusername":
|
case "setusername":
|
||||||
|
|
|
@ -207,6 +207,7 @@ func (c *Client) interactor() {
|
||||||
|
|
||||||
func (c *Client) forceClose() {
|
func (c *Client) forceClose() {
|
||||||
c.listener.Close()
|
c.listener.Close()
|
||||||
|
c.authorizer = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Online checks if the updates listener is alive
|
// Online checks if the updates listener is alive
|
||||||
|
|
Loading…
Reference in a new issue