feat: Update last_snoozed_at after the un-snooze notification (#8943)
This commit is contained in:
@@ -54,7 +54,8 @@ class Api::V1::Accounts::NotificationsController < Api::V1::Accounts::BaseContro
|
|||||||
end
|
end
|
||||||
|
|
||||||
def snooze
|
def snooze
|
||||||
@notification.update(snoozed_until: parse_date_time(params[:snoozed_until].to_s)) if params[:snoozed_until]
|
updated_meta = (@notification.meta || {}).merge('last_snoozed_at' => nil)
|
||||||
|
@notification.update(snoozed_until: parse_date_time(params[:snoozed_until].to_s), meta: updated_meta) if params[:snoozed_until]
|
||||||
render json: @notification
|
render json: @notification
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,24 @@ class Notification::ReopenSnoozedNotificationsJob < ApplicationJob
|
|||||||
queue_as :low
|
queue_as :low
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
# rubocop:disable Rails/SkipsModelValidations
|
Notification.where(snoozed_until: 3.days.ago..Time.current).find_in_batches(batch_size: 100) do |notifications_batch|
|
||||||
Notification.where(snoozed_until: 3.days.ago..Time.current)
|
notifications_batch.each do |notification|
|
||||||
.update_all(snoozed_until: nil, updated_at: Time.current, last_activity_at: Time.current, read_at: nil)
|
update_notification(notification)
|
||||||
# rubocop:enable Rails/SkipsModelValidations
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def update_notification(notification)
|
||||||
|
updated_meta = (notification.meta || {}).merge('last_snoozed_at' => notification.snoozed_until)
|
||||||
|
|
||||||
|
notification.update!(
|
||||||
|
snoozed_until: nil,
|
||||||
|
updated_at: Time.current,
|
||||||
|
last_activity_at: Time.current,
|
||||||
|
meta: updated_meta,
|
||||||
|
read_at: nil
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ class Notification < ApplicationRecord
|
|||||||
created_at: created_at.to_i,
|
created_at: created_at.to_i,
|
||||||
last_activity_at: last_activity_at.to_i,
|
last_activity_at: last_activity_at.to_i,
|
||||||
snoozed_until: snoozed_until,
|
snoozed_until: snoozed_until,
|
||||||
|
meta: meta,
|
||||||
account_id: account_id
|
account_id: account_id
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ json.data do
|
|||||||
json.created_at notification.created_at.to_i
|
json.created_at notification.created_at.to_i
|
||||||
json.last_activity_at notification.last_activity_at.to_i
|
json.last_activity_at notification.last_activity_at.to_i
|
||||||
json.snoozed_until notification.snoozed_until
|
json.snoozed_until notification.snoozed_until
|
||||||
|
json.meta notification.meta
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -179,6 +179,7 @@ RSpec.describe 'Notifications API', type: :request do
|
|||||||
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
expect(notification.reload.snoozed_until).not_to eq('')
|
expect(notification.reload.snoozed_until).not_to eq('')
|
||||||
|
expect(notification.reload.meta['last_snoozed_at']).to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,10 +14,13 @@ RSpec.describe Notification::ReopenSnoozedNotificationsJob do
|
|||||||
it 'reopens snoozed notifications whose snooze until has passed' do
|
it 'reopens snoozed notifications whose snooze until has passed' do
|
||||||
described_class.perform_now
|
described_class.perform_now
|
||||||
|
|
||||||
|
snoozed_until = snoozed_till_5_minutes_ago.reload.snoozed_until
|
||||||
|
|
||||||
expect(snoozed_till_5_minutes_ago.reload.snoozed_until).to be_nil
|
expect(snoozed_till_5_minutes_ago.reload.snoozed_until).to be_nil
|
||||||
expect(snoozed_till_tomorrow.reload.snoozed_until.to_date).to eq 1.day.from_now.to_date
|
expect(snoozed_till_tomorrow.reload.snoozed_until.to_date).to eq 1.day.from_now.to_date
|
||||||
expect(snoozed_indefinitely.reload.snoozed_until).to be_nil
|
expect(snoozed_indefinitely.reload.snoozed_until).to be_nil
|
||||||
expect(snoozed_indefinitely.reload.read_at).to be_nil
|
expect(snoozed_indefinitely.reload.read_at).to be_nil
|
||||||
|
expect(snoozed_until).to eq(snoozed_till_5_minutes_ago.reload.meta['snoozed_until'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user