mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-23 16:44:04 -05:00
Fix some nil errors (#3338)
* Fix nil input not handled well in AuthorExtractor concern * Fix hard error in ProcessFeedService when replied-to status has been deleted * Fix nil errors in ProcessInteractionService when favourited status cannot be found
This commit is contained in:
parent
bd21afb5ed
commit
44cb08297c
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
module AuthorExtractor
|
module AuthorExtractor
|
||||||
def author_from_xml(xml)
|
def author_from_xml(xml)
|
||||||
|
return nil if xml.nil?
|
||||||
|
|
||||||
# Try <email> for acct
|
# Try <email> for acct
|
||||||
acct = xml.at_xpath('./xmlns:author/xmlns:email', xmlns: TagManager::XMLNS)&.content
|
acct = xml.at_xpath('./xmlns:author/xmlns:email', xmlns: TagManager::XMLNS)&.content
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ class ProcessFeedService < BaseService
|
|||||||
def find_status(uri)
|
def find_status(uri)
|
||||||
if TagManager.instance.local_id?(uri)
|
if TagManager.instance.local_id?(uri)
|
||||||
local_id = TagManager.instance.unique_tag_to_local_id(uri, 'Status')
|
local_id = TagManager.instance.unique_tag_to_local_id(uri, 'Status')
|
||||||
return Status.find(local_id)
|
return Status.find_by(id: local_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
Status.find_by(uri: uri)
|
Status.find_by(uri: uri)
|
||||||
|
@ -108,12 +108,18 @@ class ProcessInteractionService < BaseService
|
|||||||
|
|
||||||
def favourite!(xml, from_account)
|
def favourite!(xml, from_account)
|
||||||
current_status = status(xml)
|
current_status = status(xml)
|
||||||
|
|
||||||
|
return if current_status.nil?
|
||||||
|
|
||||||
favourite = current_status.favourites.where(account: from_account).first_or_create!(account: from_account)
|
favourite = current_status.favourites.where(account: from_account).first_or_create!(account: from_account)
|
||||||
NotifyService.new.call(current_status.account, favourite)
|
NotifyService.new.call(current_status.account, favourite)
|
||||||
end
|
end
|
||||||
|
|
||||||
def unfavourite!(xml, from_account)
|
def unfavourite!(xml, from_account)
|
||||||
current_status = status(xml)
|
current_status = status(xml)
|
||||||
|
|
||||||
|
return if current_status.nil?
|
||||||
|
|
||||||
favourite = current_status.favourites.where(account: from_account).first
|
favourite = current_status.favourites.where(account: from_account).first
|
||||||
favourite&.destroy
|
favourite&.destroy
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user