trabajo-afectivo/lib/push_messages.rb

36 lines
663 B
Ruby
Raw Normal View History

module PushMessages
def self.enabled?
return true if Thread.current[:push_messages].class == Array
false
end
def self.init
Thread.current[:push_messages] = []
end
def self.send(data)
if !PushMessages.enabled?
Sessions.broadcast(
data[:message],
data[:type],
data[:current_user_id],
)
return true
end
Thread.current[:push_messages].push data
end
def self.finish
Thread.current[:push_messages].each { |data|
Sessions.broadcast(
data[:message],
data[:type],
data[:current_user_id],
)
}
Thread.current[:push_messages] = nil
end
end