1
0
зеркало из https://github.com/glebtv/telegram-bot.git synced 2026-09-03 09:46:17 +03:00

Fixed controller crashes on unsupported update types

Этот коммит содержится в:
Max Melentiev
2016-05-31 10:38:36 +03:00
родитель a52e7ff31b
Коммит 33a1220c5f
5 изменённых файлов: 45 добавлений и 18 удалений

Просмотреть файл

@@ -17,11 +17,15 @@ module Telegram
protected
def session
@_session ||= SessionHash.new(self.class.session_store, session_key)
@_session ||= begin
key = session_key
key ? SessionHash.new(self.class.session_store, key) : NullSessionHash.new
end
end
def session_key
"#{bot.username}:#{from ? "from:#{from['id']}" : "chat:#{chat['id']}"}"
subject = from || chat
"#{bot.username}:#{subject['id']}" if subject
end
# Rack::Session::Abstract::SessionHash is taken to provide lazy loading.
@@ -59,6 +63,18 @@ module Telegram
end
end
class NullSessionHash < Session::SessionHash
def initialize
@data = {}
@loaded = true
@exists = true
end
alias_method :destroy, :clear
alias_method :load!, :id
alias_method :commit, :id
end
module ConfigMethods
delegate :session_store, to: :config

Просмотреть файл

@@ -27,19 +27,7 @@ module Telegram
# Stubs session.
def session
@_session ||= Testing::SessionHash.new
end
class SessionHash < Session::SessionHash
def initialize
@data = {}
@loaded = true
@exists = true
end
alias_method :destroy, :clear
alias_method :load!, :id
alias_method :commit, :id
@_session ||= Session::NullSessionHash.new
end
end
end