-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add journey sessions and participations
- Loading branch information
1 parent
f2f48e5
commit 808d7db
Showing
41 changed files
with
3,276 additions
and
149 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module Journey | ||
class ApplicationController < ::ApplicationController | ||
# == Filters | ||
before_action :set_participant_id | ||
|
||
private | ||
|
||
# == Helpers | ||
sig { returns(String) } | ||
def participant_id | ||
cookies.signed[:journey_participant_id] or | ||
raise "Missing journey participant ID" | ||
end | ||
|
||
# == Filter Callbacks | ||
sig { void } | ||
def set_participant_id | ||
return if cookies.key?(:journey_participant_id) | ||
cookies.permanent.signed[:journey_participant_id] = SecureRandom.uuid | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
module Journey | ||
class SessionsController < ApplicationController | ||
# == Filters | ||
before_action :set_session_and_participation, only: :show | ||
|
||
# == Actions | ||
def show | ||
session = @session or raise "Missing session" | ||
if @participation | ||
data = query!("JourneySessionPageQuery", { | ||
session_id: session.to_gid.to_s, | ||
}) | ||
render(inertia: "JourneySessionPage", props: { | ||
data:, | ||
}) | ||
else | ||
redirect_to( | ||
journey_root_path, | ||
alert: "You are not a participant in this session.", | ||
) | ||
end | ||
end | ||
|
||
def create | ||
session = T.let(Session.joinable.first || Session.new, Session) | ||
goal = transcribe_goal_recording | ||
session.participations.build( | ||
participant_id:, | ||
goal:, | ||
**participation_params, | ||
) | ||
session.save! | ||
redirect_to(journey_session_path(session)) | ||
rescue => error | ||
redirect_to( | ||
journey_root_path, | ||
alert: "Failed to start session: #{error.message}", | ||
) | ||
end | ||
|
||
private | ||
|
||
# == Helpers | ||
sig { returns(ActionController::Parameters) } | ||
def participation_params | ||
params.require(:participation).permit(:participant_name) | ||
end | ||
|
||
sig { returns(OpenAI::Client) } | ||
def client | ||
@client ||= T.let(OpenAI::Client.new, T.nilable(OpenAI::Client)) | ||
end | ||
|
||
sig { returns(ActionDispatch::Http::UploadedFile) } | ||
def goal_recording | ||
params.fetch(:goal_recording) | ||
end | ||
|
||
sig { returns(String) } | ||
def transcribe_goal_recording | ||
recording = goal_recording | ||
Tempfile.open(["recording", ".webm"], binmode: true) do |file| | ||
file.write(recording.read) | ||
file.flush | ||
file.seek(0) | ||
movie = FFMPEG::Movie.new(file.path) | ||
movie.transcode(file.path, { audio_codec: "webm" }) | ||
response = client.audio.translate( | ||
parameters: { | ||
model: "whisper-1", | ||
file:, | ||
}, | ||
) | ||
response.fetch("text") | ||
end | ||
end | ||
|
||
# == Filter Handlers | ||
sig { void } | ||
def set_session_and_participation | ||
@session = T.let( | ||
Session.friendly.find(params.fetch(:id)), | ||
T.nilable(Session), | ||
) | ||
@participation = T.let( | ||
SessionParticipation.find_by(session: @session, participant_id:), | ||
T.nilable(SessionParticipation), | ||
) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module Queries | ||
class JourneySession < BaseQuery | ||
include AllowsFailedLoads | ||
|
||
# == Type | ||
type Types::JourneySessionType, null: true | ||
|
||
# == Arguments | ||
argument :id, ID, loads: Types::JourneySessionType, as: :session | ||
|
||
# == Resolver | ||
sig do | ||
params(session: T.nilable(::Journey::Session)) | ||
.returns(T.nilable(::Journey::Session)) | ||
end | ||
def resolve(session:) | ||
return unless session | ||
session if allowed_to?(:show?, session) | ||
end | ||
end | ||
end |
This file contains 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
22 changes: 22 additions & 0 deletions
22
app/graphql/subscriptions/journey_session_participation.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module Subscriptions | ||
class JourneySessionParticipation < BaseSubscription | ||
# == Configuration | ||
broadcastable false | ||
|
||
# == Type | ||
type Types::JourneySessionParticipationType, null: true | ||
|
||
# == Arguments | ||
argument :session_id, ID, loads: Types::JourneySessionType | ||
|
||
# == Callback Handlers | ||
sig do | ||
params(session: ::Journey::Session) | ||
.returns(T.nilable(::Journey::SessionParticipation)) | ||
end | ||
def subscribe(session:) = nil | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module Types | ||
class JourneySessionParticipationType < BaseObject | ||
# == Interfaces | ||
implements NodeType | ||
|
||
# == Fields | ||
field :goal, String, null: false | ||
field :participant_is_viewer, Boolean, null: false | ||
field :participant_name, String, null: false | ||
field :session, [JourneySessionType], null: false | ||
|
||
# == Resolvers | ||
sig { returns(T::Boolean) } | ||
def participant_is_viewer | ||
journey_participant_id == object.participant_id | ||
end | ||
|
||
# == Helpers | ||
sig { override.returns(::Journey::SessionParticipation) } | ||
def object = super | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module Types | ||
class JourneySessionType < BaseObject | ||
# == Interfaces | ||
implements NodeType | ||
|
||
# == Fields | ||
field :participations, [JourneySessionParticipationType], null: false | ||
field :started_at, DateTimeType, null: false, method: :created_at | ||
field :url, String, null: false | ||
|
||
# == Resolvers | ||
sig { returns(String) } | ||
def url | ||
journey_session_url(object) | ||
end | ||
|
||
# == Helpers | ||
sig { override.returns(::Journey::Session) } | ||
def object = super | ||
end | ||
end |
This file contains 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
This file contains 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
Oops, something went wrong.