From 3918686f211a3eac60916a81423c64240ad1988a Mon Sep 17 00:00:00 2001 From: bodqhrohro Date: Sun, 15 Dec 2019 21:30:54 +0200 Subject: [PATCH] Connect on probe presence (for clients that do not send online presence first) --- telegram/connect.go | 5 ++++- xmpp/handlers.go | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/telegram/connect.go b/telegram/connect.go index b19e4ed..8988528 100644 --- a/telegram/connect.go +++ b/telegram/connect.go @@ -87,6 +87,9 @@ func (stateHandler *clientAuthorizer) Close() { // Connect starts TDlib connection func (c *Client) Connect() error { + // avoid conflict if another authorization is pending already + c.locks.authorizationReady.Wait() + if c.Online() { return nil } @@ -113,8 +116,8 @@ func (c *Client) Connect() error { } c.client = tdlibClient - c.locks.authorizationReady.Done() c.listener = tdlibClient.GetListener() + c.locks.authorizationReady.Done() go c.updateHandler() diff --git a/xmpp/handlers.go b/xmpp/handlers.go index 31c2b27..971ac86 100644 --- a/xmpp/handlers.go +++ b/xmpp/handlers.go @@ -236,8 +236,8 @@ func handlePresence(s xmpp.Sender, p stanza.Presence) { delete(sessions, bareFromJid) case "unavailable", "error": session.Disconnect() - case "", "online": - // due to the weird implentation of go-tdlib wrapper, it won't + case "probe", "", "online": + // due to the weird implementation of go-tdlib wrapper, it won't // return the client instance until successful authorization go func() { err = session.Connect()