Now also sending resource to prevent some clients unwanted behaviour

This commit is contained in:
annelin 2020-09-20 14:03:02 +03:00
parent 2c3ab0aceb
commit 474e59b4d8
2 changed files with 4 additions and 3 deletions

View file

@ -70,6 +70,7 @@ class TelegramClient
def initialize(xmpp, jid, **session)
return unless @@config
@logger = Logger.new(STDOUT, level: @@config[:loglevel], progname: 'TelegramClient: %s | %s' % [jid, session[:login]] )
@resource = @@config[:tdlib][:client][:device_model] || 'zhabogram'
@xmpp = xmpp
@jid = jid
@session = session
@ -270,7 +271,7 @@ class TelegramClient
when TD::Types::UserStatus::Offline then show, status = (Time.now.getutc.to_i-status.was_online.to_i<3600) ? :away : :xa,
DateTime.strptime((status.was_online+Time.now.getlocal(@session[:timezone]).utc_offset).to_s,'%s').strftime("Last seen at %H:%M %d/%m/%Y")
end
return @xmpp.send_presence(@jid, id, type, show, status, nil, photo, immed)
return @xmpp.send_presence(@jid, id, type, show, status, nil, photo, @resource, immed)
end
## send outgoing message to telegram user

View file

@ -94,10 +94,10 @@ class XMPPComponent
@component.send(message)
end
def send_presence(to, from=nil, type=nil, show=nil, status=nil, nickname=nil, photo=nil, immed=true)
def send_presence(to, from=nil, type=nil, show=nil, status=nil, nickname=nil, photo=nil, resource=nil, immed=true)
@logger.info "Got presence :%s from %s to %s" % [type, from||@component.jid, to]
presence = Jabber::Presence.new()
presence.from = from.nil? ? @component.jid : "%s@%s" % [from.to_s, @component.jid.to_s] # presence <from>
presence.from = from.nil? ? @component.jid : "%s@%s%s" % [from.to_s, @component.jid.to_s, (resource ? "/"+resource : "")] # presence <from>
presence.to = to # presence <to>
presence.type = type unless type.nil? # pres. type
presence.show = show unless show.nil? # presence <show>