This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| React.render(<ActivityFeed newActivity=message />, @react('ActivityFeed')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%= react_component('ActivityFeed' ) %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def have_already_answered_the_question?(question) | |
| question.participant_answers.where(participant_id: self.id).count >= 1 | |
| end | |
| def answer_question(question, answer) | |
| participant_answers.build(answer: answer) | |
| save() | |
| answer.correct? | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def handle_question_answer(auth_key, answer_id) | |
| ActiveRecord::Base.connection_pool.with_connection | |
| participant = Participant.find_by(authorization_password: auth_key) | |
| answer = Answer.find(answer_id) | |
| allowed_to_answer_question = ( answer.question.id == current_question.id ) | |
| if allowed_to_answer_question && !participant.have_already_answered_the_question?(answer.question) | |
| participant.answer_question(current_question, answer) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rails g model ParticipantAnswer participant:references answer:references | |
| rake db:migrate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def subscribe_to_client_events | |
| PubnubSingleton.client.subscribe( | |
| channel: client_channel, | |
| auth_key: auth_key, | |
| callback: handle_client_events | |
| ) | |
| end | |
| def handle_client_events | |
| lambda do |envelope| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%= react_component('QuestionDisplay') %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| subscribeToServerChannel: -> | |
| @pubnub.subscribe( | |
| channel: @server_channel | |
| message: @serverCallback | |
| connect: -> | |
| ) | |
| serverCallback: (message, env, ch, timer, magic_ch) => | |
| switch(message.event) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def format(format_name) | |
| format = if format_name == :title_with_answers | |
| h = { title: title } | |
| h[:answers] = answers.to_a.collect{|answer| {id: answer.id, title: answer.title }} | |
| h | |
| else | |
| raise 'Unknown format' | |
| end | |
| format | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def start! | |
| self.current_question_index = 0 | |
| send_current_question() | |
| schedule_switch_to_next_question!(30) | |
| save() | |
| end | |
| def schedule_switch_to_next_question!(secondes) | |
| Rufus::Scheduler.singleton.in "#{secondes}s" do | |
| ActiveRecord::Base.connection_pool.with_connection do |