Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/controllers/calendar_events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def apply_calendar_update!(starts:, ends:, title:)
title: title,
starts_at: starts,
ends_at: ends,
all_day: @event.all_day
all_day: @event.all_day,
time_zone: current_user.timezone
)

if result.nil?
Expand Down
7 changes: 5 additions & 2 deletions app/controllers/timer_sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def create
if current_user.hey_connected? && task
begin
client = HeyClient.new(current_user)
result = client.start_time_track(title: task.title)
result = client.start_time_track
if result.is_a?(Hash) && result["id"].present?
@timer.update_column(:hey_time_track_id, result["id"].to_s)
end
Expand Down Expand Up @@ -47,7 +47,10 @@ def stop_hey_time_track(timer)
return if timer.hey_time_track_id.blank?
return unless current_user.hey_connected?

HeyClient.new(current_user).stop_time_track(timer.hey_time_track_id)
HeyClient.new(current_user).stop_time_track(
timer.hey_time_track_id,
category_title: timer.task_assignment&.title
)
rescue StandardError => e
Rails.logger.warn("HEY time track stop failed: #{e.message}")
end
Expand Down
13 changes: 10 additions & 3 deletions app/jobs/sync_calendar_events_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,17 @@ def upsert_basecamp(user, entry, week_start, week_end)

def sync_hey(user, week_start, week_end)
client = HeyClient.new(user)
events = client.calendar_events(starts_on: week_start.iso8601, ends_on: week_end.iso8601)
if events.is_a?(Array)
dedupe_hey_recordings(events).each { |evt| upsert_hey(user, evt) }
events = []

if client.respond_to?(:calendar_week_events)
week_rows = client.calendar_week_events(week_start.iso8601)
events.concat(week_rows) if week_rows.is_a?(Array)
end

recordings = client.calendar_events(starts_on: week_start.iso8601, ends_on: week_end.iso8601)
events.concat(recordings) if recordings.is_a?(Array)

dedupe_hey_recordings(events).each { |evt| upsert_hey(user, evt) }
reconcile_duplicate_hey_calendar_rows!(user)
true
rescue HeyClient::AuthError => e
Expand Down
9 changes: 7 additions & 2 deletions app/jobs/sync_sometime_todo_to_hey_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ def perform(task_assignment_id)
user = task.user
return unless user.hey_connected?
return unless task.week_bucket == "sometime"
return if task.hey_mirrored_todo_id.present?

week_start = task.week_start_date || user.current_week_start
tz = ActiveSupport::TimeZone[user.timezone] || Time.zone
anchor = tz.local(week_start.year, week_start.month, week_start.day, 12, 0) + 6.days
starts_on = anchor.to_date.iso8601

client = HeyClient.new(user)
result = client.create_todo(title: task.title, starts_at: anchor.to_date.iso8601)
if task.hey_mirrored_todo_id.present?
client.update_todo(task.hey_mirrored_todo_id, title: task.title, starts_at: starts_on)
return
end

result = client.create_todo(title: task.title, starts_at: starts_on)
new_id = extract_todo_id(result)
return if new_id.blank?

Expand Down
34 changes: 25 additions & 9 deletions app/jobs/sync_timebox_to_hey_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ def perform(task_assignment_id)
CalendarEvent.destroy_daybreak_timebox_mirror!(user, task.id)

prev_id = task.hey_calendar_event_id
client.delete_timebox_mirror_remote_id(prev_id) if prev_id.present?

cal_id = client.calendar_id_for_timed_writes
tz_name = user.timezone.presence || "UTC"
zone = ActiveSupport::TimeZone[tz_name] || Time.zone
Expand All @@ -26,13 +24,31 @@ def perform(task_assignment_id)

new_id = nil
if cal_id.present?
new_id = client.create_timed_calendar_event_form(
calendar_id: cal_id,
title: task.title,
local_start: local_start,
local_end: local_end,
time_zone: tz_name
)
if prev_id.present?
patched = client.update_calendar_event(
calendar_id: cal_id,
event_id: prev_id,
title: task.title,
starts_at: local_start,
ends_at: local_end,
all_day: false,
time_zone: tz_name
)
new_id = patched.presence
end

if new_id.blank?
new_id = client.create_timed_calendar_event_form(
calendar_id: cal_id,
title: task.title,
local_start: local_start,
local_end: local_end,
time_zone: tz_name
)
if prev_id.present? && new_id.present? && new_id.to_s != prev_id.to_s
client.delete_timebox_mirror_remote_id(prev_id)
end
end
end

d = task.planned_start_at.in_time_zone(user.timezone).to_date
Expand Down
Loading
Loading