Bump version to 2.1
[FIX] correct presence handling when we have several priorities
This commit is contained in:
parent
82aa27558b
commit
5014133cc0
|
@ -53,11 +53,12 @@ class TelegramClient
|
|||
@jid = jid
|
||||
@session = session
|
||||
@cache = {chats: {nil => []}, users: {}}
|
||||
@resources = []
|
||||
end
|
||||
|
||||
## connect telegram client
|
||||
def connect()
|
||||
return if self.online? # already connected.
|
||||
def connect(resource=nil)
|
||||
return self.refresh(resource) if self.online? # already connected
|
||||
@logger.warn 'Connecting to Telegram network..'
|
||||
@telegram = TD::Client.new(database_directory: 'sessions/' + @jid, files_directory: 'sessions/' + @jid + '/files/')
|
||||
@telegram.on(TD::Types::Update::AuthorizationState) do |u| @logger.debug(u); self.update_authorizationstate(u) end
|
||||
|
@ -69,22 +70,37 @@ class TelegramClient
|
|||
@telegram.on(TD::Types::Update::DeleteMessages) do |u| @logger.debug(u); self.update_deletemessages(u) end
|
||||
@telegram.on(TD::Types::Update::File) do |u| @logger.debug(u); self.update_file(u) end
|
||||
@telegram.connect()
|
||||
@resources << resource
|
||||
end
|
||||
|
||||
## disconnect telegram client
|
||||
def disconnect()
|
||||
return unless self.online? # already disconnected
|
||||
def disconnect(resource=nil)
|
||||
@resources.delete resource
|
||||
return if @resources.count > 0 or not self.online?
|
||||
@logger.warn 'Disconnecting from Telegram network..'
|
||||
@cache[:chats].each_key do |chat| @xmpp.send_presence(@jid, chat, :unavailable) end # we're offline (unsubscribe if logout)
|
||||
@telegram.dispose()
|
||||
@telegram = nil
|
||||
end
|
||||
|
||||
## refresh roster
|
||||
def refresh(resource=nil)
|
||||
return if @resources.include? resource
|
||||
@logger.warn 'Refreshing roster for resource %s' % resource
|
||||
@cache[:chats].each_key do |chat| self.process_status_update(chat) if chat; end
|
||||
@resources << resource
|
||||
end
|
||||
|
||||
## online?
|
||||
def online?
|
||||
@telegram and @telegram.alive?
|
||||
@telegram and @telegram.alive?
|
||||
end
|
||||
|
||||
def authorized?
|
||||
@telegram and @telegram.alive and @state == TD::Types::AuthorizationState::Ready
|
||||
end
|
||||
|
||||
|
||||
#########################################################################
|
||||
# telegram updates handlers #############################################
|
||||
#########################################################################
|
||||
|
|
|
@ -52,8 +52,8 @@ class XMPPComponent
|
|||
@logger.debug presence.to_s
|
||||
@sessions[presence.from.bare.to_s] = TelegramClient.new(self, presence.from.bare.to_s) unless @sessions.key? presence.from.bare.to_s # create session
|
||||
@sessions[presence.from.bare.to_s] = nil if presence.type == :unsubscribed # destroy session
|
||||
@sessions[presence.from.bare.to_s].disconnect() if presence.type == :unavailable or presence.type == :error # go offline
|
||||
@sessions[presence.from.bare.to_s].connect() if presence.type == :subscribe or not presence.type # go online
|
||||
@sessions[presence.from.bare.to_s].disconnect(presence.from.resource) if presence.type == :unavailable or presence.type == :error # go offline
|
||||
@sessions[presence.from.bare.to_s].connect(presence.from.resource) if presence.type == :subscribe or not presence.type # go online
|
||||
end
|
||||
|
||||
def handle_message(message)
|
||||
|
|
Reference in a new issue