module DiasporaFederation::Federation::DiasporaUrlParser

This module is for parsing and fetching linked entities.

Constants

DIASPORA_URL_REGEX

Regex to find diaspora:// URLs

Public Class Methods

fetch_linked_entities(text) click to toggle source

Parses all diaspora:// URLs from the text and fetches the entities from the remote server if needed. @param [String] sender the diaspora* ID of the sender of the entity @param [String] text text with diaspora:// URLs to fetch

# File lib/diaspora_federation/federation/diaspora_url_parser.rb, line 21
def self.fetch_linked_entities(text)
  text.scan(DIASPORA_URL_REGEX).each do |author, type, guid|
    fetch_entity(author, type, guid)
  end
end

Private Class Methods

fetch_entity(author, type, guid) click to toggle source
# File lib/diaspora_federation/federation/diaspora_url_parser.rb, line 27
                     def self.fetch_entity(author, type, guid)
  class_name = Entity.entity_class(type).to_s.rpartition("::").last
  return if DiasporaFederation.callbacks.trigger(:fetch_related_entity, class_name, guid)

  Fetcher.fetch_public(author, type, guid)
rescue => e # rubocop:disable Style/RescueStandardError
  logger.error "Failed to fetch linked entity #{type}:#{guid}: #{e.class}: #{e.message}"
end