Merge branch 'develop' of https://code.gab.com/gab/social/gab-social into feature/removing_ruby_junk

This commit is contained in:
mgabdev
2020-12-09 00:00:35 -05:00
28 changed files with 827 additions and 7 deletions

View File

@@ -0,0 +1,15 @@
# frozen_string_literal: true
module LinkNormalizable
extend ActiveSupport::Concern
included do
before_validation :normalize_link
end
private
def normalize_link
self.link = TagManager.instance.normalize_link(link&.strip)
end
end

26
app/models/link_block.rb Normal file
View File

@@ -0,0 +1,26 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: link_blocks
#
# id :bigint(8) not null, primary key
# link :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
#
class LinkBlock < ApplicationRecord
include LinkNormalizable
validates :link, presence: true, uniqueness: true
def self.block?(text)
return false if text.nil?
return false if text.length < 1
urls = text.scan(FetchLinkCardService::URL_PATTERN).map { |array| Addressable::URI.parse(array[0]).normalize }
url = urls.first
link_for_fetch = TagManager.instance.normalize_link(url)
where(link: link_for_fetch).exists?
end
end

View File

@@ -290,13 +290,13 @@ class Status < ApplicationRecord
end
def as_home_timeline(account)
query = where('updated_at > ?', 5.days.ago)
query = where('created_at > ?', 5.days.ago)
query.where(visibility: [:public, :unlisted, :private])
query.where(account: [account] + account.following).without_replies
end
def as_group_timeline(group)
query = where('updated_at > ?', 5.days.ago)
query = where('created_at > ?', 5.days.ago)
query.where(group: group).without_replies
end