about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-01-25 00:49:08 +0100
committerEugen Rochko <eugen@zeonfederated.com>2017-01-25 01:29:16 +0100
commit999cde94a6a2d67cf36160365378951d3b55b868 (patch)
tree51d86739522f79ee545f7c821507997f0a4914cb /app/services
parentf8da0dd4907490f57cb14b052b767c66c95c4db3 (diff)
Instead of using spoiler boolean and spoiler_text, simply check for non-blank spoiler_text
Federate spoiler_text using warning attribute on <content /> instead of a <category term="spoiler" />
Clean up schema file from accidental development migrations
Diffstat (limited to 'app/services')
-rw-r--r--app/services/fetch_link_card_service.rb4
-rw-r--r--app/services/post_status_service.rb12
-rw-r--r--app/services/process_feed_service.rb5
-rw-r--r--app/services/process_hashtags_service.rb1
4 files changed, 13 insertions, 9 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 ef8aa4a91..91b654603 100644
--- a/app/services/post_status_service.rb
+++ b/app/services/post_status_service.rb
@@ -8,18 +8,16 @@ class PostStatusService < BaseService
   # @param [Hash] options
   # @option [Boolean] :sensitive
   # @option [String] :visibility
-  # @option [Boolean] :spoiler
   # @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],
-                                      spoiler:   options[:spoiler],
-                                      spoiler_text:   options[:spoiler_text],
-                                      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
diff --git a/app/services/process_hashtags_service.rb b/app/services/process_hashtags_service.rb
index 9da7ef74e..617a38159 100644
--- a/app/services/process_hashtags_service.rb
+++ b/app/services/process_hashtags_service.rb
@@ -9,6 +9,5 @@ class ProcessHashtagsService < BaseService
     end
 
     status.update(sensitive: true) if tags.include?('nsfw')
-    status.update(spoiler: true) if tags.include?('spoiler')
   end
 end