Skip to content

Commit

Permalink
Merge pull request #708 from ChicagoWorldcon/PLAN-709-diff-reports
Browse files Browse the repository at this point in the history
fix missing tokens after resync
  • Loading branch information
Gailbear authored Aug 26, 2022
2 parents 93e865c + 17d9850 commit a77b13c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
24 changes: 19 additions & 5 deletions app/services/airmeet_api_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def self.person_to_airmeet(person, dont_send = false)
person.update({integrations: person.integrations.merge({airmeet: {speaker_email: speaker_email, synced: newly_created || (person.integrations["airmeet"] || {})["synced"], data: newly_created ? args : (person.integrations["airmeet"] || {})["data"], synced_at: newly_created ? Time.now.iso8601 : (person.integrations["airmeet"] || {})["synced_at"] }})})
end

def self.session_to_airmeet(session)
def self.session_to_airmeet(session, dont_send = false)
args = {sessionTitle: "#{session.title} - #{session.format.name}",
sessionSummary: ActionView::Base.full_sanitizer.sanitize(session.description),
sessionDuration: session.duration,
Expand All @@ -122,12 +122,18 @@ def self.session_to_airmeet(session)
args[:sessionTitle] = "Never Give Up, Never Surrender! The Art of Eric Wilkerson: Scifi Illustrator and Visual Afrofuturist"
end
puts args
result = create_session(args);
if dont_send
result = args
else
result = create_session(args);
end
puts result
session.update({integrations: session.integrations.merge({airmeet: {session_id: result["uid"] || (session.integrations["airmeet"] || {})["session_id"], synced: !!result["uid"] || (session.integrations["airmeet"] || {})["synced"] , synced_at: !!result["uid"] ? Time.now() : (session.integrations["airmeet"] || {})["synced_at"] , data: args}})})
if session.environment == "virtual"
success = result["uid"] || dont_send
old_airmeet_data = session.integrations["airmeet"] || {}
session.update({integrations: session.integrations.merge({airmeet: {session_id: result["uid"] || old_airmeet_data["session_id"], synced: success || old_airmeet_data["synced"] , synced_at: success ? Time.now() : old_airmeet_data["synced_at"] , data: success ? args : old_airmeet_data["data"]}})})
if session.environment == "virtual" && !dont_send
people_tokens = (result["token"] || []).inject({}) {|p,c| p[c["email"]] = c["token"]; p}
participants.each { |p| p.update({integrations: p.integrations.merge({airmeet: (p.integrations["airmeet"] || {}).merge({token: people_tokens[(p.integrations["airmeet"] || {})["speaker_email"]]})})})}
participants.each { |p| p.update({integrations: p.integrations.merge({airmeet: (p.integrations["airmeet"] || {}).merge({token: people_tokens[(p.integrations["airmeet"] || {})["speaker_email"]] || (p.integrations["airmeet"] || {})["token"]})})})}
end
end

Expand Down Expand Up @@ -159,6 +165,14 @@ def self.sync_to_airmeet
puts "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA IT WORKED"
end

def self.clear_participant_data
Person.where.not(integrations: {}).update_all(integrations: {})
end

def self.clear_session_data
PublishedSession.where.not(integrations: {}).update_all(integrations: {})
end

class Airmeet
include HTTParty
base_uri "https://api-gateway.airmeet.com/prod"
Expand Down
5 changes: 5 additions & 0 deletions lib/tasks/chicon_airmeet.rake
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,10 @@ namespace :chicon do
task sync_airmeet: :environment do
AirmeetApiService.sync_to_airmeet
end

task clear_airmeet: :environment do
AirmeetApiService.clear_participant_data
AirmeetApiService.clear_session_data
end
end

0 comments on commit a77b13c

Please sign in to comment.