Merge remote-tracking branch 'origin/kb_development' into kb_migration
This commit is contained in:
commit
0071b15fa3
18 changed files with 455 additions and 2 deletions
|
@ -26,6 +26,7 @@ class DeleteAccountService < BaseService
|
|||
passive_relationships
|
||||
report_notes
|
||||
scheduled_statuses
|
||||
scheduled_expiration_statuses
|
||||
status_pins
|
||||
).freeze
|
||||
|
||||
|
@ -51,6 +52,7 @@ class DeleteAccountService < BaseService
|
|||
notifications
|
||||
owned_lists
|
||||
scheduled_statuses
|
||||
scheduled_expiration_statuses
|
||||
status_pins
|
||||
)
|
||||
|
||||
|
|
|
@ -76,6 +76,8 @@ class PostStatusService < BaseService
|
|||
@status = @account.statuses.new(status_attributes)
|
||||
process_mentions_service.call(@status, save_records: false)
|
||||
safeguard_mentions!(@status)
|
||||
|
||||
UpdateStatusExpirationService.new.call(@status)
|
||||
|
||||
# The following transaction block is needed to wrap the UPDATEs to
|
||||
# the media attachments when the status is created
|
||||
|
|
20
app/services/update_status_expiration_service.rb
Normal file
20
app/services/update_status_expiration_service.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class UpdateStatusExpirationService < BaseService
|
||||
SCAN_EXPIRATION_RE = /#exp((\d{1,4}\.\d{1,2}|\d{1,4}))(d|h|m|s)/
|
||||
|
||||
def call(status)
|
||||
existing_expiration = ScheduledExpirationStatus.find_by(status: status)
|
||||
existing_expiration.destroy! if existing_expiration
|
||||
|
||||
expiration = status.text.scan(SCAN_EXPIRATION_RE).first
|
||||
return if !expiration
|
||||
|
||||
expiration_num = expiration[1].to_f
|
||||
expiration_option = expiration[2]
|
||||
base_time = status.created_at || Time.now.utc
|
||||
|
||||
expired_at = base_time + (expiration_option == 'd' ? expiration_num.days : expiration_option == 'h' ? expiration_num.hours : expiration_option == 's' ? expiration_num.seconds : expiration_num.minutes)
|
||||
ScheduledExpirationStatus.create!(account: status.account, status: status, scheduled_at: expired_at)
|
||||
end
|
||||
end
|
|
@ -117,11 +117,17 @@ class UpdateStatusService < BaseService
|
|||
|
||||
# We raise here to rollback the entire transaction
|
||||
raise NoChangesSubmittedError unless significant_changes?
|
||||
|
||||
update_expiration!
|
||||
|
||||
@status.edited_at = Time.now.utc
|
||||
@status.save!
|
||||
end
|
||||
|
||||
def update_expiration!
|
||||
UpdateStatusExpirationService.new.call(@status)
|
||||
end
|
||||
|
||||
def reset_preview_card!
|
||||
return unless @status.text_previously_changed?
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue