From 47d50b0e3967f1d396bdbe8ea3e8909ce2be599f Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 28 Feb 2016 15:46:29 +0100 Subject: [PATCH] A lot of fixes from a live test --- app/assets/stylesheets/profile.scss | 16 ++++++++++++++++ app/controllers/xrd_controller.rb | 7 ++++++- app/helpers/application_helper.rb | 8 ++++++++ app/helpers/profile_helper.rb | 8 -------- app/helpers/routing_helper.rb | 1 + app/services/follow_service.rb | 2 +- app/services/post_status_service.rb | 2 +- app/services/process_feed_service.rb | 4 ++-- app/services/process_interaction_service.rb | 2 +- app/services/reblog_service.rb | 2 +- app/services/send_interaction_service.rb | 2 +- app/views/profile/_favourite.html.haml | 5 +++++ app/views/profile/_follow.html.haml | 5 +++++ app/views/profile/_status.html.haml | 2 +- app/views/xrd/webfinger.xml.ruby | 4 ++-- spec/helpers/application_helper_spec.rb | 8 ++++++++ spec/helpers/profile_helper_spec.rb | 8 -------- 17 files changed, 59 insertions(+), 27 deletions(-) create mode 100644 app/views/profile/_favourite.html.haml create mode 100644 app/views/profile/_follow.html.haml diff --git a/app/assets/stylesheets/profile.scss b/app/assets/stylesheets/profile.scss index 71466527e..49ce98d02 100644 --- a/app/assets/stylesheets/profile.scss +++ b/app/assets/stylesheets/profile.scss @@ -56,6 +56,13 @@ background: darken($background-color, 5%); } + &.entry-follow, &.entry-favourite { + .content { + padding-top: 10px; + padding-bottom: 10px; + } + } + &:last-child { border-bottom: 0; } @@ -127,6 +134,15 @@ font-size: 16px; padding: 0 10px; padding-left: 8px; + + a { + color: $primary-color; + text-decoration: none; + + &:hover { + text-decoration: underline; + } + } } .time { diff --git a/app/controllers/xrd_controller.rb b/app/controllers/xrd_controller.rb index 6fda75a03..417d4f4fa 100644 --- a/app/controllers/xrd_controller.rb +++ b/app/controllers/xrd_controller.rb @@ -19,7 +19,12 @@ class XrdController < ApplicationController end def username_from_resource - params[:resource].split('@').first.gsub('acct:', '') + if params[:resource].start_with?('acct:') + params[:resource].split('@').first.gsub('acct:', '') + else + url = Addressable::URI.parse(params[:resource]) + url.path.gsub('/users/', '') + end end def pem_to_magic_key(public_key) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4c65a78bb..90b45a025 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -22,6 +22,14 @@ module ApplicationHelper add_base_url_prefix salmon_path(id: account.id, format: '') end + def profile_url(account) + account.local? ? super(name: account.username) : account.url + end + + def status_url(status) + status.local? ? super(name: status.account.username, id: status.stream_entry.id) : status.url + end + def add_base_url_prefix(suffix) File.join(root_url, "api", suffix) end diff --git a/app/helpers/profile_helper.rb b/app/helpers/profile_helper.rb index cb19638d3..3a34dfbd8 100644 --- a/app/helpers/profile_helper.rb +++ b/app/helpers/profile_helper.rb @@ -3,14 +3,6 @@ module ProfileHelper account.display_name.blank? ? account.username : account.display_name end - def profile_url(account) - account.local? ? super(name: account.username) : account.url - end - - def status_url(status) - status.local? ? super(name: status.account.username, id: status.stream_entry.id) : status.url - end - def avatar_for_status_url(status) status.reblog? ? status.reblog.account.avatar.url(:small) : status.account.avatar.url(:small) end diff --git a/app/helpers/routing_helper.rb b/app/helpers/routing_helper.rb index 655e6bc26..390602623 100644 --- a/app/helpers/routing_helper.rb +++ b/app/helpers/routing_helper.rb @@ -2,6 +2,7 @@ module RoutingHelper extend ActiveSupport::Concern include Rails.application.routes.url_helpers include GrapeRouteHelpers::NamedRouteMatcher + include ActionView::Helpers::AssetUrlHelper included do def default_url_options diff --git a/app/services/follow_service.rb b/app/services/follow_service.rb index bcf7f5f97..55cb9bdca 100644 --- a/app/services/follow_service.rb +++ b/app/services/follow_service.rb @@ -9,7 +9,7 @@ class FollowService < BaseService follow = source_account.follow!(target_account) send_interaction_service.(follow.stream_entry, target_account) - source_account.ping!(atom_user_stream_url(id: source_account.id), HUB_URL) + source_account.ping!(atom_user_stream_url(id: source_account.id), [HUB_URL]) end private diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index 64519a400..e19c0584e 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -7,7 +7,7 @@ class PostStatusService < BaseService def call(account, text, in_reply_to = nil) status = account.statuses.create!(text: text, thread: in_reply_to) process_mentions_service.(status) - account.ping!(atom_user_stream_url(id: account.id), HUB_URL) + account.ping!(atom_user_stream_url(id: account.id), [HUB_URL]) status end diff --git a/app/services/process_feed_service.rb b/app/services/process_feed_service.rb index 1c85942f3..146869552 100644 --- a/app/services/process_feed_service.rb +++ b/app/services/process_feed_service.rb @@ -10,7 +10,7 @@ class ProcessFeedService < BaseService end xml.xpath('//xmlns:entry').each do |entry| - next unless [:note, :comment, :activity].includes? object_type(entry) + next unless [:note, :comment, :activity].include? object_type(entry) status = Status.find_by(uri: activity_id(entry)) @@ -88,7 +88,7 @@ class ProcessFeedService < BaseService end def thread_id(xml) - xml.at_xpath('./thr:in-reply-to-id').attribute('ref').value + xml.at_xpath('./thr:in-reply-to').attribute('ref').value rescue nil end diff --git a/app/services/process_interaction_service.rb b/app/services/process_interaction_service.rb index b5ceaac06..2ebaa5296 100644 --- a/app/services/process_interaction_service.rb +++ b/app/services/process_interaction_service.rb @@ -43,7 +43,7 @@ class ProcessInteractionService < BaseService end def mentions_account?(xml, account) - xml.xpath('/xmlns:entry/xmlns:link[@rel="mentioned"]').each { |mention_link| return true if mention_link.attribute('ref') == profile_url(name: account.username) } + xml.xpath('/xmlns:entry/xmlns:link[@rel="mentioned"]').each { |mention_link| return true if mention_link.attribute('href').value == profile_url(account) } false end diff --git a/app/services/reblog_service.rb b/app/services/reblog_service.rb index 66b7634fb..4c76e5038 100644 --- a/app/services/reblog_service.rb +++ b/app/services/reblog_service.rb @@ -5,7 +5,7 @@ class ReblogService < BaseService # @return [Status] def call(account, reblogged_status) reblog = account.statuses.create!(reblog: reblogged_status, text: '') - account.ping!(atom_user_stream_url(id: account.id), HUB_URL) + account.ping!(atom_user_stream_url(id: account.id), [HUB_URL]) return reblog if reblogged_status.local? send_interaction_service.(reblog.stream_entry, reblogged_status.account) reblog diff --git a/app/services/send_interaction_service.rb b/app/services/send_interaction_service.rb index 42b273ed6..5385831ed 100644 --- a/app/services/send_interaction_service.rb +++ b/app/services/send_interaction_service.rb @@ -5,7 +5,7 @@ class SendInteractionService < BaseService # @param [StreamEntry] stream_entry # @param [Account] target_account def call(stream_entry, target_account) - envelope = salmon.pack(entry_xml(stream_entry), target_account.keypair) + envelope = salmon.pack(entry_xml(stream_entry), stream_entry.account.keypair) salmon.post(target_account.salmon_url, envelope) end diff --git a/app/views/profile/_favourite.html.haml b/app/views/profile/_favourite.html.haml new file mode 100644 index 000000000..85e3a0824 --- /dev/null +++ b/app/views/profile/_favourite.html.haml @@ -0,0 +1,5 @@ +.entry.entry-favourite + .content + %strong= favourite.account.acct + favourited a post by + %strong= favourite.status.account.acct diff --git a/app/views/profile/_follow.html.haml b/app/views/profile/_follow.html.haml new file mode 100644 index 000000000..c1c081374 --- /dev/null +++ b/app/views/profile/_follow.html.haml @@ -0,0 +1,5 @@ +.entry.entry-follow + .content + %strong= follow.account.acct + is now following + %strong= follow.target_account.acct diff --git a/app/views/profile/_status.html.haml b/app/views/profile/_status.html.haml index 1edd8df77..b089036b1 100644 --- a/app/views/profile/_status.html.haml +++ b/app/views/profile/_status.html.haml @@ -14,7 +14,7 @@ .header = render partial: 'status_header', locals: { status: status.reblog? ? status.reblog : status } .content - = status.content + = status.content.html_safe .counters = render partial: 'status_footer', locals: { status: status.reblog? ? status.reblog : status } diff --git a/app/views/xrd/webfinger.xml.ruby b/app/views/xrd/webfinger.xml.ruby index ce21f148a..42adc6551 100644 --- a/app/views/xrd/webfinger.xml.ruby +++ b/app/views/xrd/webfinger.xml.ruby @@ -1,8 +1,8 @@ Nokogiri::XML::Builder.new do |xml| xml.XRD(xmlns: 'http://docs.oasis-open.org/ns/xri/xrd-1.0') do xml.Subject @canonical_account_uri - xml.Alias profile_url(name: @account.username) - xml.Link(rel: 'http://webfinger.net/rel/profile-page', type: 'text/html', href: profile_url(name: @account.username)) + xml.Alias profile_url(@account) + xml.Link(rel: 'http://webfinger.net/rel/profile-page', type: 'text/html', href: profile_url(@account)) xml.Link(rel: 'http://schemas.google.com/g/2010#updates-from', type: 'application/atom+xml', href: atom_user_stream_url(id: @account.id)) xml.Link(rel: 'salmon', href: salmon_url(@account)) xml.Link(rel: 'magic-public-key', href: @magic_key) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index ad4284768..0599c46e6 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -34,4 +34,12 @@ RSpec.describe ApplicationHelper, type: :helper do expect(helper.add_base_url_prefix('test')).to eql "#{root_url}api/test" end end + + describe '#profile_url' do + pending + end + + describe '#status_url' do + pending + end end diff --git a/spec/helpers/profile_helper_spec.rb b/spec/helpers/profile_helper_spec.rb index cd5952717..77712105c 100644 --- a/spec/helpers/profile_helper_spec.rb +++ b/spec/helpers/profile_helper_spec.rb @@ -5,14 +5,6 @@ RSpec.describe ProfileHelper, type: :helper do pending end - describe '#profile_url' do - pending - end - - describe '#status_url' do - pending - end - describe '#avatar_for_status_url' do pending end