From eca1bfcb8f9d690948fb64ac7af6169da92f91ad Mon Sep 17 00:00:00 2001 From: annelin Date: Sun, 14 Jul 2019 10:39:36 +0300 Subject: [PATCH] [+] now asking subscription only after explicit request (/add) or after incoming message, I hope it will help --- inc/telegramclient.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/inc/telegramclient.rb b/inc/telegramclient.rb index bb20807..74a9d3d 100644 --- a/inc/telegramclient.rb +++ b/inc/telegramclient.rb @@ -37,7 +37,7 @@ class TelegramClient @me = nil # self telegram profile @online = nil # we do not know @auth_state = 'nil' # too. - @cache = {chats: {}, users: {}, photos: {}} # cache + @cache = {chats: {}, users: {}, photos: {}, subscribed: []} # cache end # initialize and connect telegram client # @@ -118,6 +118,9 @@ class TelegramClient @logger.debug update.message.to_json @logger.info 'New message from Telegram chat %s' % update.message.chat_id + # add to contact list + self.process_chat_info(update.message.chat_id, true) if not @cache[:subscribed].include? update.message.chat_id + # message content prefix = [] content = update.message.content @@ -360,12 +363,15 @@ class TelegramClient end # update users information and save it to cache # - def process_chat_info(chat_id, subscription = true) + def process_chat_info(chat_id, subscription = false) @logger.debug 'Updating chat id %s..' % chat_id.to_s @client.get_chat(chat_id).then { |chat| @cache[:chats][chat_id] = chat # cache chat @client.download_file(chat.photo.small.id).then{|f| @cache[:photos][chat_id] = f}.wait if chat.photo # download userpic - @xmpp.presence(@jid, chat_id.to_s, :subscribe, nil, nil, chat.title.to_s) if subscription # send subscription request + if subscription then # send subscription request + @xmpp.presence(@jid, chat_id.to_s, :subscribe, nil, nil, chat.title.to_s) + @cache[:subscribed] << chat_id + end self.process_status_update(chat_id, chat.title.to_s, true) if chat.id < 0 # groups presence }.wait return @cache[:chats][chat_id] if @cache[:chats].key? chat_id