diff options
author | beatrix <beatrix.bitrot@gmail.com> | 2017-07-20 11:24:32 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-20 11:24:32 -0400 |
commit | e7edb4d1eeba6c12a1c71271faa30d2bbf00d054 (patch) | |
tree | f373d05c4ea43bd335910f3603fab3d866a2486e /app | |
parent | d2352246920800e491466d84b0146feb4d1d791f (diff) | |
parent | 1fcdaafa6fbe6d746a096c33263d76e6819da46d (diff) |
Merge pull request #87 from tootsuite/master
merge upstream
Diffstat (limited to 'app')
47 files changed, 245 insertions, 145 deletions
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 37a1e540f..c270eb000 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -13,7 +13,7 @@ class AccountsController < ApplicationController format.atom do @entries = @account.stream_entries.where(hidden: false).with_includes.paginate_by_max_id(20, params[:max_id], params[:since_id]) - render xml: Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.feed(@account, @entries.to_a)) + render xml: OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.feed(@account, @entries.to_a)) end format.json do diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index c1b2ec3cf..105a2859d 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -17,11 +17,7 @@ class Api::BaseController < ApplicationController render json: { error: 'Record not found' }, status: 404 end - rescue_from Goldfinger::Error do - render json: { error: 'Remote account could not be resolved' }, status: 422 - end - - rescue_from HTTP::Error do + rescue_from HTTP::Error, Mastodon::UnexpectedResponseError do render json: { error: 'Remote data could not be fetched' }, status: 503 end diff --git a/app/controllers/settings/sessions_controller.rb b/app/controllers/settings/sessions_controller.rb new file mode 100644 index 000000000..0da1b027b --- /dev/null +++ b/app/controllers/settings/sessions_controller.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class Settings::SessionsController < ApplicationController + before_action :set_session, only: :destroy + + def destroy + @session.destroy! + flash[:notice] = I18n.t('sessions.revoke_success') + redirect_to edit_user_registration_path + end + + private + + def set_session + @session = current_user.session_activations.find(params[:id]) + end +end diff --git a/app/controllers/stream_entries_controller.rb b/app/controllers/stream_entries_controller.rb index e3db77caa..3eb91d830 100644 --- a/app/controllers/stream_entries_controller.rb +++ b/app/controllers/stream_entries_controller.rb @@ -19,7 +19,7 @@ class StreamEntriesController < ApplicationController end format.atom do - render xml: Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.entry(@stream_entry, true)) + render xml: OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.entry(@stream_entry, true)) end end end diff --git a/app/helpers/routing_helper.rb b/app/helpers/routing_helper.rb index 9650ee286..8126176ba 100644 --- a/app/helpers/routing_helper.rb +++ b/app/helpers/routing_helper.rb @@ -11,7 +11,7 @@ module RoutingHelper end end - def full_asset_url(source) - Rails.configuration.x.use_s3 ? source : URI.join(root_url, ActionController::Base.helpers.asset_url(source)).to_s + def full_asset_url(source, options = {}) + Rails.configuration.x.use_s3 ? source : URI.join(root_url, ActionController::Base.helpers.asset_url(source, options)).to_s end end diff --git a/app/javascript/mastodon/actions/statuses.js b/app/javascript/mastodon/actions/statuses.js index 8d385715c..2204e0b14 100644 --- a/app/javascript/mastodon/actions/statuses.js +++ b/app/javascript/mastodon/actions/statuses.js @@ -113,7 +113,7 @@ export function fetchContext(id) { dispatch(fetchContextSuccess(id, response.data.ancestors, response.data.descendants)); }).catch(error => { - if (error.response.status === 404) { + if (error.response && error.response.status === 404) { dispatch(deleteFromTimelines(id)); } diff --git a/app/javascript/mastodon/actions/timelines.js b/app/javascript/mastodon/actions/timelines.js index dd14cb1cd..5c0cd93c7 100644 --- a/app/javascript/mastodon/actions/timelines.js +++ b/app/javascript/mastodon/actions/timelines.js @@ -105,7 +105,7 @@ export function refreshTimelineFail(timeline, error, skipLoading) { timeline, error, skipLoading, - skipAlert: error.response.status === 404, + skipAlert: error.response && error.response.status === 404, }; }; diff --git a/app/javascript/mastodon/components/status_list.js b/app/javascript/mastodon/components/status_list.js index e7b38a07a..59f792920 100644 --- a/app/javascript/mastodon/components/status_list.js +++ b/app/javascript/mastodon/components/status_list.js @@ -30,8 +30,8 @@ export default class StatusList extends ImmutablePureComponent { intersectionObserverWrapper = new IntersectionObserverWrapper(); - handleScroll = debounce((e) => { - const { scrollTop, scrollHeight, clientHeight } = e.target; + handleScroll = debounce(() => { + const { scrollTop, scrollHeight, clientHeight } = this.node; const offset = scrollHeight - scrollTop - clientHeight; this._oldScrollPosition = scrollHeight - scrollTop; @@ -49,18 +49,22 @@ export default class StatusList extends ImmutablePureComponent { componentDidMount () { this.attachScrollListener(); this.attachIntersectionObserver(); + + // Handle initial scroll posiiton + this.handleScroll(); } componentDidUpdate (prevProps) { // Reset the scroll position when a new toot comes in in order not to // jerk the scrollbar around if you're already scrolled down the page. - if (prevProps.statusIds.size < this.props.statusIds.size && - prevProps.statusIds.first() !== this.props.statusIds.first() && - this._oldScrollPosition && - this.node.scrollTop > 0) { - let newScrollTop = this.node.scrollHeight - this._oldScrollPosition; - if (this.node.scrollTop !== newScrollTop) { - this.node.scrollTop = newScrollTop; + if (prevProps.statusIds.size < this.props.statusIds.size && this._oldScrollPosition && this.node.scrollTop > 0) { + if (prevProps.statusIds.first() !== this.props.statusIds.first()) { + let newScrollTop = this.node.scrollHeight - this._oldScrollPosition; + if (this.node.scrollTop !== newScrollTop) { + this.node.scrollTop = newScrollTop; + } + } else { + this._oldScrollPosition = this.node.scrollHeight - this.node.scrollTop; } } } diff --git a/app/javascript/mastodon/emoji.js b/app/javascript/mastodon/emoji.js index 1de41f572..9b58cacf5 100644 --- a/app/javascript/mastodon/emoji.js +++ b/app/javascript/mastodon/emoji.js @@ -1,7 +1,7 @@ -import { unicodeToFilename } from './emojione_light'; +import { unicodeMapping } from './emojione_light'; import Trie from 'substring-trie'; -const trie = new Trie(Object.keys(unicodeToFilename)); +const trie = new Trie(Object.keys(unicodeMapping)); function emojify(str) { // This walks through the string from start to end, ignoring any tags (<p>, <br>, etc.) @@ -19,10 +19,10 @@ function emojify(str) { insideTag = true; } else if (!insideTag && (match = trie.search(str.substring(i)))) { const unicodeStr = match; - if (unicodeStr in unicodeToFilename) { - const filename = unicodeToFilename[unicodeStr]; + if (unicodeStr in unicodeMapping) { + const [filename, shortCode] = unicodeMapping[unicodeStr]; const alt = unicodeStr; - const replacement = `<img draggable="false" class="emojione" alt="${alt}" src="/emoji/${filename}.svg" />`; + const replacement = `<img draggable="false" class="emojione" alt="${alt}" title=":${shortCode}:" src="/emoji/${filename}.svg" />`; str = str.substring(0, i) + replacement + str.substring(i + unicodeStr.length); i += (replacement.length - unicodeStr.length); // jump ahead the length we've added to the string } diff --git a/app/javascript/mastodon/emojione_light.js b/app/javascript/mastodon/emojione_light.js index c75e10a98..985e9dbcb 100644 --- a/app/javascript/mastodon/emojione_light.js +++ b/app/javascript/mastodon/emojione_light.js @@ -5,7 +5,7 @@ const emojione = require('emojione'); const mappedUnicode = emojione.mapUnicodeToShort(); -module.exports.unicodeToFilename = Object.keys(emojione.jsEscapeMap) +module.exports.unicodeMapping = Object.keys(emojione.jsEscapeMap) .map(unicodeStr => [unicodeStr, mappedUnicode[emojione.jsEscapeMap[unicodeStr]]]) - .map(([unicodeStr, shortCode]) => ({ [unicodeStr]: emojione.emojioneList[shortCode].fname })) + .map(([unicodeStr, shortCode]) => ({ [unicodeStr]: [emojione.emojioneList[shortCode].fname, shortCode.slice(1, shortCode.length - 1)] })) .reduce((x, y) => Object.assign(x, y), { }); diff --git a/app/javascript/mastodon/locales/ja.json b/app/javascript/mastodon/locales/ja.json index b3943f646..7fe27a092 100644 --- a/app/javascript/mastodon/locales/ja.json +++ b/app/javascript/mastodon/locales/ja.json @@ -56,7 +56,7 @@ "confirmations.mute.confirm": "ミュート", "confirmations.mute.message": "本当に{name}をミュートしますか?", "confirmations.unfollow.confirm": "フォロー解除", - "confirmations.unfollow.message": "本当に{name}のフォローを解除しますか?", + "confirmations.unfollow.message": "本当に{name}をフォロー解除しますか?", "emoji_button.activity": "活動", "emoji_button.flags": "国旗", "emoji_button.food": "食べ物", diff --git a/app/javascript/mastodon/locales/pl.json b/app/javascript/mastodon/locales/pl.json index 683f589b1..348984648 100644 --- a/app/javascript/mastodon/locales/pl.json +++ b/app/javascript/mastodon/locales/pl.json @@ -55,8 +55,8 @@ "confirmations.domain_block.message": "Czy na pewno chcesz zablokować całą domenę {domain}? Zwykle lepszym rozwiązaniem jest blokada lub wyciszenie kilku użytkowników.", "confirmations.mute.confirm": "Wycisz", "confirmations.mute.message": "Czy na pewno chcesz wyciszyć {name}?", - "confirmations.unfollow.confirm": "Unfollow", - "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", + "confirmations.unfollow.confirm": "Przestań śledzić", + "confirmations.unfollow.message": "Czy na pewno zamierzasz przestać śledzić {name}?", "emoji_button.activity": "Aktywność", "emoji_button.flags": "Flagi", "emoji_button.food": "Żywność i napoje", @@ -111,8 +111,8 @@ "notifications.column_settings.favourite": "Ulubione:", "notifications.column_settings.follow": "Nowi śledzący:", "notifications.column_settings.mention": "Wspomniali:", - "notifications.column_settings.push": "Push notifications", - "notifications.column_settings.push_meta": "This device", + "notifications.column_settings.push": "Powiadomienia push", + "notifications.column_settings.push_meta": "To urządzenie", "notifications.column_settings.reblog": "Podbili:", "notifications.column_settings.show": "Pokaż w kolumnie", "notifications.column_settings.sound": "Odtwarzaj dźwięk", @@ -125,7 +125,7 @@ "onboarding.page_one.handle": "Jesteś na domenie {domain}, więc Twój pełny adres to {handle}", "onboarding.page_one.welcome": "Witamy w Mastodon!", "onboarding.page_six.admin": "Administratorem tej instancji jest {admin}.", - "onboarding.page_six.almost_done": "Prawie gotowe...", + "onboarding.page_six.almost_done": "Prawie gotowe…", "onboarding.page_six.appetoot": "Bon Appetoot!", "onboarding.page_six.apps_available": "Są dostępne {apps} dla Androida, iOS i innych platform.", "onboarding.page_six.github": "Mastodon jest oprogramowaniem otwartoźródłwym. Możesz zgłaszać błędy, proponować funkcje i pomóc w rozwoju na {github}.", @@ -151,7 +151,7 @@ "report.target": "Zgłaszanie {target}", "search.placeholder": "Szukaj", "search_results.total": "{count, number} {count, plural, one {wynik} more {wyniki}}", - "standalone.public_title": "A look inside...", + "standalone.public_title": "Spojrzenie wgłąb…", "status.cannot_reblog": "Ten post nie może zostać podbity", "status.delete": "Usuń", "status.favourite": "Ulubione", @@ -178,7 +178,7 @@ "upload_area.title": "Przeciągnij i upuść aby wysłać", "upload_button.label": "Dodaj zawartość multimedialną", "upload_form.undo": "Cofnij", - "upload_progress.label": "Wysyłanie...", + "upload_progress.label": "Wysyłanie", "video_player.expand": "Przełącz wideo", "video_player.toggle_sound": "Przełącz dźwięk", "video_player.toggle_visible": "Przełącz widoczność", diff --git a/app/javascript/packs/public.js b/app/javascript/packs/public.js index 1e89660f2..e34c47fd0 100644 --- a/app/javascript/packs/public.js +++ b/app/javascript/packs/public.js @@ -36,7 +36,7 @@ function main() { [].forEach.call(document.querySelectorAll('time.time-ago'), (content) => { const datetime = new Date(content.getAttribute('datetime')); - content.textContent = relativeFormat.format(datetime);; + content.textContent = relativeFormat.format(datetime); }); }); diff --git a/app/javascript/styles/components.scss b/app/javascript/styles/components.scss index 0a8fa5e6d..0cd082985 100644 --- a/app/javascript/styles/components.scss +++ b/app/javascript/styles/components.scss @@ -4091,6 +4091,10 @@ button.icon-button.active i.fa-retweet { } } +::-webkit-scrollbar-thumb { + border-radius: 0; +} + noscript { text-align: center; diff --git a/app/lib/exceptions.rb b/app/lib/exceptions.rb index 9bc802c12..34d84a34f 100644 --- a/app/lib/exceptions.rb +++ b/app/lib/exceptions.rb @@ -5,4 +5,14 @@ module Mastodon class NotPermittedError < Error; end class ValidationError < Error; end class RaceConditionError < Error; end + + class UnexpectedResponseError < Error + def initialize(response = nil) + @response = response + end + + def to_s + "#{@response.uri} returned code #{@response.code}" + end + end end diff --git a/app/lib/ostatus/activity/base.rb b/app/lib/ostatus/activity/base.rb index f528815b3..e1477f0eb 100644 --- a/app/lib/ostatus/activity/base.rb +++ b/app/lib/ostatus/activity/base.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Ostatus::Activity::Base +class OStatus::Activity::Base def initialize(xml, account = nil) @xml = xml @account = account diff --git a/app/lib/ostatus/activity/creation.rb b/app/lib/ostatus/activity/creation.rb index c54d64fd7..e22f746f2 100644 --- a/app/lib/ostatus/activity/creation.rb +++ b/app/lib/ostatus/activity/creation.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Ostatus::Activity::Creation < Ostatus::Activity::Base +class OStatus::Activity::Creation < OStatus::Activity::Base def perform if redis.exists("delete_upon_arrival:#{@account.id}:#{id}") Rails.logger.debug "Delete for status #{id} was queued, ignoring" diff --git a/app/lib/ostatus/activity/deletion.rb b/app/lib/ostatus/activity/deletion.rb index c4d05a467..860faf501 100644 --- a/app/lib/ostatus/activity/deletion.rb +++ b/app/lib/ostatus/activity/deletion.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Ostatus::Activity::Deletion < Ostatus::Activity::Base +class OStatus::Activity::Deletion < OStatus::Activity::Base def perform Rails.logger.debug "Deleting remote status #{id}" status = Status.find_by(uri: id, account: @account) diff --git a/app/lib/ostatus/activity/general.rb b/app/lib/ostatus/activity/general.rb index 3ff7a039a..b3bef9861 100644 --- a/app/lib/ostatus/activity/general.rb +++ b/app/lib/ostatus/activity/general.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Ostatus::Activity::General < Ostatus::Activity::Base +class OStatus::Activity::General < OStatus::Activity::Base def specialize special_class&.new(@xml, @account) end @@ -10,11 +10,11 @@ class Ostatus::Activity::General < Ostatus::Activity::Base def special_class case verb when :post - Ostatus::Activity::Post + OStatus::Activity::Post when :share - Ostatus::Activity::Share + OStatus::Activity::Share when :delete - Ostatus::Activity::Deletion + OStatus::Activity::Deletion end end end diff --git a/app/lib/ostatus/activity/post.rb b/app/lib/ostatus/activity/post.rb index 8028db2f8..755ed8656 100644 --- a/app/lib/ostatus/activity/post.rb +++ b/app/lib/ostatus/activity/post.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Ostatus::Activity::Post < Ostatus::Activity::Creation +class OStatus::Activity::Post < OStatus::Activity::Creation def perform status, just_created = super diff --git a/app/lib/ostatus/activity/remote.rb b/app/lib/ostatus/activity/remote.rb index 755f885e6..ecec6886c 100644 --- a/app/lib/ostatus/activity/remote.rb +++ b/app/lib/ostatus/activity/remote.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Ostatus::Activity::Remote < Ostatus::Activity::Base +class OStatus::Activity::Remote < OStatus::Activity::Base def perform find_status(id) || FetchRemoteStatusService.new.call(url) end diff --git a/app/lib/ostatus/activity/share.rb b/app/lib/ostatus/activity/share.rb index 73aac58ed..290008021 100644 --- a/app/lib/ostatus/activity/share.rb +++ b/app/lib/ostatus/activity/share.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Ostatus::Activity::Share < Ostatus::Activity::Creation +class OStatus::Activity::Share < OStatus::Activity::Creation def perform return if reblog.nil? @@ -18,7 +18,7 @@ class Ostatus::Activity::Share < Ostatus::Activity::Creation def reblog return @reblog if defined? @reblog - original_status = Ostatus::Activity::Remote.new(object).perform + original_status = OStatus::Activity::Remote.new(object).perform return if original_status.nil? @reblog = original_status.reblog? ? original_status.reblog : original_status diff --git a/app/lib/ostatus/atom_serializer.rb b/app/lib/ostatus/atom_serializer.rb index 909d84df3..0d62361be 100644 --- a/app/lib/ostatus/atom_serializer.rb +++ b/app/lib/ostatus/atom_serializer.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Ostatus::AtomSerializer +class OStatus::AtomSerializer include RoutingHelper include ActionView::Helpers::SanitizeHelper diff --git a/app/models/account.rb b/app/models/account.rb index 9f8e22adf..46cc84746 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -36,6 +36,11 @@ # followers_count :integer default(0), not null # following_count :integer default(0), not null # last_webfingered_at :datetime +# inbox_url :string default(""), not null +# outbox_url :string default(""), not null +# shared_inbox_url :string default(""), not null +# followers_url :string default(""), not null +# protocol :integer default("ostatus"), not null # class Account < ApplicationRecord @@ -49,6 +54,8 @@ class Account < ApplicationRecord include Remotable include EmojiHelper + enum protocol: [:ostatus, :activitypub] + # Local users has_one :user, inverse_of: :account diff --git a/app/models/web/push_subscription.rb b/app/models/web/push_subscription.rb index baf6a1ece..86df9b591 100644 --- a/app/models/web/push_subscription.rb +++ b/app/models/web/push_subscription.rb @@ -26,8 +26,6 @@ class Web::PushSubscription < ApplicationRecord before_create :send_welcome_notification def push(notification) - return unless pushable? notification - name = display_name notification.from_account title = title_str(name, notification) body = body_str notification @@ -45,7 +43,7 @@ class Web::PushSubscription < ApplicationRecord title: title, dir: dir, image: image, - badge: full_asset_url('badge.png'), + badge: full_asset_url('badge.png', skip_pipeline: true), tag: notification.id, timestamp: notification.created_at, icon: notification.from_account.avatar_static_url, @@ -69,6 +67,10 @@ class Web::PushSubscription < ApplicationRecord ) end + def pushable?(notification) + data && data.key?('alerts') && data['alerts'][notification.type.to_s] + end + def as_payload payload = { id: id, @@ -115,7 +117,7 @@ class Web::PushSubscription < ApplicationRecord when :mention then [ { title: translate('push_notifications.mention.action_favourite'), - icon: full_asset_url('emoji/2764.png'), + icon: full_asset_url('emoji/2764.png', skip_pipeline: true), todo: 'request', method: 'POST', action: "/api/v1/statuses/#{notification.target_status.id}/favourite", @@ -148,16 +150,12 @@ class Web::PushSubscription < ApplicationRecord rtl?(body) ? 'rtl' : 'ltr' end - def pushable?(notification) - data && data.key?('alerts') && data['alerts'][notification.type.to_s] - end - def send_welcome_notification Webpush.payload_send( message: JSON.generate( title: translate('push_notifications.subscribed.title'), - icon: full_asset_url('android-chrome-192x192.png'), - badge: full_asset_url('badge.png'), + icon: full_asset_url('android-chrome-192x192.png', skip_pipeline: true), + badge: full_asset_url('badge.png', skip_pipeline: true), data: { content: translate('push_notifications.subscribed.body'), actions: [], diff --git a/app/services/authorize_follow_service.rb b/app/services/authorize_follow_service.rb index a25d11dbd..41815a393 100644 --- a/app/services/authorize_follow_service.rb +++ b/app/services/authorize_follow_service.rb @@ -10,6 +10,6 @@ class AuthorizeFollowService < BaseService private def build_xml(follow_request) - Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request)) + OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request)) end end diff --git a/app/services/block_service.rb b/app/services/block_service.rb index 15420e192..5d7bf6a3b 100644 --- a/app/services/block_service.rb +++ b/app/services/block_service.rb @@ -18,6 +18,6 @@ class BlockService < BaseService private def build_xml(block) - Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.block_salmon(block)) + OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.block_salmon(block)) end end diff --git a/app/services/concerns/stream_entry_renderer.rb b/app/services/concerns/stream_entry_renderer.rb index d9c30c53c..9f6c8a082 100644 --- a/app/services/concerns/stream_entry_renderer.rb +++ b/app/services/concerns/stream_entry_renderer.rb @@ -2,6 +2,6 @@ module StreamEntryRenderer def stream_entry_to_xml(stream_entry) - Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.entry(stream_entry, true)) + OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.entry(stream_entry, true)) end end diff --git a/app/services/favourite_service.rb b/app/services/favourite_service.rb index a08aba638..291f9e56e 100644 --- a/app/services/favourite_service.rb +++ b/app/services/favourite_service.rb @@ -28,6 +28,6 @@ class FavouriteService < BaseService private def build_xml(favourite) - Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.favourite_salmon(favourite)) + OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.favourite_salmon(favourite)) end end diff --git a/app/services/fetch_remote_account_service.rb b/app/services/fetch_remote_account_service.rb index 1efac365b..8eed0d454 100644 --- a/app/services/fetch_remote_account_service.rb +++ b/app/services/fetch_remote_account_service.rb @@ -32,8 +32,5 @@ class FetchRemoteAccountService < BaseService rescue Nokogiri::XML::XPath::SyntaxError Rails.logger.debug 'Invalid XML or missing namespace' nil - rescue Goldfinger::NotFoundError, Goldfinger::Error - Rails.logger.debug 'Exceptions related to Goldfinger occurs' - nil end end diff --git a/app/services/fetch_remote_status_service.rb b/app/services/fetch_remote_status_service.rb index 6ac31e4d8..b9f5f97b1 100644 --- a/app/services/fetch_remote_status_service.rb +++ b/app/services/fetch_remote_status_service.rb @@ -33,9 +33,6 @@ class FetchRemoteStatusService < BaseService rescue Nokogiri::XML::XPath::SyntaxError Rails.logger.debug 'Invalid XML or missing namespace' nil - rescue Goldfinger::NotFoundError, Goldfinger::Error - Rails.logger.debug 'Exceptions related to Goldfinger occurs' - nil end def confirmed_domain?(domain, account) diff --git a/app/services/follow_service.rb b/app/services/follow_service.rb index 7a7275b6e..3155feaa4 100644 --- a/app/services/follow_service.rb +++ b/app/services/follow_service.rb @@ -57,10 +57,10 @@ class FollowService < BaseService end def build_follow_request_xml(follow_request) - Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.follow_request_salmon(follow_request)) + OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.follow_request_salmon(follow_request)) end def build_follow_xml(follow) - Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.follow_salmon(follow)) + OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.follow_salmon(follow)) end end diff --git a/app/services/notify_service.rb b/app/services/notify_service.rb index c7d8ad50a..a44df5180 100644 --- a/app/services/notify_service.rb +++ b/app/services/notify_service.rb @@ -65,7 +65,12 @@ class NotifyService < BaseService end def send_push_notifications - sessions_with_subscriptions_ids = @recipient.user.session_activations.where.not(web_push_subscription: nil).pluck(:id) + # HACK: Can be caused by quickly unfavouriting a status, since creating + # a favourite and creating a notification are not wrapped in a transaction. + return if @notification.activity.nil? + + sessions_with_subscriptions = @recipient.user.session_activations.where.not(web_push_subscription: nil) + sessions_with_subscriptions_ids = sessions_with_subscriptions.select { |session| session.web_push_subscription.pushable? @notification }.map(&:id) WebPushNotificationWorker.push_bulk(sessions_with_subscriptions_ids) do |session_activation_id| [session_activation_id, @notification.id] diff --git a/app/services/process_feed_service.rb b/app/services/process_feed_service.rb index b99048a06..31191a818 100644 --- a/app/services/process_feed_service.rb +++ b/app/services/process_feed_service.rb @@ -20,10 +20,10 @@ class ProcessFeedService < BaseService end def process_entry(xml, account) - activity = Ostatus::Activity::General.new(xml, account) + activity = OStatus::Activity::General.new(xml, account) activity.specialize&.perform if activity.status? rescue ActiveRecord::RecordInvalid => e - Rails.logger.debug "Nothing was saved for #{id} because: #{e}" + Rails.logger.debug "Nothing was saved for #{activity.id} because: #{e}" nil end end diff --git a/app/services/process_interaction_service.rb b/app/services/process_interaction_service.rb index 584a109ad..cc99cde03 100644 --- a/app/services/process_interaction_service.rb +++ b/app/services/process_interaction_service.rb @@ -47,7 +47,7 @@ class ProcessInteractionService < BaseService reflect_unblock!(account, target_account) end end - rescue Goldfinger::Error, HTTP::Error, OStatus2::BadSalmonError, Mastodon::NotPermittedError + rescue HTTP::Error, OStatus2::BadSalmonError, Mastodon::NotPermittedError nil end diff --git a/app/services/reject_follow_service.rb b/app/services/reject_follow_service.rb index 87fc49b34..fd7e66c23 100644 --- a/app/services/reject_follow_service.rb +++ b/app/services/reject_follow_service.rb @@ -10,6 +10,6 @@ class RejectFollowService < BaseService private def build_xml(follow_request) - Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.reject_follow_request_salmon(follow_request)) + OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.reject_follow_request_salmon(follow_request)) end end diff --git a/app/services/resolve_remote_account_service.rb b/app/services/resolve_remote_account_service.rb index d2dfda824..e0e2ebc83 100644 --- a/app/services/resolve_remote_account_service.rb +++ b/app/services/resolve_remote_account_service.rb @@ -11,97 +11,154 @@ class ResolveRemoteAccountService < BaseService # @param [String] uri User URI in the form of username@domain # @return [Account] def call(uri, update_profile = true, redirected = nil) - username, domain = uri.split('@') + @username, @domain = uri.split('@') - return Account.find_local(username) if TagManager.instance.local_domain?(domain) + return Account.find_local(@username) if TagManager.instance.local_domain?(@domain) - account = Account.find_remote(username, domain) - return account unless account_needs_webfinger_update?(account) + @account = Account.find_remote(@username, @domain) - Rails.logger.debug "Looking up webfinger for #{uri}" + return @account unless webfinger_update_due? - data = Goldfinger.finger("acct:#{uri}") + Rails.logger.debug "Looking up webfinger for #{uri}" - raise Goldfinger::Error, 'Missing resource links' if data.link('http://schemas.google.com/g/2010#updates-from').nil? || data.link('salmon').nil? || data.link('http://webfinger.net/rel/profile-page').nil? || data.link('magic-public-key').nil? + @webfinger = Goldfinger.finger("acct:#{uri}") - # Disallow account hijacking - confirmed_username, confirmed_domain = data.subject.gsub(/\Aacct:/, '').split('@') + confirmed_username, confirmed_domain = @webfinger.subject.gsub(/\Aacct:/, '').split('@') - unless confirmed_username.casecmp(username).zero? && confirmed_domain.casecmp(domain).zero? - return call("#{confirmed_username}@#{confirmed_domain}", update_profile, true) if redirected.nil? - raise Goldfinger::Error, 'Requested and returned acct URI do not match' + if confirmed_username.casecmp(@username).zero? && confirmed_domain.casecmp(@domain).zero? + @username = confirmed_username + @domain = confirmed_domain + elsif redirected.nil? + return call("#{confirmed_username}@#{confirmed_domain}", update_profile, true) + else + Rails.logger.debug 'Requested and returned acct URIs do not match' + return end - return Account.find_local(confirmed_username) if TagManager.instance.local_domain?(confirmed_domain) + return if links_missing? + return Account.find_local(@username) if TagManager.instance.local_domain?(@domain) - confirmed_account = Account.find_remote(confirmed_username, confirmed_domain) - if confirmed_account.nil? - Rails.logger.debug "Creating new remote account for #{uri}" + RedisLock.acquire(lock_options) do |lock| + if lock.acquired? + @account = Account.find_remote(@username, @domain) - domain_block = DomainBlock.find_by(domain: domain) - account = Account.new(username: confirmed_username, domain: confirmed_domain) - account.suspended = true if domain_block && domain_block.suspend? - account.silenced = true if domain_block && domain_block.silence? - account.private_key = nil - else - account = confirmed_account + create_account if @account.nil? + update_account + + update_account_profile if update_profile + end end - account.last_webfingered_at = Time.now.utc + @account + rescue Goldfinger::Error => e + Rails.logger.debug "Webfinger query for #{uri} unsuccessful: #{e}" + nil + end - account.remote_url = data.link('http://schemas.google.com/g/2010#updates-from').href - account.salmon_url = data.link('salmon').href - account.url = data.link('http://webfinger.net/rel/profile-page').href - account.public_key = magic_key_to_pem(data.link('magic-public-key').href) + private - body, xml = get_feed(account.remote_url) - hubs = get_hubs(xml) + def links_missing? + @webfinger.link('http://schemas.google.com/g/2010#updates-from').nil? || + @webfinger.link('salmon').nil? || + @webfinger.link('http://webfinger.net/rel/profile-page').nil? || + @webfinger.link('magic-public-key').nil? || + canonical_uri.nil? || + hub_url.nil? + end - account.uri = get_account_uri(xml) - account.hub_url = hubs.first.attribute('href').value + def webfinger_update_due? + @account.nil? || @account.last_webfingered_at.nil? || @account.last_webfingered_at <= 1.day.ago + end - begin - account.save! - get_profile(body, account) if update_profile - rescue ActiveRecord::RecordNotUnique - # The account has been added by another worker! - return Account.find_remote(confirmed_username, confirmed_domain) - end + def create_account + Rails.logger.debug "Creating new remote account for #{@username}@#{@domain}" - account + @account = Account.new(username: @username, domain: @domain) + @account.suspended = true if auto_suspend? + @account.silenced = true if auto_silence? + @account.private_key = nil end - private + def update_account + @account.last_webfingered_at = Time.now.utc + @account.remote_url = atom_url + @account.salmon_url = salmon_url + @account.url = url + @account.public_key = public_key + @account.uri = canonical_uri + @account.hub_url = hub_url + @account.save! + end + + def auto_suspend? + domain_block && domain_block.suspend? + end + + def auto_silence? + domain_block && domain_block.silence? + end - def account_needs_webfinger_update?(account) - account&.last_webfingered_at.nil? || account.last_webfingered_at <= 1.day.ago + def domain_block + return @domain_block if defined?(@domain_block) + @domain_block = DomainBlock.find_by(domain: @domain) end - def get_feed(url) - response = Request.new(:get, url).perform - raise Goldfinger::Error, "Feed attempt failed for #{url}: HTTP #{response.code}" unless response.code == 200 - [response.to_s, Nokogiri::XML(response)] + def atom_url + @atom_url ||= @webfinger.link('http://schemas.google.com/g/2010#updates-from').href end - def get_hubs(xml) - hubs = xml.xpath('//xmlns:link[@rel="hub"]') - raise Goldfinger::Error, 'No PubSubHubbub hubs found' if hubs.empty? || hubs.first.attribute('href').nil? - hubs + def salmon_url + @salmon_url ||= @webfinger.link('salmon').href end - def get_account_uri(xml) - author_uri = xml.at_xpath('/xmlns:feed/xmlns:author/xmlns:uri') + def url + @url ||= @webfinger.link('http://webfinger.net/rel/profile-page').href + end + + def public_key + @public_key ||= magic_key_to_pem(@webfinger.link('magic-public-key').href) + end + + def canonical_uri + return @canonical_uri if defined?(@canonical_uri) + + author_uri = atom.at_xpath('/xmlns:feed/xmlns:author/xmlns:uri') if author_uri.nil? - owner = xml.at_xpath('/xmlns:feed').at_xpath('./dfrn:owner', dfrn: DFRN_NS) + owner = atom.at_xpath('/xmlns:feed').at_xpath('./dfrn:owner', dfrn: DFRN_NS) author_uri = owner.at_xpath('./xmlns:uri') unless owner.nil? end - raise Goldfinger::Error, 'Author URI could not be found' if author_uri.nil? - author_uri.content + @canonical_uri = author_uri.nil? ? nil : author_uri.content + end + + def hub_url + return @hub_url if defined?(@hub_url) + + hubs = atom.xpath('//xmlns:link[@rel="hub"]') + @hub_url = hubs.empty? || hubs.first['href'].nil? ? nil : hubs.first['href'] + end + + def atom_body + return @atom_body if defined?(@atom_body) + + response = Request.new(:get, atom_url).perform + + raise Mastodon::UnexpectedResponseError, response unless response.code == 200 + + @atom_body = response.to_s + end + + def atom + return @atom if defined?(@atom) + @atom = Nokogiri::XML(atom_body) + end + + def update_account_profile + RemoteProfileUpdateWorker.perform_async(@account.id, atom_body.force_encoding('UTF-8'), false) end - def get_profile(body, account) - RemoteProfileUpdateWorker.perform_async(account.id, body.force_encoding('UTF-8'), false) + def lock_options + { redis: Redis.current, key: "resolve:#{@username}@#{@domain}" } end end diff --git a/app/services/send_interaction_service.rb b/app/services/send_interaction_service.rb index ef38a748b..c11813abc 100644 --- a/app/services/send_interaction_service.rb +++ b/app/services/send_interaction_service.rb @@ -10,11 +10,11 @@ class SendInteractionService < BaseService @source_account = source_account @target_account = target_account - return if block_notification? + return if !target_account.ostatus? || block_notification? delivery = build_request.perform - raise "Delivery failed for #{target_account.salmon_url}: HTTP #{delivery.code}" unless delivery.code > 199 && delivery.code < 300 + raise Mastodon::UnexpectedResponseError, delivery unless delivery.code > 199 && delivery.code < 300 end private diff --git a/app/services/subscribe_service.rb b/app/services/subscribe_service.rb index f58067038..d3e41e691 100644 --- a/app/services/subscribe_service.rb +++ b/app/services/subscribe_service.rb @@ -2,6 +2,8 @@ class SubscribeService < BaseService def call(account) + return unless account.ostatus? + @account = account @account.secret = SecureRandom.hex @response = build_request.perform @@ -16,7 +18,7 @@ class SubscribeService < BaseService else # The response was either a 429 rate limit, or a 5xx error. # We need to retry at a later time. Fail loudly! - raise "Subscription attempt failed for #{@account.acct} (#{@account.hub_url}): HTTP #{@response.code}" + raise Mastodon::UnexpectedResponseError, @response end end diff --git a/app/services/unblock_service.rb b/app/services/unblock_service.rb index 50c2dc2f0..ff15c7275 100644 --- a/app/services/unblock_service.rb +++ b/app/services/unblock_service.rb @@ -11,6 +11,6 @@ class UnblockService < BaseService private def build_xml(block) - Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.unblock_salmon(block)) + OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.unblock_salmon(block)) end end diff --git a/app/services/unfavourite_service.rb b/app/services/unfavourite_service.rb index ede3caad1..564aaee46 100644 --- a/app/services/unfavourite_service.rb +++ b/app/services/unfavourite_service.rb @@ -13,6 +13,6 @@ class UnfavouriteService < BaseService private def build_xml(favourite) - Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.unfavourite_salmon(favourite)) + OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.unfavourite_salmon(favourite)) end end diff --git a/app/services/unfollow_service.rb b/app/services/unfollow_service.rb index 0c9a5f657..388909586 100644 --- a/app/services/unfollow_service.rb +++ b/app/services/unfollow_service.rb @@ -14,6 +14,6 @@ class UnfollowService < BaseService private def build_xml(follow) - Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.unfollow_salmon(follow)) + OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.unfollow_salmon(follow)) end end diff --git a/app/services/unsubscribe_service.rb b/app/services/unsubscribe_service.rb index c2f022d7d..c5e0e73fe 100644 --- a/app/services/unsubscribe_service.rb +++ b/app/services/unsubscribe_service.rb @@ -2,6 +2,8 @@ class UnsubscribeService < BaseService def call(account) + return unless account.ostatus? + @account = account @response = build_request.perform diff --git a/app/views/auth/registrations/_sessions.html.haml b/app/views/auth/registrations/_sessions.html.haml index 4521aad0a..84207862a 100644 --- a/app/views/auth/registrations/_sessions.html.haml +++ b/app/views/auth/registrations/_sessions.html.haml @@ -7,6 +7,7 @@ %th= t 'sessions.browser' %th= t 'sessions.ip' %th= t 'sessions.activity' + %td %tbody - @sessions.each do |session| %tr @@ -22,3 +23,6 @@ = t 'sessions.current_session' - else %time.time-ago{ datetime: session.updated_at.iso8601, title: l(session.updated_at) }= l(session.updated_at) + %td + - if request.session['auth_id'] != session.session_id + = table_link_to 'times', t('sessions.revoke'), settings_session_path(session), method: :delete diff --git a/app/workers/import_worker.rb b/app/workers/import_worker.rb index 90a226206..27cc6b365 100644 --- a/app/workers/import_worker.rb +++ b/app/workers/import_worker.rb @@ -44,7 +44,7 @@ class ImportWorker target_account = ResolveRemoteAccountService.new.call(row.first) next if target_account.nil? MuteService.new.call(from_account, target_account) - rescue Goldfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError + rescue Mastodon::UnexpectedResponseError, HTTP::Error, OpenSSL::SSL::SSLError next end end @@ -56,7 +56,7 @@ class ImportWorker target_account = ResolveRemoteAccountService.new.call(row.first) next if target_account.nil? BlockService.new.call(from_account, target_account) - rescue Goldfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError + rescue Mastodon::UnexpectedResponseError, HTTP::Error, OpenSSL::SSL::SSLError next end end @@ -66,7 +66,7 @@ class ImportWorker import_rows.each do |row| begin FollowService.new.call(from_account, row.first) - rescue Mastodon::NotPermittedError, ActiveRecord::RecordNotFound, Goldfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError + rescue Mastodon::NotPermittedError, ActiveRecord::RecordNotFound, Mastodon::UnexpectedResponseError, HTTP::Error, OpenSSL::SSL::SSLError next end end diff --git a/app/workers/pubsubhubbub/delivery_worker.rb b/app/workers/pubsubhubbub/delivery_worker.rb index 2e1101b93..035a59048 100644 --- a/app/workers/pubsubhubbub/delivery_worker.rb +++ b/app/workers/pubsubhubbub/delivery_worker.rb @@ -23,7 +23,7 @@ class Pubsubhubbub::DeliveryWorker def process_delivery payload_delivery - raise "Delivery failed for #{subscription.callback_url}: HTTP #{payload_delivery.code}" unless response_successful? + raise Mastodon::UnexpectedResponseError, payload_delivery unless response_successful? subscription.touch(:last_successful_delivery_at) end diff --git a/app/workers/pubsubhubbub/distribution_worker.rb b/app/workers/pubsubhubbub/distribution_worker.rb index 9c1fa76cb..ce467d18b 100644 --- a/app/workers/pubsubhubbub/distribution_worker.rb +++ b/app/workers/pubsubhubbub/distribution_worker.rb @@ -22,7 +22,7 @@ class Pubsubhubbub::DistributionWorker def distribute_public!(stream_entries) return if stream_entries.empty? - @payload = Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.feed(@account, stream_entries)) + @payload = OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.feed(@account, stream_entries)) Pubsubhubbub::DeliveryWorker.push_bulk(@subscriptions) do |subscription| [subscription.id, @payload] @@ -32,7 +32,7 @@ class Pubsubhubbub::DistributionWorker def distribute_hidden!(stream_entries) return if stream_entries.empty? - @payload = Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.feed(@account, stream_entries)) + @payload = OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.feed(@account, stream_entries)) @domains = @account.followers.domains Pubsubhubbub::DeliveryWorker.push_bulk(@subscriptions.reject { |s| !allowed_to_receive?(s.callback_url, s.domain) }) do |subscription| |