diff options
author | Starfall <root@starfall.blue> | 2020-02-04 17:44:29 -0600 |
---|---|---|
committer | Starfall <root@starfall.blue> | 2020-02-04 17:44:29 -0600 |
commit | 6d24d3bcb84abd04f31da95f97f6d60ef0afdc00 (patch) | |
tree | e7c38251a9e92bdf3a464b4aa7f1880aa5139bf0 /app/lib | |
parent | c0c9529df269816f52915a9802e5e30fbce9576b (diff) | |
parent | 885e9227c6e8e1ce5e4a5625d5126ba76dce2c00 (diff) |
Merge branch 'glitch'
Diffstat (limited to 'app/lib')
-rw-r--r-- | app/lib/activitypub/activity.rb | 2 | ||||
-rw-r--r-- | app/lib/entity_cache.rb | 2 | ||||
-rw-r--r-- | app/lib/feed_manager.rb | 4 | ||||
-rw-r--r-- | app/lib/formatter.rb | 5 | ||||
-rw-r--r-- | app/lib/inline_renderer.rb | 4 | ||||
-rw-r--r-- | app/lib/request.rb | 6 | ||||
-rw-r--r-- | app/lib/sanitize_config.rb | 2 | ||||
-rw-r--r-- | app/lib/search_query_transformer.rb | 2 | ||||
-rw-r--r-- | app/lib/spam_check.rb | 2 |
9 files changed, 20 insertions, 9 deletions
diff --git a/app/lib/activitypub/activity.rb b/app/lib/activitypub/activity.rb index 49b1dc9cd..ee35e1e8d 100644 --- a/app/lib/activitypub/activity.rb +++ b/app/lib/activitypub/activity.rb @@ -21,7 +21,7 @@ class ActivityPub::Activity class << self def factory(json, account, **options) @json = json - klass&.new(json, account, options) + klass&.new(json, account, **options) end private diff --git a/app/lib/entity_cache.rb b/app/lib/entity_cache.rb index 8fff544a0..35a3773d2 100644 --- a/app/lib/entity_cache.rb +++ b/app/lib/entity_cache.rb @@ -8,7 +8,7 @@ class EntityCache MAX_EXPIRATION = 7.days.freeze def mention(username, domain) - Rails.cache.fetch(to_key(:mention, username, domain), expires_in: MAX_EXPIRATION) { Account.select(:username, :domain, :url).find_remote(username, domain) } + Rails.cache.fetch(to_key(:mention, username, domain), expires_in: MAX_EXPIRATION) { Account.select(:id, :username, :domain, :url).find_remote(username, domain) } end def emoji(shortcodes, domain) diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index cdb8383df..3ce182809 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -11,6 +11,10 @@ class FeedManager # Must be <= MAX_ITEMS or the tracking sets will grow forever REBLOG_FALLOFF = 40 + def with_active_accounts(&block) + Account.joins(:user).where('users.current_sign_in_at > ?', User::ACTIVE_DURATION.ago).find_each(&block) + end + def key(type, id, subtype = nil) return "feed:#{type}:#{id}" unless subtype diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb index 9159db2a1..f1a751f84 100644 --- a/app/lib/formatter.rb +++ b/app/lib/formatter.rb @@ -308,8 +308,9 @@ class Formatter end standard = Extractor.extract_entities_with_indices(text, options) + extra = Extractor.extract_extra_uris_with_indices(text, options) - Extractor.remove_overlapping_entities(special + standard) + Extractor.remove_overlapping_entities(special + standard + extra) end def html_friendly_extractor(html, options = {}) @@ -370,7 +371,7 @@ class Formatter def link_html(url) url = Addressable::URI.parse(url).to_s - prefix = url.match(/\Ahttps?:\/\/(www\.)?/).to_s + prefix = url.match(/\A(https?:\/\/(www\.)?|xmpp:)/).to_s text = url[prefix.length, 30] suffix = url[prefix.length + 30..-1] cutoff = url[prefix.length..-1].length > 30 diff --git a/app/lib/inline_renderer.rb b/app/lib/inline_renderer.rb index 761a8822d..27e334a4d 100644 --- a/app/lib/inline_renderer.rb +++ b/app/lib/inline_renderer.rb @@ -15,6 +15,10 @@ class InlineRenderer serializer = REST::NotificationSerializer when :conversation serializer = REST::ConversationSerializer + when :announcement + serializer = REST::AnnouncementSerializer + when :reaction + serializer = REST::ReactionSerializer else return end diff --git a/app/lib/request.rb b/app/lib/request.rb index 42ccc6513..c476e7785 100644 --- a/app/lib/request.rb +++ b/app/lib/request.rb @@ -59,7 +59,7 @@ class Request begin response = http_client.public_send(@verb, @url.to_s, @options.merge(headers: headers)) rescue => e - raise e.class, "#{e.message} on #{@url}", e.backtrace + raise e.class, "#{e.message} on #{@url}", e.backtrace[0] end begin @@ -73,6 +73,8 @@ class Request response.body_with_limit if http_client.persistent? yield response if block_given? + rescue => e + raise e.class, e.message, e.backtrace[0] ensure http_client.close unless http_client.persistent? end @@ -94,7 +96,7 @@ class Request end def http_client - HTTP.use(:auto_inflate).timeout(:per_operation, TIMEOUT.dup).follow(max_hops: 2) + HTTP.use(:auto_inflate).timeout(TIMEOUT.dup).follow(max_hops: 2) end end diff --git a/app/lib/sanitize_config.rb b/app/lib/sanitize_config.rb index 9f5bf0125..2b5d554b5 100644 --- a/app/lib/sanitize_config.rb +++ b/app/lib/sanitize_config.rb @@ -2,7 +2,7 @@ class Sanitize module Config - HTTP_PROTOCOLS ||= ['http', 'https', 'dat', 'dweb', 'ipfs', 'ipns', 'ssb', 'gopher', :relative].freeze + HTTP_PROTOCOLS ||= ['http', 'https', 'dat', 'dweb', 'ipfs', 'ipns', 'ssb', 'gopher', 'xmpp', 'magnet', :relative].freeze CLASS_WHITELIST_TRANSFORMER = lambda do |env| node = env[:node] diff --git a/app/lib/search_query_transformer.rb b/app/lib/search_query_transformer.rb index 6a299f59d..e07ebfffe 100644 --- a/app/lib/search_query_transformer.rb +++ b/app/lib/search_query_transformer.rb @@ -78,7 +78,7 @@ class SearchQueryTransformer < Parslet::Transform elsif clause[:shortcode] TermClause.new(prefix, operator, ":#{clause[:term]}:") elsif clause[:phrase] - PhraseClause.new(prefix, operator, clause[:phrase].map { |p| p[:term].to_s }.join(' ')) + PhraseClause.new(prefix, operator, clause[:phrase].is_a?(Array) ? clause[:phrase].map { |p| p[:term].to_s }.join(' ') : clause[:phrase].to_s) else raise "Unexpected clause type: #{clause}" end diff --git a/app/lib/spam_check.rb b/app/lib/spam_check.rb index 5b40514fd..652d03615 100644 --- a/app/lib/spam_check.rb +++ b/app/lib/spam_check.rb @@ -143,7 +143,7 @@ class SpamCheck end def trusted? - @account.trust_level > Account::TRUST_LEVELS[:untrusted] + @account.trust_level > Account::TRUST_LEVELS[:untrusted] || (@account.local? && @account.user_staff?) end def no_unsolicited_mentions? |