forked from cybrespace/mastodon
		
	Fix public channel
This commit is contained in:
		
							parent
							
								
									a9e40a3d80
								
							
						
					
					
						commit
						abb8f5837e
					
				
					 5 changed files with 49 additions and 45 deletions
				
			
		| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
 | 
					# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
 | 
				
			||||||
class PublicChannel < ApplicationCable::Channel
 | 
					class PublicChannel < ApplicationCable::Channel
 | 
				
			||||||
  def subscribed
 | 
					  def subscribed
 | 
				
			||||||
    stream_from 'timeline:public', lambda do |encoded_message|
 | 
					    stream_from 'timeline:public', lambda { |encoded_message|
 | 
				
			||||||
      message = ActiveSupport::JSON.decode(encoded_message)
 | 
					      message = ActiveSupport::JSON.decode(encoded_message)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      status = Status.find_by(id: message['id'])
 | 
					      status = Status.find_by(id: message['id'])
 | 
				
			||||||
| 
						 | 
					@ -10,7 +10,7 @@ class PublicChannel < ApplicationCable::Channel
 | 
				
			||||||
      message['message'] = FeedManager.instance.inline_render(current_user.account, status)
 | 
					      message['message'] = FeedManager.instance.inline_render(current_user.account, status)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      transmit message
 | 
					      transmit message
 | 
				
			||||||
    end
 | 
					    }
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def unsubscribed
 | 
					  def unsubscribed
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,8 +1,9 @@
 | 
				
			||||||
class FollowSuggestion
 | 
					class FollowSuggestion
 | 
				
			||||||
  def self.get(for_account_id, limit = 10)
 | 
					  class << self
 | 
				
			||||||
    neo = Neography::Rest.new
 | 
					    def get(for_account_id, limit = 10)
 | 
				
			||||||
 | 
					      neo = Neography::Rest.new
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    query = <<END
 | 
					      query = <<END
 | 
				
			||||||
START a=node:account_index(Account={id})
 | 
					START a=node:account_index(Account={id})
 | 
				
			||||||
MATCH (a)-[:follows]->(b)-[:follows]->(c)
 | 
					MATCH (a)-[:follows]->(b)-[:follows]->(c)
 | 
				
			||||||
WHERE a <> c
 | 
					WHERE a <> c
 | 
				
			||||||
| 
						 | 
					@ -12,30 +13,30 @@ ORDER BY count(b) DESC, c.nodeRank DESC
 | 
				
			||||||
LIMIT {limit}
 | 
					LIMIT {limit}
 | 
				
			||||||
END
 | 
					END
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    results = neo.execute_query(query, id: for_account_id, limit: limit)
 | 
					      results = neo.execute_query(query, id: for_account_id, limit: limit)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if results.empty? || results['data'].empty?
 | 
					      if results.empty? || results['data'].empty?
 | 
				
			||||||
      results = fallback(for_account_id, limit)
 | 
					        results = fallback(for_account_id, limit)
 | 
				
			||||||
    elsif results['data'].size < limit
 | 
					      elsif results['data'].size < limit
 | 
				
			||||||
      results['data'] = (results['data'] + fallback(for_account_id, limit - results['data'].size)['data']).uniq
 | 
					        results['data'] = (results['data'] + fallback(for_account_id, limit - results['data'].size)['data']).uniq
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      account_ids  = results['data'].map(&:first)
 | 
				
			||||||
 | 
					      blocked_ids  = Block.where(account_id: for_account_id).pluck(:target_account_id)
 | 
				
			||||||
 | 
					      accounts_map = Account.where(id: account_ids - blocked_ids).with_counters.map { |a| [a.id, a] }.to_h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      account_ids.map { |id| accounts_map[id] }.compact
 | 
				
			||||||
 | 
					    rescue Neography::NeographyError, Excon::Error::Socket => e
 | 
				
			||||||
 | 
					      Rails.logger.error e
 | 
				
			||||||
 | 
					      return []
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    account_ids  = results['data'].map(&:first)
 | 
					    private
 | 
				
			||||||
    blocked_ids  = Block.where(account_id: for_account_id).pluck(:target_account_id)
 | 
					 | 
				
			||||||
    accounts_map = Account.where(id: account_ids - blocked_ids).with_counters.map { |a| [a.id, a] }.to_h
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    account_ids.map { |id| accounts_map[id] }.compact
 | 
					    def fallback(for_account_id, limit)
 | 
				
			||||||
  rescue Neography::NeographyError, Excon::Error::Socket => e
 | 
					      neo = Neography::Rest.new
 | 
				
			||||||
    Rails.logger.error e
 | 
					 | 
				
			||||||
    return []
 | 
					 | 
				
			||||||
  end
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private
 | 
					      query = <<END
 | 
				
			||||||
 | 
					 | 
				
			||||||
  def self.fallback(for_account_id, limit)
 | 
					 | 
				
			||||||
    neo = Neography::Rest.new
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    query = <<END
 | 
					 | 
				
			||||||
START a=node:account_index(Account={id})
 | 
					START a=node:account_index(Account={id})
 | 
				
			||||||
MATCH (b)
 | 
					MATCH (b)
 | 
				
			||||||
WHERE a <> b
 | 
					WHERE a <> b
 | 
				
			||||||
| 
						 | 
					@ -45,6 +46,7 @@ ORDER BY b.nodeRank DESC
 | 
				
			||||||
LIMIT {limit}
 | 
					LIMIT {limit}
 | 
				
			||||||
END
 | 
					END
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    neo.execute_query(query, id: for_account_id, limit: limit)
 | 
					      neo.execute_query(query, id: for_account_id, limit: limit)
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,26 +34,28 @@ class MediaAttachment < ApplicationRecord
 | 
				
			||||||
    image? ? 'image' : 'video'
 | 
					    image? ? 'image' : 'video'
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private
 | 
					  class << self
 | 
				
			||||||
 | 
					    private
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def self.file_styles(f)
 | 
					    def file_styles(f)
 | 
				
			||||||
    if f.instance.image?
 | 
					      if f.instance.image?
 | 
				
			||||||
      {
 | 
					        {
 | 
				
			||||||
        original: '100%',
 | 
					          original: '100%',
 | 
				
			||||||
        small: '510x680>'
 | 
					          small: '510x680>'
 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
        small: {
 | 
					 | 
				
			||||||
          convert_options: {
 | 
					 | 
				
			||||||
            output: {
 | 
					 | 
				
			||||||
              vf: 'scale=\'min(510\, iw):min(680\, ih)\':force_original_aspect_ratio=decrease'
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
          },
 | 
					 | 
				
			||||||
          format: 'png',
 | 
					 | 
				
			||||||
          time: 1
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      else
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          small: {
 | 
				
			||||||
 | 
					            convert_options: {
 | 
				
			||||||
 | 
					              output: {
 | 
				
			||||||
 | 
					                vf: 'scale=\'min(510\, iw):min(680\, ih)\':force_original_aspect_ratio=decrease'
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            format: 'png',
 | 
				
			||||||
 | 
					            time: 1
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
class BlockDomainService < BaseService
 | 
					class BlockDomainService < BaseService
 | 
				
			||||||
  def call(domain)
 | 
					  def call(domain)
 | 
				
			||||||
    block = DomainBlock.find_or_create_by!(domain: domain)
 | 
					    DomainBlock.find_or_create_by!(domain: domain)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Account.where(domain: domain).find_each do |account|
 | 
					    Account.where(domain: domain).find_each do |account|
 | 
				
			||||||
      if account.subscribed?
 | 
					      if account.subscribed?
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,7 +19,7 @@ class FetchRemoteAccountService < BaseService
 | 
				
			||||||
    Rails.logger.debug "Going to webfinger #{username}@#{domain}"
 | 
					    Rails.logger.debug "Going to webfinger #{username}@#{domain}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return FollowRemoteAccountService.new.call("#{username}@#{domain}")
 | 
					    return FollowRemoteAccountService.new.call("#{username}@#{domain}")
 | 
				
			||||||
  rescue TypeError => e
 | 
					  rescue TypeError
 | 
				
			||||||
    Rails.logger.debug "Unparseable URL given: #{url}"
 | 
					    Rails.logger.debug "Unparseable URL given: #{url}"
 | 
				
			||||||
    nil
 | 
					    nil
 | 
				
			||||||
  rescue Nokogiri::XML::XPath::SyntaxError
 | 
					  rescue Nokogiri::XML::XPath::SyntaxError
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue