about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
Diffstat (limited to 'app/services')
-rw-r--r--app/services/fetch_link_card_service.rb4
-rw-r--r--app/services/post_status_service.rb10
-rw-r--r--app/services/process_feed_service.rb5
3 files changed, 14 insertions, 5 deletions
diff --git a/app/services/fetch_link_card_service.rb b/app/services/fetch_link_card_service.rb
index 2779b79b5..005e5acea 100644
--- a/app/services/fetch_link_card_service.rb
+++ b/app/services/fetch_link_card_service.rb
@@ -9,7 +9,7 @@ class FetchLinkCardService < BaseService
 
     response = http_client.get(url)
 
-    return if response.code != 200
+    return if response.code != 200 || response.mime_type != 'text/html'
 
     page = Nokogiri::HTML(response.to_s)
     card = PreviewCard.where(status: status).first_or_initialize(status: status, url: url)
@@ -18,6 +18,8 @@ class FetchLinkCardService < BaseService
     card.description = meta_property(page, 'og:description') || meta_property(page, 'description')
     card.image       = URI.parse(meta_property(page, 'og:image')) if meta_property(page, 'og:image')
 
+    return if card.title.blank?
+
     card.save_with_optional_image!
   end
 
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb
index 8765ef5e3..91b654603 100644
--- a/app/services/post_status_service.rb
+++ b/app/services/post_status_service.rb
@@ -8,14 +8,16 @@ class PostStatusService < BaseService
   # @param [Hash] options
   # @option [Boolean] :sensitive
   # @option [String] :visibility
+  # @option [String] :spoiler_text
   # @option [Enumerable] :media_ids Optional array of media IDs to attach
   # @option [Doorkeeper::Application] :application
   # @return [Status]
   def call(account, text, in_reply_to = nil, options = {})
-    status = account.statuses.create!(text:        text,
-                                      thread:      in_reply_to,
-                                      sensitive:   options[:sensitive],
-                                      visibility:  options[:visibility],
+    status = account.statuses.create!(text: text,
+                                      thread: in_reply_to,
+                                      sensitive: options[:sensitive],
+                                      spoiler_text: options[:spoiler_text],
+                                      visibility: options[:visibility],
                                       application: options[:application])
 
     attach_media(status, options[:media_ids])
diff --git a/app/services/process_feed_service.rb b/app/services/process_feed_service.rb
index 84273680d..4576b4321 100644
--- a/app/services/process_feed_service.rb
+++ b/app/services/process_feed_service.rb
@@ -103,6 +103,7 @@ class ProcessFeedService < BaseService
         url: url(entry),
         account: account,
         text: content(entry),
+        spoiler_text: content_warning(entry),
         created_at: published(entry)
       )
 
@@ -223,6 +224,10 @@ class ProcessFeedService < BaseService
       xml.at_xpath('./xmlns:content', xmlns: TagManager::XMLNS).content
     end
 
+    def content_warning(xml = @xml)
+      xml.at_xpath('./xmlns:content', xmlns: TagManager::XMLNS)['warning']
+    end
+
     def published(xml = @xml)
       xml.at_xpath('./xmlns:published', xmlns: TagManager::XMLNS).content
     end