2016-02-29 18:42:08 +00:00
|
|
|
module AtomBuilderHelper
|
2016-02-22 15:00:20 +00:00
|
|
|
def stream_updated_at
|
2016-02-28 20:22:56 +00:00
|
|
|
@account.stream_entries.last ? (@account.updated_at > @account.stream_entries.last.created_at ? @account.updated_at : @account.stream_entries.last.created_at) : @account.updated_at
|
2016-02-23 12:08:01 +00:00
|
|
|
end
|
|
|
|
|
2016-03-20 12:50:22 +00:00
|
|
|
def entry(xml, is_root = false, &block)
|
2016-02-23 12:08:01 +00:00
|
|
|
if is_root
|
|
|
|
root_tag(xml, :entry, &block)
|
|
|
|
else
|
2016-02-24 23:22:46 +00:00
|
|
|
xml.entry(&block)
|
2016-02-23 12:08:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def feed(xml, &block)
|
|
|
|
root_tag(xml, :feed, &block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def unique_id(xml, date, id, type)
|
2016-09-09 19:04:34 +01:00
|
|
|
xml.id_ TagManager.instance.unique_tag(date, id, type)
|
2016-02-23 12:08:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def simple_id(xml, id)
|
|
|
|
xml.id_ id
|
|
|
|
end
|
|
|
|
|
|
|
|
def published_at(xml, date)
|
|
|
|
xml.published date.iso8601
|
|
|
|
end
|
|
|
|
|
|
|
|
def updated_at(xml, date)
|
|
|
|
xml.updated date.iso8601
|
|
|
|
end
|
|
|
|
|
|
|
|
def verb(xml, verb)
|
|
|
|
xml['activity'].send('verb', "http://activitystrea.ms/schema/1.0/#{verb}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def content(xml, content)
|
2016-03-22 19:20:37 +00:00
|
|
|
xml.content({ type: 'html' }, content) unless content.blank?
|
2016-02-23 12:08:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def title(xml, title)
|
2016-03-21 09:31:20 +00:00
|
|
|
xml.title strip_tags(title || '').truncate(80)
|
2016-02-23 12:08:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def author(xml, &block)
|
2016-02-24 23:22:46 +00:00
|
|
|
xml.author(&block)
|
2016-02-23 12:08:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def target(xml, &block)
|
2016-02-24 23:22:46 +00:00
|
|
|
xml['activity'].object(&block)
|
2016-02-23 12:08:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def object_type(xml, type)
|
|
|
|
xml['activity'].send('object-type', "http://activitystrea.ms/schema/1.0/#{type}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def uri(xml, uri)
|
|
|
|
xml.uri uri
|
|
|
|
end
|
|
|
|
|
|
|
|
def name(xml, name)
|
|
|
|
xml.name name
|
|
|
|
end
|
|
|
|
|
|
|
|
def summary(xml, summary)
|
2016-03-22 19:20:37 +00:00
|
|
|
xml.summary(summary) unless summary.blank?
|
2016-02-23 12:08:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def subtitle(xml, subtitle)
|
2016-03-22 19:20:37 +00:00
|
|
|
xml.subtitle(subtitle) unless subtitle.blank?
|
2016-02-23 12:08:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def link_alternate(xml, url)
|
|
|
|
xml.link(rel: 'alternate', type: 'text/html', href: url)
|
|
|
|
end
|
|
|
|
|
|
|
|
def link_self(xml, url)
|
|
|
|
xml.link(rel: 'self', type: 'application/atom+xml', href: url)
|
|
|
|
end
|
|
|
|
|
|
|
|
def link_hub(xml, url)
|
|
|
|
xml.link(rel: 'hub', href: url)
|
|
|
|
end
|
|
|
|
|
|
|
|
def link_salmon(xml, url)
|
|
|
|
xml.link(rel: 'salmon', href: url)
|
|
|
|
end
|
|
|
|
|
|
|
|
def portable_contact(xml, account)
|
|
|
|
xml['poco'].preferredUsername account.username
|
2016-03-22 19:20:37 +00:00
|
|
|
xml['poco'].displayName(account.display_name) unless account.display_name.blank?
|
|
|
|
xml['poco'].note(account.note) unless account.note.blank?
|
2016-02-23 12:08:01 +00:00
|
|
|
end
|
|
|
|
|
2016-02-23 18:17:37 +00:00
|
|
|
def in_reply_to(xml, uri, url)
|
|
|
|
xml['thr'].send('in-reply-to', { ref: uri, href: url, type: 'text/html' })
|
|
|
|
end
|
|
|
|
|
|
|
|
def link_mention(xml, account)
|
2016-09-09 19:04:34 +01:00
|
|
|
xml.link(rel: 'mentioned', href: TagManager.instance.uri_for(account))
|
2016-02-23 18:17:37 +00:00
|
|
|
end
|
|
|
|
|
2016-09-05 17:57:59 +01:00
|
|
|
def link_enclosure(xml, media)
|
2016-09-07 23:33:07 +01:00
|
|
|
xml.link(rel: 'enclosure', href: full_asset_url(media.file.url), type: media.file_content_type, length: media.file_file_size)
|
2016-09-05 17:57:59 +01:00
|
|
|
end
|
|
|
|
|
2016-02-28 13:26:26 +00:00
|
|
|
def link_avatar(xml, account)
|
2016-03-21 09:08:19 +00:00
|
|
|
single_link_avatar(xml, account, :large, 300)
|
|
|
|
single_link_avatar(xml, account, :medium, 96)
|
|
|
|
single_link_avatar(xml, account, :small, 48)
|
2016-02-28 13:26:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def logo(xml, url)
|
|
|
|
xml.logo url
|
|
|
|
end
|
|
|
|
|
2016-03-25 01:13:30 +00:00
|
|
|
def email(xml, email)
|
|
|
|
xml.email email
|
|
|
|
end
|
|
|
|
|
2016-03-18 23:16:04 +00:00
|
|
|
def conditionally_formatted(activity)
|
|
|
|
if activity.is_a?(Status)
|
2016-09-09 19:04:34 +01:00
|
|
|
Formatter.instance.format(activity.reblog? ? activity.reblog : activity)
|
2016-03-18 23:16:04 +00:00
|
|
|
elsif activity.nil?
|
2016-03-22 19:20:37 +00:00
|
|
|
nil
|
2016-03-18 23:16:04 +00:00
|
|
|
else
|
|
|
|
activity.content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-23 18:17:37 +00:00
|
|
|
def include_author(xml, account)
|
|
|
|
object_type xml, :person
|
2016-09-09 19:04:34 +01:00
|
|
|
uri xml, TagManager.instance.uri_for(account)
|
2016-02-23 18:17:37 +00:00
|
|
|
name xml, account.username
|
2016-03-25 01:13:30 +00:00
|
|
|
email xml, account.local? ? "#{account.acct}@#{Rails.configuration.x.local_domain}" : account.acct
|
2016-02-23 18:17:37 +00:00
|
|
|
summary xml, account.note
|
2016-09-09 19:04:34 +01:00
|
|
|
link_alternate xml, TagManager.instance.url_for(account)
|
2016-02-28 13:26:26 +00:00
|
|
|
link_avatar xml, account
|
2016-02-23 18:17:37 +00:00
|
|
|
portable_contact xml, account
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_entry(xml, stream_entry)
|
2016-03-26 00:10:18 +00:00
|
|
|
unique_id xml, stream_entry.created_at, stream_entry.activity_id, stream_entry.activity_type
|
|
|
|
published_at xml, stream_entry.created_at
|
|
|
|
updated_at xml, stream_entry.updated_at
|
|
|
|
title xml, stream_entry.title
|
|
|
|
content xml, conditionally_formatted(stream_entry.activity)
|
|
|
|
verb xml, stream_entry.verb
|
|
|
|
link_self xml, account_stream_entry_url(stream_entry.account, stream_entry, format: 'atom')
|
|
|
|
link_alternate xml, account_stream_entry_url(stream_entry.account, stream_entry)
|
2016-02-23 18:17:37 +00:00
|
|
|
|
|
|
|
# Comments need thread element
|
|
|
|
if stream_entry.threaded?
|
2016-09-09 19:04:34 +01:00
|
|
|
in_reply_to xml, TagManager.instance.uri_for(stream_entry.thread), TagManager.instance.url_for(stream_entry.thread)
|
2016-02-23 18:17:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if stream_entry.targeted?
|
|
|
|
target(xml) do
|
|
|
|
if stream_entry.target.object_type == :person
|
2016-03-25 01:13:30 +00:00
|
|
|
include_author xml, stream_entry.target
|
|
|
|
else
|
|
|
|
object_type xml, stream_entry.target.object_type
|
2016-09-09 19:04:34 +01:00
|
|
|
simple_id xml, TagManager.instance.uri_for(stream_entry.target)
|
2016-03-25 01:13:30 +00:00
|
|
|
title xml, stream_entry.target.title
|
2016-09-09 19:04:34 +01:00
|
|
|
link_alternate xml, TagManager.instance.url_for(stream_entry.target)
|
2016-02-23 18:17:37 +00:00
|
|
|
end
|
|
|
|
|
2016-03-22 08:03:03 +00:00
|
|
|
# Statuses have content and author
|
2016-02-23 18:17:37 +00:00
|
|
|
if [:note, :comment].include? stream_entry.target.object_type
|
2016-03-22 08:49:54 +00:00
|
|
|
content xml, conditionally_formatted(stream_entry.target)
|
|
|
|
verb xml, stream_entry.target.verb
|
|
|
|
published_at xml, stream_entry.target.created_at
|
|
|
|
updated_at xml, stream_entry.target.updated_at
|
2016-03-22 08:03:03 +00:00
|
|
|
|
|
|
|
author(xml) do
|
|
|
|
include_author xml, stream_entry.target.account
|
|
|
|
end
|
2016-02-23 18:17:37 +00:00
|
|
|
end
|
|
|
|
end
|
2016-03-22 19:20:37 +00:00
|
|
|
else
|
|
|
|
object_type xml, stream_entry.object_type
|
2016-02-23 18:17:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
stream_entry.mentions.each do |mentioned|
|
|
|
|
link_mention xml, mentioned
|
|
|
|
end
|
2016-09-05 17:57:59 +01:00
|
|
|
|
|
|
|
if stream_entry.activity.is_a?(Status)
|
|
|
|
stream_entry.activity.media_attachments.each do |media|
|
|
|
|
link_enclosure xml, media
|
|
|
|
end
|
|
|
|
end
|
2016-02-23 18:17:37 +00:00
|
|
|
end
|
|
|
|
|
2016-02-23 12:08:01 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def root_tag(xml, tag, &block)
|
2016-02-28 13:26:26 +00:00
|
|
|
xml.send(tag, { :xmlns => 'http://www.w3.org/2005/Atom', 'xmlns:thr' => 'http://purl.org/syndication/thread/1.0', 'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/', 'xmlns:poco' => 'http://portablecontacts.net/spec/1.0', 'xmlns:media' => 'http://purl.org/syndication/atommedia' }, &block)
|
2016-02-22 15:00:20 +00:00
|
|
|
end
|
2016-03-21 09:08:19 +00:00
|
|
|
|
|
|
|
def single_link_avatar(xml, account, size, px)
|
2016-09-04 13:04:26 +01:00
|
|
|
xml.link('rel' => 'avatar', 'type' => account.avatar_content_type, 'media:width' => px, 'media:height' =>px, 'href' => full_asset_url(account.avatar.url(size, false)))
|
2016-03-21 09:08:19 +00:00
|
|
|
end
|
2016-02-22 15:00:20 +00:00
|
|
|
end
|