From b11ac88692ad7a8765b0b15e6d7a882d171ffe81 Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Tue, 18 Jul 2017 07:19:02 +0900 Subject: [PATCH 01/16] Require any modules after loading polyfill in entry points (#4231) app/javascript/mastodon/main.js delayed the execution of modules, but other entry points didn't. That leads to failure in executing modules, which requires those polyfills. Strictly enforce the rule to require any modules after loading polyfill in entry points. --- app/javascript/mastodon/main.js | 11 ++--- app/javascript/packs/about.js | 8 +-- app/javascript/packs/application.js | 5 +- app/javascript/packs/public.js | 75 ++++++++++++++--------------- 4 files changed, 49 insertions(+), 50 deletions(-) diff --git a/app/javascript/mastodon/main.js b/app/javascript/mastodon/main.js index cc422c109..a7fc22a00 100644 --- a/app/javascript/mastodon/main.js +++ b/app/javascript/mastodon/main.js @@ -1,12 +1,14 @@ +import * as OfflinePluginRuntime from 'offline-plugin/runtime'; +import * as WebPushSubscription from './web_push_subscription'; +import Mastodon from 'mastodon/containers/mastodon'; +import React from 'react'; +import ReactDOM from 'react-dom'; import ready from './ready'; const perf = require('./performance'); function main() { perf.start('main()'); - const Mastodon = require('mastodon/containers/mastodon').default; - const React = require('react'); - const ReactDOM = require('react-dom'); if (window.history && history.replaceState) { const { pathname, search, hash } = window.location; @@ -23,9 +25,6 @@ function main() { ReactDOM.render(, mountNode); if (process.env.NODE_ENV === 'production') { // avoid offline in dev mode because it's harder to debug - const OfflinePluginRuntime = require('offline-plugin/runtime'); - const WebPushSubscription = require('./web_push_subscription'); - OfflinePluginRuntime.install(); WebPushSubscription.register(); } diff --git a/app/javascript/packs/about.js b/app/javascript/packs/about.js index 7b8ab5e5d..6705377c1 100644 --- a/app/javascript/packs/about.js +++ b/app/javascript/packs/about.js @@ -1,12 +1,11 @@ -import TimelineContainer from '../mastodon/containers/timeline_container'; -import React from 'react'; -import ReactDOM from 'react-dom'; import loadPolyfills from '../mastodon/load_polyfills'; -import ready from '../mastodon/ready'; require.context('../images/', true); function loaded() { + const TimelineContainer = require('../mastodon/containers/timeline_container').default; + const React = require('react'); + const ReactDOM = require('react-dom'); const mountNode = document.getElementById('mastodon-timeline'); if (mountNode !== null) { @@ -16,6 +15,7 @@ function loaded() { } function main() { + const ready = require('../mastodon/ready').default; ready(loaded); } diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 63c5d6272..116632dea 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -1,6 +1,7 @@ -import main from '../mastodon/main'; import loadPolyfills from '../mastodon/load_polyfills'; -loadPolyfills().then(main).catch(e => { +loadPolyfills().then(() => { + require('../mastodon/main').default(); +}).catch(e => { console.error(e); }); diff --git a/app/javascript/packs/public.js b/app/javascript/packs/public.js index 371e0f445..ce79836d6 100644 --- a/app/javascript/packs/public.js +++ b/app/javascript/packs/public.js @@ -1,44 +1,43 @@ -import { length } from 'stringz'; -import IntlRelativeFormat from 'intl-relativeformat'; -import { delegate } from 'rails-ujs'; -import emojify from '../mastodon/emoji'; -import { getLocale } from '../mastodon/locales'; import loadPolyfills from '../mastodon/load_polyfills'; -import ready from '../mastodon/ready'; - -const { localeData } = getLocale(); -localeData.forEach(IntlRelativeFormat.__addLocaleData); - -function loaded() { - const locale = document.documentElement.lang; - const dateTimeFormat = new Intl.DateTimeFormat(locale, { - year: 'numeric', - month: 'long', - day: 'numeric', - hour: 'numeric', - minute: 'numeric', - }); - const relativeFormat = new IntlRelativeFormat(locale); - - [].forEach.call(document.querySelectorAll('.emojify'), (content) => { - content.innerHTML = emojify(content.innerHTML); - }); - - [].forEach.call(document.querySelectorAll('time.formatted'), (content) => { - const datetime = new Date(content.getAttribute('datetime')); - const formattedDate = dateTimeFormat.format(datetime); - content.title = formattedDate; - content.textContent = formattedDate; - }); - - [].forEach.call(document.querySelectorAll('time.time-ago'), (content) => { - const datetime = new Date(content.getAttribute('datetime')); - content.textContent = relativeFormat.format(datetime);; - }); -} function main() { - ready(loaded); + const { length } = require('stringz'); + const IntlRelativeFormat = require('intl-relativeformat').default; + const { delegate } = require('rails-ujs'); + const emojify = require('../mastodon/emoji').default; + const { getLocale } = require('../mastodon/locales'); + const ready = require('../mastodon/ready').default; + + const { localeData } = getLocale(); + localeData.forEach(IntlRelativeFormat.__addLocaleData); + + ready(() => { + const locale = document.documentElement.lang; + const dateTimeFormat = new Intl.DateTimeFormat(locale, { + year: 'numeric', + month: 'long', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + }); + const relativeFormat = new IntlRelativeFormat(locale); + + [].forEach.call(document.querySelectorAll('.emojify'), (content) => { + content.innerHTML = emojify(content.innerHTML); + }); + + [].forEach.call(document.querySelectorAll('time.formatted'), (content) => { + const datetime = new Date(content.getAttribute('datetime')); + const formattedDate = dateTimeFormat.format(datetime); + content.title = formattedDate; + content.textContent = formattedDate; + }); + + [].forEach.call(document.querySelectorAll('time.time-ago'), (content) => { + const datetime = new Date(content.getAttribute('datetime')); + content.textContent = relativeFormat.format(datetime);; + }); + }); delegate(document, '.video-player video', 'click', ({ target }) => { if (target.paused) { From 719ab720a7286c4968f1b42e1be385f5580de13e Mon Sep 17 00:00:00 2001 From: Sorin Davidoi Date: Tue, 18 Jul 2017 00:19:17 +0200 Subject: [PATCH 02/16] feat(push-notifications): Open link in current tab if possible (#4228) * fix(push-notification): Open link in current tab if possible * feat(sw): Skip waiting and claim clients --- .../mastodon/service_worker/entry.js | 9 +++++++++ .../service_worker/web_push_notifications.js | 20 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/javascript/mastodon/service_worker/entry.js b/app/javascript/mastodon/service_worker/entry.js index 364b67066..eea4cfc3c 100644 --- a/app/javascript/mastodon/service_worker/entry.js +++ b/app/javascript/mastodon/service_worker/entry.js @@ -1 +1,10 @@ import './web_push_notifications'; + +// Cause a new version of a registered Service Worker to replace an existing one +// that is already installed, and replace the currently active worker on open pages. +self.addEventListener('install', function(event) { + event.waitUntil(self.skipWaiting()); +}); +self.addEventListener('activate', function(event) { + event.waitUntil(self.clients.claim()); +}); diff --git a/app/javascript/mastodon/service_worker/web_push_notifications.js b/app/javascript/mastodon/service_worker/web_push_notifications.js index 1708aa9f7..4a8a57767 100644 --- a/app/javascript/mastodon/service_worker/web_push_notifications.js +++ b/app/javascript/mastodon/service_worker/web_push_notifications.js @@ -50,6 +50,24 @@ const makeRequest = (notification, action) => credentials: 'include', }); +const openUrl = url => + self.clients.matchAll({ type: 'window' }).then(clientList => { + if (clientList.length !== 0 && 'navigate' in clientList[0]) { // Chrome 42-48 does not support navigate + const webClients = clientList + .filter(client => /\/web\//.test(client.url)) + .sort(client => client !== 'visible'); + + const visibleClient = clientList.find(client => client.visibilityState === 'visible'); + const focusedClient = clientList.find(client => client.focused); + + const client = webClients[0] || visibleClient || focusedClient || clientList[0]; + + return client.navigate(url).then(client => client.focus()); + } else { + return self.clients.openWindow(url); + } + }); + const removeActionFromNotification = (notification, action) => { const actions = notification.actions.filter(act => act.action !== action.action); @@ -75,7 +93,7 @@ const handleNotificationClick = (event) => { } } else { event.notification.close(); - resolve(self.clients.openWindow(event.notification.data.url)); + resolve(openUrl(event.notification.data.url)); } }); From 7f4375822a869bac55eb9dd9884e7803695aed82 Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Tue, 18 Jul 2017 07:31:43 +0900 Subject: [PATCH 03/16] Install libidn11-dev in Vagrant (#4238) --- Vagrantfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Vagrantfile b/Vagrantfile index cbe6623b3..0c21bed68 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -35,9 +35,10 @@ sudo apt-get install \ postgresql-contrib \ protobuf-compiler \ yarn \ + libicu-dev \ + libidn11-dev \ libprotobuf-dev \ libreadline-dev \ - libicu-dev \ -y # Install rvm From 407073d7a2557bb0da42472b822c664863bcc7fc Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Tue, 18 Jul 2017 22:19:49 +0900 Subject: [PATCH 04/16] Move icu-dev to build-dependencies (#4240) --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8cd374481..760999f8c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,7 @@ RUN echo "@edge https://nl.alpinelinux.org/alpine/edge/main" >> /etc/apk/reposit && apk -U upgrade \ && apk add -t build-dependencies \ build-base \ + icu-dev \ libidn-dev \ libxml2-dev \ libxslt-dev \ @@ -26,7 +27,7 @@ RUN echo "@edge https://nl.alpinelinux.org/alpine/edge/main" >> /etc/apk/reposit ffmpeg \ file \ git \ - icu-dev \ + icu-libs \ imagemagick@edge \ libidn \ libpq \ From f5382ec08504a06c005e8f40738596c5c5c837de Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Tue, 18 Jul 2017 22:20:38 +0900 Subject: [PATCH 05/16] Exclude self toots from regular expression filter (#4245) * Exclude self toots from regular expression filter * refactor --- .../ui/containers/status_list_container.js | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/app/javascript/mastodon/features/ui/containers/status_list_container.js b/app/javascript/mastodon/features/ui/containers/status_list_container.js index 1b2e1056a..ff29bfdd4 100644 --- a/app/javascript/mastodon/features/ui/containers/status_list_container.js +++ b/app/javascript/mastodon/features/ui/containers/status_list_container.js @@ -10,31 +10,36 @@ const makeGetStatusIds = () => createSelector([ (state, { type }) => state.getIn(['timelines', type, 'items'], ImmutableList()), (state) => state.get('statuses'), (state) => state.getIn(['meta', 'me']), -], (columnSettings, statusIds, statuses, me) => statusIds.filter(id => { - const statusForId = statuses.get(id); - let showStatus = true; +], (columnSettings, statusIds, statuses, me) => { + const rawRegex = columnSettings.getIn(['regex', 'body'], '').trim(); + let regex = null; - if (columnSettings.getIn(['shows', 'reblog']) === false) { - showStatus = showStatus && statusForId.get('reblog') === null; + try { + regex = rawRegex && new RegExp(rawRegex, 'i'); + } catch (e) { + // Bad regex, don't affect filters } - if (columnSettings.getIn(['shows', 'reply']) === false) { - showStatus = showStatus && (statusForId.get('in_reply_to_id') === null || statusForId.get('in_reply_to_account_id') === me); - } + return statusIds.filter(id => { + const statusForId = statuses.get(id); + let showStatus = true; - if (columnSettings.getIn(['regex', 'body'], '').trim().length > 0) { - try { - if (showStatus) { - const regex = new RegExp(columnSettings.getIn(['regex', 'body']).trim(), 'i'); - showStatus = !regex.test(statusForId.get('reblog') ? statuses.getIn([statusForId.get('reblog'), 'search_index']) : statusForId.get('search_index')); - } - } catch(e) { - // Bad regex, don't affect filters + if (columnSettings.getIn(['shows', 'reblog']) === false) { + showStatus = showStatus && statusForId.get('reblog') === null; } - } - return showStatus; -})); + if (columnSettings.getIn(['shows', 'reply']) === false) { + showStatus = showStatus && (statusForId.get('in_reply_to_id') === null || statusForId.get('in_reply_to_account_id') === me); + } + + if (showStatus && regex && statusForId.get('account') !== me) { + const searchIndex = statusForId.get('reblog') ? statuses.getIn([statusForId.get('reblog'), 'search_index']) : statusForId.get('search_index'); + showStatus = !regex.test(searchIndex); + } + + return showStatus; + }); +}); const makeMapStateToProps = () => { const getStatusIds = makeGetStatusIds(); From c0c7af2194cffcddbbcab5879f37afca3eb0bcec Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Tue, 18 Jul 2017 22:21:30 +0900 Subject: [PATCH 06/16] Download npm and yarn from Alpine packages repository (#4242) --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 760999f8c..ef139dcec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,7 @@ EXPOSE 3000 4000 WORKDIR /mastodon RUN echo "@edge https://nl.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \ + && echo "@edge https://nl.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \ && apk -U upgrade \ && apk add -t build-dependencies \ build-base \ @@ -38,7 +39,7 @@ RUN echo "@edge https://nl.alpinelinux.org/alpine/edge/main" >> /etc/apk/reposit protobuf \ su-exec \ tini \ - && npm install -g npm@3 && npm install -g yarn \ + yarn@edge \ && update-ca-certificates \ && rm -rf /tmp/* /var/cache/apk/* From 8949aad030f47b89397ecb371f0464926286ab8f Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Tue, 18 Jul 2017 22:22:09 +0900 Subject: [PATCH 07/16] Add empty alt attribute to img elements in landing page (#4243) --- app/views/about/show.html.haml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/views/about/show.html.haml b/app/views/about/show.html.haml index fd468bba0..0af47bde3 100644 --- a/app/views/about/show.html.haml +++ b/app/views/about/show.html.haml @@ -18,13 +18,13 @@ .landing-page .header-wrapper .mascot-container - = image_tag asset_pack_path('elephant-fren.png'), class: 'mascot' + = image_tag asset_pack_path('elephant-fren.png'), alt: '', role: 'presentation', class: 'mascot' .header .container.links .brand = link_to root_url do - = image_tag asset_pack_path('logo.svg') + = image_tag asset_pack_path('logo.svg'), alt: '', role: 'presentation' Mastodon %ul.nav @@ -38,9 +38,9 @@ .container.hero .floats - = image_tag asset_pack_path('cloud2.png'), class: 'float-1' - = image_tag asset_pack_path('cloud3.png'), class: 'float-2' - = image_tag asset_pack_path('cloud4.png'), class: 'float-3' + = image_tag asset_pack_path('cloud2.png'), alt: '', role: 'presentation', class: 'float-1' + = image_tag asset_pack_path('cloud3.png'), alt: '', role: 'presentation', class: 'float-2' + = image_tag asset_pack_path('cloud4.png'), alt: '', role: 'presentation', class: 'float-3' .heading %h1 = @instance_presenter.site_title @@ -54,7 +54,7 @@ %p= t('about.closed_registrations') - else = @instance_presenter.closed_registrations_message.html_safe - = link_to t('about.find_another_instance'), 'https://joinmastodon.org', class: 'button button-alternative button--block' + = link_to t('about.find_another_instance'), 'https://joinmastodon.org/', class: 'button button-alternative button--block' .learn-more-cta .container @@ -69,7 +69,7 @@ .about-mastodon %h3= t 'about.what_is_mastodon' %p= t 'about.about_mastodon_html' - %a.button.button-secondary{ href: 'https://joinmastodon.org' }= t 'about.learn_more' + %a.button.button-secondary{ href: 'https://joinmastodon.org/' }= t 'about.learn_more' = render 'features' .footer-links .container From afa52e4d636f8fdc4b21b90e4f006d8ea434b4e9 Mon Sep 17 00:00:00 2001 From: abcang Date: Tue, 18 Jul 2017 22:24:57 +0900 Subject: [PATCH 08/16] Fixed issue that the NSFW image is not hidden on detail page (#4244) --- app/javascript/mastodon/components/media_gallery.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/javascript/mastodon/components/media_gallery.js b/app/javascript/mastodon/components/media_gallery.js index 89a358e38..92d7d494e 100644 --- a/app/javascript/mastodon/components/media_gallery.js +++ b/app/javascript/mastodon/components/media_gallery.js @@ -183,6 +183,12 @@ export default class MediaGallery extends React.PureComponent { visible: !this.props.sensitive, }; + componentWillReceiveProps (nextProps) { + if (nextProps.sensitive !== this.props.sensitive) { + this.setState({ visible: !nextProps.sensitive }); + } + } + handleOpen = () => { this.setState({ visible: !this.state.visible }); } From 8387b3928ec7658192907da79df65e65aaa8a7fc Mon Sep 17 00:00:00 2001 From: Sorin Davidoi Date: Tue, 18 Jul 2017 16:25:40 +0200 Subject: [PATCH 09/16] fix(push-subscriptions): Refactor how Sidekiq jobs are handled (#4226) --- app/models/web/push_subscription.rb | 8 +++++--- app/services/notify_service.rb | 6 +++++- app/workers/web_push_notification_worker.rb | 22 +++++++++------------ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/models/web/push_subscription.rb b/app/models/web/push_subscription.rb index 4440706a6..baf6a1ece 100644 --- a/app/models/web/push_subscription.rb +++ b/app/models/web/push_subscription.rb @@ -12,6 +12,9 @@ # updated_at :datetime not null # +require 'webpush' +require_relative '../../models/setting' + class Web::PushSubscription < ApplicationRecord include RoutingHelper include StreamEntriesHelper @@ -37,7 +40,6 @@ class Web::PushSubscription < ApplicationRecord nsfw = notification.target_status.nil? || notification.target_status.spoiler_text.empty? ? nil : notification.target_status.spoiler_text # TODO: Make sure that the payload does not exceed 4KB - Webpush::PayloadTooLarge - # TODO: Queue the requests - Webpush::TooManyRequests Webpush.payload_send( message: JSON.generate( title: title, @@ -59,7 +61,7 @@ class Web::PushSubscription < ApplicationRecord p256dh: key_p256dh, auth: key_auth, vapid: { - # subject: "mailto:#{Setting.site_contact_email}", + subject: "mailto:#{Setting.site_contact_email}", private_key: Rails.configuration.x.vapid_private_key, public_key: Rails.configuration.x.vapid_public_key, }, @@ -166,7 +168,7 @@ class Web::PushSubscription < ApplicationRecord p256dh: key_p256dh, auth: key_auth, vapid: { - # subject: "mailto:#{Setting.site_contact_email}", + subject: "mailto:#{Setting.site_contact_email}", private_key: Rails.configuration.x.vapid_private_key, public_key: Rails.configuration.x.vapid_public_key, }, diff --git a/app/services/notify_service.rb b/app/services/notify_service.rb index 0ab61b634..c7d8ad50a 100644 --- a/app/services/notify_service.rb +++ b/app/services/notify_service.rb @@ -65,7 +65,11 @@ class NotifyService < BaseService end def send_push_notifications - WebPushNotificationWorker.perform_async(@recipient.id, @notification.id) + sessions_with_subscriptions_ids = @recipient.user.session_activations.where.not(web_push_subscription: nil).pluck(:id) + + WebPushNotificationWorker.push_bulk(sessions_with_subscriptions_ids) do |session_activation_id| + [session_activation_id, @notification.id] + end end def send_email diff --git a/app/workers/web_push_notification_worker.rb b/app/workers/web_push_notification_worker.rb index e8f1d72bd..da4043ddb 100644 --- a/app/workers/web_push_notification_worker.rb +++ b/app/workers/web_push_notification_worker.rb @@ -5,22 +5,18 @@ class WebPushNotificationWorker sidekiq_options backtrace: true - def perform(recipient_id, notification_id) - recipient = Account.find(recipient_id) + def perform(session_activation_id, notification_id) + session_activation = SessionActivation.find(session_activation_id) notification = Notification.find(notification_id) - sessions_with_subscriptions = recipient.user.session_activations.where.not(web_push_subscription: nil) + begin + session_activation.web_push_subscription.push(notification) + rescue Webpush::InvalidSubscription, Webpush::ExpiredSubscription => e + # Subscription expiration is not currently implemented in any browser + session_activation.web_push_subscription.destroy! + session_activation.update!(web_push_subscription: nil) - sessions_with_subscriptions.each do |session| - begin - session.web_push_subscription.push(notification) - rescue Webpush::InvalidSubscription, Webpush::ExpiredSubscription - # Subscription expiration is not currently implemented in any browser - session.web_push_subscription.destroy! - session.update!(web_push_subscription: nil) - rescue Webpush::PayloadTooLarge => e - Rails.logger.error(e) - end + raise e end end end From 4d42a389540690b32886f2a38af1f86aee617d27 Mon Sep 17 00:00:00 2001 From: abcang Date: Tue, 18 Jul 2017 23:38:22 +0900 Subject: [PATCH 10/16] Improve admin page (#4121) * Improve admin page * Fix test * Add spec * Improve select style --- .../admin/reported_statuses_controller.rb | 15 ++- app/controllers/admin/reports_controller.rb | 4 +- app/controllers/admin/statuses_controller.rb | 69 +++++++++++ app/javascript/packs/admin.js | 40 +++++++ app/javascript/styles/admin.scss | 45 +++++++- app/models/form/status_batch.rb | 39 +++++++ app/views/admin/accounts/show.html.haml | 4 +- app/views/admin/reports/show.html.haml | 34 ++++-- app/views/admin/statuses/index.html.haml | 47 ++++++++ config/locales/en.yml | 15 +++ config/locales/ja.yml | 15 +++ config/routes.rb | 3 +- .../reported_statuses_controller_spec.rb | 38 ++++++- .../admin/statuses_controller_spec.rb | 107 ++++++++++++++++++ spec/models/form/status_batch_spec.rb | 52 +++++++++ 15 files changed, 508 insertions(+), 19 deletions(-) create mode 100644 app/controllers/admin/statuses_controller.rb create mode 100644 app/javascript/packs/admin.js create mode 100644 app/models/form/status_batch.rb create mode 100644 app/views/admin/statuses/index.html.haml create mode 100644 spec/controllers/admin/statuses_controller_spec.rb create mode 100644 spec/models/form/status_batch_spec.rb diff --git a/app/controllers/admin/reported_statuses_controller.rb b/app/controllers/admin/reported_statuses_controller.rb index 32434d30f..5a31adecf 100644 --- a/app/controllers/admin/reported_statuses_controller.rb +++ b/app/controllers/admin/reported_statuses_controller.rb @@ -5,7 +5,14 @@ module Admin include Authorization before_action :set_report - before_action :set_status + before_action :set_status, only: [:update, :destroy] + + def create + @form = Form::StatusBatch.new(form_status_batch_params) + flash[:alert] = t('admin.statuses.failed_to_execute') unless @form.save + + redirect_to admin_report_path(@report) + end def update @status.update(status_params) @@ -15,7 +22,7 @@ module Admin def destroy authorize @status, :destroy? RemovalWorker.perform_async(@status.id) - redirect_to admin_report_path(@report) + render json: @status end private @@ -24,6 +31,10 @@ module Admin params.require(:status).permit(:sensitive) end + def form_status_batch_params + params.require(:form_status_batch).permit(:action, status_ids: []) + end + def set_report @report = Report.find(params[:report_id]) end diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb index 2d8c3c820..226467739 100644 --- a/app/controllers/admin/reports_controller.rb +++ b/app/controllers/admin/reports_controller.rb @@ -8,7 +8,9 @@ module Admin @reports = filtered_reports.page(params[:page]) end - def show; end + def show + @form = Form::StatusBatch.new + end def update process_report diff --git a/app/controllers/admin/statuses_controller.rb b/app/controllers/admin/statuses_controller.rb new file mode 100644 index 000000000..50712f0dd --- /dev/null +++ b/app/controllers/admin/statuses_controller.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +module Admin + class StatusesController < BaseController + include Authorization + + helper_method :current_params + + before_action :set_account + before_action :set_status, only: [:update, :destroy] + + PAR_PAGE = 20 + + def index + @statuses = @account.statuses + if params[:media] + account_media_status_ids = @account.media_attachments.attached.reorder(nil).select(:status_id).distinct + @statuses.merge!(Status.where(id: account_media_status_ids)) + end + @statuses = @statuses.preload(:media_attachments, :mentions).page(params[:page]).per(PAR_PAGE) + + @form = Form::StatusBatch.new + end + + def create + @form = Form::StatusBatch.new(form_status_batch_params) + flash[:alert] = t('admin.statuses.failed_to_execute') unless @form.save + + redirect_to admin_account_statuses_path(@account.id, current_params) + end + + def update + @status.update(status_params) + redirect_to admin_account_statuses_path(@account.id, current_params) + end + + def destroy + authorize @status, :destroy? + RemovalWorker.perform_async(@status.id) + render json: @status + end + + private + + def status_params + params.require(:status).permit(:sensitive) + end + + def form_status_batch_params + params.require(:form_status_batch).permit(:action, status_ids: []) + end + + def set_status + @status = @account.statuses.find(params[:id]) + end + + def set_account + @account = Account.find(params[:account_id]) + end + + def current_params + page = (params[:page] || 1).to_i + { + media: params[:media], + page: page > 1 && page, + }.select { |_, value| value.present? } + end + end +end diff --git a/app/javascript/packs/admin.js b/app/javascript/packs/admin.js new file mode 100644 index 000000000..993827db5 --- /dev/null +++ b/app/javascript/packs/admin.js @@ -0,0 +1,40 @@ +import { delegate } from 'rails-ujs'; + +function handleDeleteStatus(event) { + const [data] = event.detail; + const element = document.querySelector(`[data-id="${data.id}"]`); + if (element) { + element.parentNode.removeChild(element); + } +} + +[].forEach.call(document.querySelectorAll('.trash-button'), (content) => { + content.addEventListener('ajax:success', handleDeleteStatus); +}); + +const batchCheckboxClassName = '.batch-checkbox input[type="checkbox"]'; + +delegate(document, '#batch_checkbox_all', 'change', ({ target }) => { + [].forEach.call(document.querySelectorAll(batchCheckboxClassName), (content) => { + content.checked = target.checked; + }); +}); + +delegate(document, batchCheckboxClassName, 'change', () => { + const checkAllElement = document.querySelector('#batch_checkbox_all'); + if (checkAllElement) { + checkAllElement.checked = [].every.call(document.querySelectorAll(batchCheckboxClassName), (content) => content.checked); + } +}); + +delegate(document, '.media-spoiler-show-button', 'click', () => { + [].forEach.call(document.querySelectorAll('.activity-stream .media-spoiler-wrapper'), (content) => { + content.classList.add('media-spoiler-wrapper__visible'); + }); +}); + +delegate(document, '.media-spoiler-hide-button', 'click', () => { + [].forEach.call(document.querySelectorAll('.activity-stream .media-spoiler-wrapper'), (content) => { + content.classList.remove('media-spoiler-wrapper__visible'); + }); +}); diff --git a/app/javascript/styles/admin.scss b/app/javascript/styles/admin.scss index 3bc713566..4c3bbdfc5 100644 --- a/app/javascript/styles/admin.scss +++ b/app/javascript/styles/admin.scss @@ -253,7 +253,8 @@ } } -.report-status { +.report-status, +.account-status { display: flex; margin-bottom: 10px; @@ -263,7 +264,8 @@ } } -.report-status__actions { +.report-status__actions, +.account-status__actions { flex: 0 0 auto; display: flex; flex-direction: column; @@ -275,3 +277,42 @@ margin-bottom: 10px; } } + +.batch-form-box { + display: flex; + margin-bottom: 10px; + + #form_status_batch_action { + margin-right: 5px; + font-size: 14px; + } + + .media-spoiler-toggle-buttons { + margin-left: auto; + + .button { + overflow: visible; + } + } +} + +.batch-checkbox, +.batch-checkbox-all { + display: flex; + align-items: center; + margin-right: 5px; +} + +.back-link { + margin-bottom: 10px; + font-size: 14px; + + a { + color: $classic-highlight-color; + text-decoration: none; + + &:hover { + text-decoration: underline; + } + } +} diff --git a/app/models/form/status_batch.rb b/app/models/form/status_batch.rb new file mode 100644 index 000000000..a97b4aa28 --- /dev/null +++ b/app/models/form/status_batch.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +class Form::StatusBatch + include ActiveModel::Model + + attr_accessor :status_ids, :action + + ACTION_TYPE = %w(nsfw_on nsfw_off delete).freeze + + def save + case action + when 'nsfw_on', 'nsfw_off' + change_sensitive(action == 'nsfw_on') + when 'delete' + delete_statuses + end + end + + private + + def change_sensitive(sensitive) + media_attached_status_ids = MediaAttachment.where(status_id: status_ids).pluck(:status_id) + ApplicationRecord.transaction do + Status.where(id: media_attached_status_ids).find_each do |status| + status.update!(sensitive: sensitive) + end + end + true + rescue ActiveRecord::RecordInvalid + false + end + + def delete_statuses + Status.where(id: status_ids).find_each do |status| + RemovalWorker.perform_async(status.id) + end + true + end +end diff --git a/app/views/admin/accounts/show.html.haml b/app/views/admin/accounts/show.html.haml index d91ba9c78..5ad1fd6ee 100644 --- a/app/views/admin/accounts/show.html.haml +++ b/app/views/admin/accounts/show.html.haml @@ -53,11 +53,11 @@ %td= @account.followers_count %tr %th= t('admin.accounts.statuses') - %td= @account.statuses_count + %td= link_to @account.statuses_count, admin_account_statuses_path(@account.id) %tr %th= t('admin.accounts.media_attachments') %td - = @account.media_attachments.count + = link_to @account.media_attachments.count, admin_account_statuses_path(@account.id, { media: true }) = surround '(', ')' do = number_to_human_size @account.media_attachments.sum('file_file_size') %tr diff --git a/app/views/admin/reports/show.html.haml b/app/views/admin/reports/show.html.haml index 44486cb42..5747cc274 100644 --- a/app/views/admin/reports/show.html.haml +++ b/app/views/admin/reports/show.html.haml @@ -1,3 +1,6 @@ +- content_for :header_tags do + = javascript_pack_tag 'admin', integrity: true, async: true, crossorigin: 'anonymous' + - content_for :page_title do = t('admin.reports.report', id: @report.id) @@ -19,16 +22,27 @@ - unless @report.statuses.empty? %hr/ - - @report.statuses.each do |status| - .report-status - .activity-stream.activity-stream-headless - .entry= render 'stream_entries/simple_status', status: status - .report-status__actions - - unless status.media_attachments.empty? - = link_to admin_report_reported_status_path(@report, status, status: { sensitive: !status.sensitive }), method: :patch, class: 'icon-button nsfw-button', title: t("admin.reports.nsfw.#{!status.sensitive}") do - = fa_icon status.sensitive? ? 'eye' : 'eye-slash' - = link_to admin_report_reported_status_path(@report, status), method: :delete, class: 'icon-button trash-button', title: t('admin.reports.delete'), data: { confirm: t('admin.reports.are_you_sure') } do - = fa_icon 'trash' + = form_for(@form, url: admin_report_reported_statuses_path(@report.id)) do |f| + .batch-form-box + .batch-checkbox-all + = check_box_tag :batch_checkbox_all, nil, false + = f.select :action, Form::StatusBatch::ACTION_TYPE.map{|action| [t("admin.statuses.batch.#{action}"), action]} + = f.submit t('admin.statuses.execute'), data: { confirm: t('admin.reports.are_you_sure') }, class: 'button' + .media-spoiler-toggle-buttons + .media-spoiler-show-button.button= t('admin.statuses.media.show') + .media-spoiler-hide-button.button= t('admin.statuses.media.hide') + - @report.statuses.each do |status| + .report-status{ data: { id: status.id } } + .batch-checkbox + = f.check_box :status_ids, { multiple: true, include_hidden: false }, status.id + .activity-stream.activity-stream-headless + .entry= render 'stream_entries/simple_status', status: status + .report-status__actions + - unless status.media_attachments.empty? + = link_to admin_report_reported_status_path(@report, status, status: { sensitive: !status.sensitive }), method: :put, class: 'icon-button nsfw-button', title: t("admin.reports.nsfw.#{!status.sensitive}") do + = fa_icon status.sensitive? ? 'eye' : 'eye-slash' + = link_to admin_report_reported_status_path(@report, status), method: :delete, class: 'icon-button trash-button', title: t('admin.reports.delete'), data: { confirm: t('admin.reports.are_you_sure') }, remote: true do + = fa_icon 'trash' %hr/ diff --git a/app/views/admin/statuses/index.html.haml b/app/views/admin/statuses/index.html.haml new file mode 100644 index 000000000..fe2581527 --- /dev/null +++ b/app/views/admin/statuses/index.html.haml @@ -0,0 +1,47 @@ +- content_for :header_tags do + = javascript_pack_tag 'admin', integrity: true, async: true, crossorigin: 'anonymous' + +- content_for :page_title do + = t('admin.statuses.title') + +.back-link + = link_to admin_account_path(@account.id) do + %i.fa.fa-chevron-left.fa-fw + = t('admin.statuses.back_to_account') + +.filters + .filter-subset + %strong= t('admin.statuses.media.title') + %ul + %li= link_to t('admin.statuses.no_media'), admin_account_statuses_path(@account.id, current_params.merge(media: nil)), class: !params[:media] && 'selected' + %li= link_to t('admin.statuses.with_media'), admin_account_statuses_path(@account.id, current_params.merge(media: true)), class: params[:media] && 'selected' + +- if @statuses.empty? + .accounts-grid + = render 'accounts/nothing_here' +- else + = form_for(@form, url: admin_account_statuses_path(@account.id)) do |f| + = hidden_field_tag :page, params[:page] + = hidden_field_tag :media, params[:media] + .batch-form-box + .batch-checkbox-all + = check_box_tag :batch_checkbox_all, nil, false + = f.select :action, Form::StatusBatch::ACTION_TYPE.map{|action| [t("admin.statuses.batch.#{action}"), action]} + = f.submit t('admin.statuses.execute'), data: { confirm: t('admin.reports.are_you_sure') }, class: 'button' + .media-spoiler-toggle-buttons + .media-spoiler-show-button.button= t('admin.statuses.media.show') + .media-spoiler-hide-button.button= t('admin.statuses.media.hide') + - @statuses.each do |status| + .account-status{ data: { id: status.id } } + .batch-checkbox + = f.check_box :status_ids, { multiple: true, include_hidden: false }, status.id + .activity-stream.activity-stream-headless + .entry= render 'stream_entries/simple_status', status: status + .account-status__actions + - unless status.media_attachments.empty? + = link_to admin_account_status_path(@account.id, status, current_params.merge(status: { sensitive: !status.sensitive })), method: :patch, class: 'icon-button nsfw-button', title: t("admin.reports.nsfw.#{!status.sensitive}") do + = fa_icon status.sensitive? ? 'eye' : 'eye-slash' + = link_to admin_account_status_path(@account.id, status), method: :delete, class: 'icon-button trash-button', title: t('admin.reports.delete'), data: { confirm: t('admin.reports.are_you_sure') }, remote: true do + = fa_icon 'trash' + += paginate @statuses diff --git a/config/locales/en.yml b/config/locales/en.yml index be1f15e25..4cb536223 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -185,6 +185,21 @@ en: desc_html: Display public timeline on landing page title: Timeline preview title: Site Settings + statuses: + back_to_account: Back to account page + batch: + delete: Delete + nsfw_off: NSFW OFF + nsfw_on: NSFW ON + execute: Execute + failed_to_execute: Failed to execute + media: + hide: Hide media + show: Show media + title: Media + no_media: No media + with_media: With media + title: Account statuses subscriptions: callback_url: Callback URL confirmed: Confirmed diff --git a/config/locales/ja.yml b/config/locales/ja.yml index fda87526d..2897e864f 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -171,6 +171,21 @@ ja: desc_html: ランディングページに公開タイムラインを表示します title: タイムラインプレビュー title: サイト設定 + statuses: + back_to_account: アカウントページに戻る + batch: + delete: 削除 + nsfw_off: NSFW オフ + nsfw_on: NSFW オン + execute: 実行 + failed_to_execute: 実行に失敗しました + media: + hide: メディアを隠す + show: メディアを表示 + title: メディア + no_media: メディアなし + with_media: メディアあり + title: トゥート一覧 subscriptions: callback_url: コールバックURL confirmed: 確認済み diff --git a/config/routes.rb b/config/routes.rb index dda3534eb..60234a9e6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -89,7 +89,7 @@ Rails.application.routes.draw do resources :instances, only: [:index] resources :reports, only: [:index, :show, :update] do - resources :reported_statuses, only: [:update, :destroy] + resources :reported_statuses, only: [:create, :update, :destroy] end resources :accounts, only: [:index, :show] do @@ -103,6 +103,7 @@ Rails.application.routes.draw do resource :silence, only: [:create, :destroy] resource :suspension, only: [:create, :destroy] resource :confirmation, only: [:create] + resources :statuses, only: [:index, :create, :update, :destroy] end resources :users, only: [] do diff --git a/spec/controllers/admin/reported_statuses_controller_spec.rb b/spec/controllers/admin/reported_statuses_controller_spec.rb index 80c69e8d1..297807d41 100644 --- a/spec/controllers/admin/reported_statuses_controller_spec.rb +++ b/spec/controllers/admin/reported_statuses_controller_spec.rb @@ -11,6 +11,42 @@ describe Admin::ReportedStatusesController do sign_in user, scope: :user end + describe 'POST #create' do + subject do + -> { post :create, params: { report_id: report, form_status_batch: { action: action, status_ids: status_ids } } } + end + + let(:action) { 'nsfw_on' } + let(:status_ids) { [status.id] } + let(:status) { Fabricate(:status, sensitive: !sensitive) } + let(:sensitive) { true } + let!(:media_attachment) { Fabricate(:media_attachment, status: status) } + + context 'updates sensitive column to true' do + it 'updates sensitive column' do + is_expected.to change { + status.reload.sensitive + }.from(false).to(true) + end + end + + context 'updates sensitive column to false' do + let(:action) { 'nsfw_off' } + let(:sensitive) { false } + + it 'updates sensitive column' do + is_expected.to change { + status.reload.sensitive + }.from(true).to(false) + end + end + + it 'redirects to report page' do + subject.call + expect(response).to redirect_to(admin_report_path(report)) + end + end + describe 'PATCH #update' do subject do -> { patch :update, params: { report_id: report, id: status, status: { sensitive: sensitive } } } @@ -48,7 +84,7 @@ describe Admin::ReportedStatusesController do allow(RemovalWorker).to receive(:perform_async) delete :destroy, params: { report_id: report, id: status } - expect(response).to redirect_to(admin_report_path(report)) + expect(response).to have_http_status(:success) expect(RemovalWorker). to have_received(:perform_async).with(status.id) end diff --git a/spec/controllers/admin/statuses_controller_spec.rb b/spec/controllers/admin/statuses_controller_spec.rb new file mode 100644 index 000000000..1515e299b --- /dev/null +++ b/spec/controllers/admin/statuses_controller_spec.rb @@ -0,0 +1,107 @@ +require 'rails_helper' + +describe Admin::StatusesController do + render_views + + let(:user) { Fabricate(:user, admin: true) } + let(:account) { Fabricate(:account) } + let!(:status) { Fabricate(:status, account: account) } + let(:media_attached_status) { Fabricate(:status, account: account, sensitive: !sensitive) } + let!(:media_attachment) { Fabricate(:media_attachment, account: account, status: media_attached_status) } + let(:sensitive) { true } + + before do + sign_in user, scope: :user + end + + describe 'GET #index' do + it 'returns http success with no media' do + get :index, params: { account_id: account.id } + + statuses = assigns(:statuses).to_a + expect(statuses.size).to eq 2 + expect(response).to have_http_status(:success) + end + + it 'returns http success with media' do + get :index, params: { account_id: account.id , media: true } + + statuses = assigns(:statuses).to_a + expect(statuses.size).to eq 1 + expect(response).to have_http_status(:success) + end + end + + describe 'POST #create' do + subject do + -> { post :create, params: { account_id: account.id, form_status_batch: { action: action, status_ids: status_ids } } } + end + + let(:action) { 'nsfw_on' } + let(:status_ids) { [media_attached_status.id] } + + context 'updates sensitive column to true' do + it 'updates sensitive column' do + is_expected.to change { + media_attached_status.reload.sensitive + }.from(false).to(true) + end + end + + context 'updates sensitive column to false' do + let(:action) { 'nsfw_off' } + let(:sensitive) { false } + + it 'updates sensitive column' do + is_expected.to change { + media_attached_status.reload.sensitive + }.from(true).to(false) + end + end + + it 'redirects to account statuses page' do + subject.call + expect(response).to redirect_to(admin_account_statuses_path(account.id)) + end + end + + describe 'PATCH #update' do + subject do + -> { patch :update, params: { account_id: account.id, id: media_attached_status, status: { sensitive: sensitive } } } + end + + context 'updates sensitive column to true' do + it 'updates sensitive column' do + is_expected.to change { + media_attached_status.reload.sensitive + }.from(false).to(true) + end + end + + context 'updates sensitive column to false' do + let(:sensitive) { false } + + it 'updates sensitive column' do + is_expected.to change { + media_attached_status.reload.sensitive + }.from(true).to(false) + end + end + + it 'redirects to account statuses page' do + subject.call + expect(response).to redirect_to(admin_account_statuses_path(account.id)) + end + end + + describe 'DELETE #destroy' do + it 'removes a status' do + allow(RemovalWorker).to receive(:perform_async) + + delete :destroy, params: { account_id: account.id, id: status } + expect(response).to have_http_status(:success) + expect(RemovalWorker). + to have_received(:perform_async).with(status.id) + end + end +end diff --git a/spec/models/form/status_batch_spec.rb b/spec/models/form/status_batch_spec.rb new file mode 100644 index 000000000..00c790a11 --- /dev/null +++ b/spec/models/form/status_batch_spec.rb @@ -0,0 +1,52 @@ +require 'rails_helper' + +describe Form::StatusBatch do + let(:form) { Form::StatusBatch.new(action: action, status_ids: status_ids) } + let(:status) { Fabricate(:status) } + + describe 'with nsfw action' do + let(:status_ids) { [status.id, nonsensitive_status.id, sensitive_status.id] } + let(:nonsensitive_status) { Fabricate(:status, sensitive: false) } + let(:sensitive_status) { Fabricate(:status, sensitive: true) } + let!(:shown_media_attachment) { Fabricate(:media_attachment, status: nonsensitive_status) } + let!(:hidden_media_attachment) { Fabricate(:media_attachment, status: sensitive_status) } + + context 'nsfw_on' do + let(:action) { 'nsfw_on' } + + it { expect(form.save).to be true } + it { expect { form.save }.to change { nonsensitive_status.reload.sensitive }.from(false).to(true) } + it { expect { form.save }.not_to change { sensitive_status.reload.sensitive } } + it { expect { form.save }.not_to change { status.reload.sensitive } } + end + + context 'nsfw_off' do + let(:action) { 'nsfw_off' } + + it { expect(form.save).to be true } + it { expect { form.save }.to change { sensitive_status.reload.sensitive }.from(true).to(false) } + it { expect { form.save }.not_to change { nonsensitive_status.reload.sensitive } } + it { expect { form.save }.not_to change { status.reload.sensitive } } + end + end + + describe 'with delete action' do + let(:status_ids) { [status.id] } + let(:action) { 'delete' } + let!(:another_status) { Fabricate(:status) } + + before do + allow(RemovalWorker).to receive(:perform_async) + end + + it 'call RemovalWorker' do + form.save + expect(RemovalWorker).to have_received(:perform_async).with(status.id) + end + + it 'do not call RemovalWorker' do + form.save + expect(RemovalWorker).not_to have_received(:perform_async).with(another_status.id) + end + end +end From 89b988cab5e4729bd80400a2b25ec2b790ebd18d Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Tue, 18 Jul 2017 23:39:47 +0900 Subject: [PATCH 11/16] Introduce Ostatus name space (#4164) * Wrap methods of ProcessFeedService::ProcessEntry in classes This is a change same with 425acecfdb15093a265b191120fb2d4e4c4135c4, except that it has the following changes: * Revert irrelevant change in find_or_create_conversation * Fix error handling for RemoteActivity * Introduce Ostatus name space --- app/controllers/accounts_controller.rb | 2 +- app/controllers/stream_entries_controller.rb | 2 +- app/lib/ostatus/activity/base.rb | 50 +++ app/lib/ostatus/activity/creation.rb | 149 ++++++++ app/lib/ostatus/activity/deletion.rb | 14 + app/lib/ostatus/activity/general.rb | 20 ++ app/lib/ostatus/activity/post.rb | 23 ++ app/lib/ostatus/activity/remote.rb | 7 + app/lib/ostatus/activity/share.rb | 26 ++ app/lib/{ => ostatus}/atom_serializer.rb | 2 +- app/services/authorize_follow_service.rb | 2 +- app/services/block_service.rb | 2 +- .../concerns/stream_entry_renderer.rb | 2 +- app/services/favourite_service.rb | 2 +- app/services/follow_service.rb | 4 +- app/services/process_feed_service.rb | 274 +-------------- app/services/reject_follow_service.rb | 2 +- app/services/unblock_service.rb | 2 +- app/services/unfavourite_service.rb | 2 +- app/services/unfollow_service.rb | 2 +- .../pubsubhubbub/distribution_worker.rb | 4 +- .../lib/{ => ostatus}/atom_serializer_spec.rb | 330 +++++++++--------- spec/services/process_feed_service_spec.rb | 40 +++ 23 files changed, 516 insertions(+), 447 deletions(-) create mode 100644 app/lib/ostatus/activity/base.rb create mode 100644 app/lib/ostatus/activity/creation.rb create mode 100644 app/lib/ostatus/activity/deletion.rb create mode 100644 app/lib/ostatus/activity/general.rb create mode 100644 app/lib/ostatus/activity/post.rb create mode 100644 app/lib/ostatus/activity/remote.rb create mode 100644 app/lib/ostatus/activity/share.rb rename app/lib/{ => ostatus}/atom_serializer.rb (99%) rename spec/lib/{ => ostatus}/atom_serializer_spec.rb (80%) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index a95aabf1d..37a1e540f 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: AtomSerializer.render(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/stream_entries_controller.rb b/app/controllers/stream_entries_controller.rb index 54a435238..e3db77caa 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: AtomSerializer.render(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/lib/ostatus/activity/base.rb b/app/lib/ostatus/activity/base.rb new file mode 100644 index 000000000..f528815b3 --- /dev/null +++ b/app/lib/ostatus/activity/base.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +class Ostatus::Activity::Base + def initialize(xml, account = nil) + @xml = xml + @account = account + end + + def status? + [:activity, :note, :comment].include?(type) + end + + def verb + raw = @xml.at_xpath('./activity:verb', activity: TagManager::AS_XMLNS).content + TagManager::VERBS.key(raw) + rescue + :post + end + + def type + raw = @xml.at_xpath('./activity:object-type', activity: TagManager::AS_XMLNS).content + TagManager::TYPES.key(raw) + rescue + :activity + end + + def id + @xml.at_xpath('./xmlns:id', xmlns: TagManager::XMLNS).content + end + + def url + link = @xml.at_xpath('./xmlns:link[@rel="alternate"]', xmlns: TagManager::XMLNS) + link.nil? ? nil : link['href'] + end + + private + + def find_status(uri) + if TagManager.instance.local_id?(uri) + local_id = TagManager.instance.unique_tag_to_local_id(uri, 'Status') + return Status.find_by(id: local_id) + end + + Status.find_by(uri: uri) + end + + def redis + Redis.current + end +end diff --git a/app/lib/ostatus/activity/creation.rb b/app/lib/ostatus/activity/creation.rb new file mode 100644 index 000000000..c54d64fd7 --- /dev/null +++ b/app/lib/ostatus/activity/creation.rb @@ -0,0 +1,149 @@ +# frozen_string_literal: true + +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" + return [nil, false] + end + + return [nil, false] if @account.suspended? + + Rails.logger.debug "Creating remote status #{id}" + + # Return early if status already exists in db + status = find_status(id) + + return [status, false] unless status.nil? + + status = Status.create!( + uri: id, + url: url, + account: @account, + reblog: reblog, + text: content, + spoiler_text: content_warning, + created_at: published, + reply: thread?, + language: content_language, + visibility: visibility_scope, + conversation: find_or_create_conversation, + thread: thread? ? find_status(thread.first) : nil + ) + + save_mentions(status) + save_hashtags(status) + save_media(status) + + if thread? && status.thread.nil? + Rails.logger.debug "Trying to attach #{status.id} (#{id}) to #{thread.first}" + ThreadResolveWorker.perform_async(status.id, thread.second) + end + + Rails.logger.debug "Queuing remote status #{status.id} (#{id}) for distribution" + + LinkCrawlWorker.perform_async(status.id) unless status.spoiler_text? + DistributionWorker.perform_async(status.id) + + [status, true] + end + + def content + @xml.at_xpath('./xmlns:content', xmlns: TagManager::XMLNS).content + end + + def content_language + @xml.at_xpath('./xmlns:content', xmlns: TagManager::XMLNS)['xml:lang']&.presence || 'en' + end + + def content_warning + @xml.at_xpath('./xmlns:summary', xmlns: TagManager::XMLNS)&.content || '' + end + + def visibility_scope + @xml.at_xpath('./mastodon:scope', mastodon: TagManager::MTDN_XMLNS)&.content&.to_sym || :public + end + + def published + @xml.at_xpath('./xmlns:published', xmlns: TagManager::XMLNS).content + end + + def thread? + !@xml.at_xpath('./thr:in-reply-to', thr: TagManager::THR_XMLNS).nil? + end + + def thread + thr = @xml.at_xpath('./thr:in-reply-to', thr: TagManager::THR_XMLNS) + [thr['ref'], thr['href']] + end + + private + + def find_or_create_conversation + uri = @xml.at_xpath('./ostatus:conversation', ostatus: TagManager::OS_XMLNS)&.attribute('ref')&.content + return if uri.nil? + + if TagManager.instance.local_id?(uri) + local_id = TagManager.instance.unique_tag_to_local_id(uri, 'Conversation') + return Conversation.find_by(id: local_id) + end + + Conversation.find_by(uri: uri) || Conversation.create!(uri: uri) + end + + def save_mentions(parent) + processed_account_ids = [] + + @xml.xpath('./xmlns:link[@rel="mentioned"]', xmlns: TagManager::XMLNS).each do |link| + next if [TagManager::TYPES[:group], TagManager::TYPES[:collection]].include? link['ostatus:object-type'] + + mentioned_account = account_from_href(link['href']) + + next if mentioned_account.nil? || processed_account_ids.include?(mentioned_account.id) + + mentioned_account.mentions.where(status: parent).first_or_create(status: parent) + + # So we can skip duplicate mentions + processed_account_ids << mentioned_account.id + end + end + + def save_hashtags(parent) + tags = @xml.xpath('./xmlns:category', xmlns: TagManager::XMLNS).map { |category| category['term'] }.select(&:present?) + ProcessHashtagsService.new.call(parent, tags) + end + + def save_media(parent) + do_not_download = DomainBlock.find_by(domain: parent.account.domain)&.reject_media? + + @xml.xpath('./xmlns:link[@rel="enclosure"]', xmlns: TagManager::XMLNS).each do |link| + next unless link['href'] + + media = MediaAttachment.where(status: parent, remote_url: link['href']).first_or_initialize(account: parent.account, status: parent, remote_url: link['href']) + parsed_url = Addressable::URI.parse(link['href']).normalize + + next if !%w(http https).include?(parsed_url.scheme) || parsed_url.host.empty? + + media.save + + next if do_not_download + + begin + media.file_remote_url = link['href'] + media.save! + rescue ActiveRecord::RecordInvalid + next + end + end + end + + def account_from_href(href) + url = Addressable::URI.parse(href).normalize + + if TagManager.instance.web_domain?(url.host) + Account.find_local(url.path.gsub('/users/', '')) + else + Account.where(uri: href).or(Account.where(url: href)).first || FetchRemoteAccountService.new.call(href) + end + end +end diff --git a/app/lib/ostatus/activity/deletion.rb b/app/lib/ostatus/activity/deletion.rb new file mode 100644 index 000000000..c4d05a467 --- /dev/null +++ b/app/lib/ostatus/activity/deletion.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class Ostatus::Activity::Deletion < Ostatus::Activity::Base + def perform + Rails.logger.debug "Deleting remote status #{id}" + status = Status.find_by(uri: id, account: @account) + + if status.nil? + redis.setex("delete_upon_arrival:#{@account.id}:#{id}", 6 * 3_600, id) + else + RemoveStatusService.new.call(status) + end + end +end diff --git a/app/lib/ostatus/activity/general.rb b/app/lib/ostatus/activity/general.rb new file mode 100644 index 000000000..3ff7a039a --- /dev/null +++ b/app/lib/ostatus/activity/general.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class Ostatus::Activity::General < Ostatus::Activity::Base + def specialize + special_class&.new(@xml, @account) + end + + private + + def special_class + case verb + when :post + Ostatus::Activity::Post + when :share + Ostatus::Activity::Share + when :delete + Ostatus::Activity::Deletion + end + end +end diff --git a/app/lib/ostatus/activity/post.rb b/app/lib/ostatus/activity/post.rb new file mode 100644 index 000000000..8028db2f8 --- /dev/null +++ b/app/lib/ostatus/activity/post.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class Ostatus::Activity::Post < Ostatus::Activity::Creation + def perform + status, just_created = super + + if just_created + status.mentions.includes(:account).each do |mention| + mentioned_account = mention.account + next unless mentioned_account.local? + NotifyService.new.call(mentioned_account, mention) + end + end + + status + end + + private + + def reblog + nil + end +end diff --git a/app/lib/ostatus/activity/remote.rb b/app/lib/ostatus/activity/remote.rb new file mode 100644 index 000000000..755f885e6 --- /dev/null +++ b/app/lib/ostatus/activity/remote.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class Ostatus::Activity::Remote < Ostatus::Activity::Base + def perform + find_status(id) || FetchRemoteStatusService.new.call(url) + end +end diff --git a/app/lib/ostatus/activity/share.rb b/app/lib/ostatus/activity/share.rb new file mode 100644 index 000000000..73aac58ed --- /dev/null +++ b/app/lib/ostatus/activity/share.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class Ostatus::Activity::Share < Ostatus::Activity::Creation + def perform + return if reblog.nil? + + status, just_created = super + NotifyService.new.call(reblog.account, status) if reblog.account.local? && just_created + status + end + + def object + @xml.at_xpath('.//activity:object', activity: TagManager::AS_XMLNS) + end + + private + + def reblog + return @reblog if defined? @reblog + + original_status = Ostatus::Activity::Remote.new(object).perform + return if original_status.nil? + + @reblog = original_status.reblog? ? original_status.reblog : original_status + end +end diff --git a/app/lib/atom_serializer.rb b/app/lib/ostatus/atom_serializer.rb similarity index 99% rename from app/lib/atom_serializer.rb rename to app/lib/ostatus/atom_serializer.rb index b14d596dd..909d84df3 100644 --- a/app/lib/atom_serializer.rb +++ b/app/lib/ostatus/atom_serializer.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class AtomSerializer +class Ostatus::AtomSerializer include RoutingHelper include ActionView::Helpers::SanitizeHelper diff --git a/app/services/authorize_follow_service.rb b/app/services/authorize_follow_service.rb index 97c76bee1..a25d11dbd 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) - AtomSerializer.render(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 d59b47afb..15420e192 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) - AtomSerializer.render(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 ef176d8a6..d9c30c53c 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) - AtomSerializer.render(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 90267af33..a08aba638 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) - AtomSerializer.render(AtomSerializer.new.favourite_salmon(favourite)) + Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.favourite_salmon(favourite)) end end diff --git a/app/services/follow_service.rb b/app/services/follow_service.rb index e54ff7d0f..7a7275b6e 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) - AtomSerializer.render(AtomSerializer.new.follow_request_salmon(follow_request)) + Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.follow_request_salmon(follow_request)) end def build_follow_xml(follow) - AtomSerializer.render(AtomSerializer.new.follow_salmon(follow)) + Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.follow_salmon(follow)) end end diff --git a/app/services/process_feed_service.rb b/app/services/process_feed_service.rb index c335d2159..b99048a06 100644 --- a/app/services/process_feed_service.rb +++ b/app/services/process_feed_service.rb @@ -16,274 +16,14 @@ class ProcessFeedService < BaseService end def process_entries(xml, account) - xml.xpath('//xmlns:entry', xmlns: TagManager::XMLNS).reverse_each.map { |entry| ProcessEntry.new.call(entry, account) }.compact + xml.xpath('//xmlns:entry', xmlns: TagManager::XMLNS).reverse_each.map { |entry| process_entry(entry, account) }.compact end - class ProcessEntry - def call(xml, account) - @account = account - @xml = xml - - return if skip_unsupported_type? - - case verb - when :post, :share - return create_status - when :delete - return delete_status - end - rescue ActiveRecord::RecordInvalid => e - Rails.logger.debug "Nothing was saved for #{id} because: #{e}" - nil - end - - private - - def create_status - if redis.exists("delete_upon_arrival:#{@account.id}:#{id}") - Rails.logger.debug "Delete for status #{id} was queued, ignoring" - return - end - - status, just_created = nil - - Rails.logger.debug "Creating remote status #{id}" - - if verb == :share - original_status = shared_status_from_xml(@xml.at_xpath('.//activity:object', activity: TagManager::AS_XMLNS)) - return nil if original_status.nil? - end - - ApplicationRecord.transaction do - status, just_created = status_from_xml(@xml) - - return if status.nil? - return status unless just_created - - if verb == :share - status.reblog = original_status.reblog? ? original_status.reblog : original_status - end - - status.save! - end - - if thread?(@xml) && status.thread.nil? - Rails.logger.debug "Trying to attach #{status.id} (#{id(@xml)}) to #{thread(@xml).first}" - ThreadResolveWorker.perform_async(status.id, thread(@xml).second) - end - - notify_about_mentions!(status) unless status.reblog? - notify_about_reblog!(status) if status.reblog? && status.reblog.account.local? - - Rails.logger.debug "Queuing remote status #{status.id} (#{id}) for distribution" - - LinkCrawlWorker.perform_async(status.id) unless status.spoiler_text? - DistributionWorker.perform_async(status.id) - - status - end - - def notify_about_mentions!(status) - status.mentions.includes(:account).each do |mention| - mentioned_account = mention.account - next unless mentioned_account.local? - NotifyService.new.call(mentioned_account, mention) - end - end - - def notify_about_reblog!(status) - NotifyService.new.call(status.reblog.account, status) - end - - def delete_status - Rails.logger.debug "Deleting remote status #{id}" - status = Status.find_by(uri: id, account: @account) - - if status.nil? - redis.setex("delete_upon_arrival:#{@account.id}:#{id}", 6 * 3_600, id) - else - RemoveStatusService.new.call(status) - end - end - - def skip_unsupported_type? - !([:post, :share, :delete].include?(verb) && [:activity, :note, :comment].include?(type)) - end - - def shared_status_from_xml(entry) - status = find_status(id(entry)) - - return status unless status.nil? - - FetchRemoteStatusService.new.call(url(entry)) - end - - def status_from_xml(entry) - # Return early if status already exists in db - status = find_status(id(entry)) - - return [status, false] unless status.nil? - - account = @account - - return [nil, false] if account.suspended? - - status = Status.create!( - uri: id(entry), - url: url(entry), - account: account, - text: content(entry), - spoiler_text: content_warning(entry), - created_at: published(entry), - reply: thread?(entry), - language: content_language(entry), - visibility: visibility_scope(entry), - conversation: find_or_create_conversation(entry), - thread: thread?(entry) ? find_status(thread(entry).first) : nil - ) - - mentions_from_xml(status, entry) - hashtags_from_xml(status, entry) - media_from_xml(status, entry) - - [status, true] - end - - def find_or_create_conversation(xml) - uri = xml.at_xpath('./ostatus:conversation', ostatus: TagManager::OS_XMLNS)&.attribute('ref')&.content - return if uri.nil? - - if TagManager.instance.local_id?(uri) - local_id = TagManager.instance.unique_tag_to_local_id(uri, 'Conversation') - return Conversation.find_by(id: local_id) - end - - Conversation.find_by(uri: uri) || Conversation.create!(uri: uri) - end - - def find_status(uri) - if TagManager.instance.local_id?(uri) - local_id = TagManager.instance.unique_tag_to_local_id(uri, 'Status') - return Status.find_by(id: local_id) - end - - Status.find_by(uri: uri) - end - - def mentions_from_xml(parent, xml) - processed_account_ids = [] - - xml.xpath('./xmlns:link[@rel="mentioned"]', xmlns: TagManager::XMLNS).each do |link| - next if [TagManager::TYPES[:group], TagManager::TYPES[:collection]].include? link['ostatus:object-type'] - - mentioned_account = account_from_href(link['href']) - - next if mentioned_account.nil? || processed_account_ids.include?(mentioned_account.id) - - mentioned_account.mentions.where(status: parent).first_or_create(status: parent) - - # So we can skip duplicate mentions - processed_account_ids << mentioned_account.id - end - end - - def account_from_href(href) - url = Addressable::URI.parse(href).normalize - - if TagManager.instance.web_domain?(url.host) - Account.find_local(url.path.gsub('/users/', '')) - else - Account.where(uri: href).or(Account.where(url: href)).first || FetchRemoteAccountService.new.call(href) - end - end - - def hashtags_from_xml(parent, xml) - tags = xml.xpath('./xmlns:category', xmlns: TagManager::XMLNS).map { |category| category['term'] }.select(&:present?) - ProcessHashtagsService.new.call(parent, tags) - end - - def media_from_xml(parent, xml) - do_not_download = DomainBlock.find_by(domain: parent.account.domain)&.reject_media? - - xml.xpath('./xmlns:link[@rel="enclosure"]', xmlns: TagManager::XMLNS).each do |link| - next unless link['href'] - - media = MediaAttachment.where(status: parent, remote_url: link['href']).first_or_initialize(account: parent.account, status: parent, remote_url: link['href']) - parsed_url = Addressable::URI.parse(link['href']).normalize - - next if !%w(http https).include?(parsed_url.scheme) || parsed_url.host.empty? - - media.save - - next if do_not_download - - begin - media.file_remote_url = link['href'] - media.save! - rescue ActiveRecord::RecordInvalid - next - end - end - end - - def id(xml = @xml) - xml.at_xpath('./xmlns:id', xmlns: TagManager::XMLNS).content - end - - def verb(xml = @xml) - raw = xml.at_xpath('./activity:verb', activity: TagManager::AS_XMLNS).content - TagManager::VERBS.key(raw) - rescue - :post - end - - def type(xml = @xml) - raw = xml.at_xpath('./activity:object-type', activity: TagManager::AS_XMLNS).content - TagManager::TYPES.key(raw) - rescue - :activity - end - - def url(xml = @xml) - link = xml.at_xpath('./xmlns:link[@rel="alternate"]', xmlns: TagManager::XMLNS) - link.nil? ? nil : link['href'] - end - - def content(xml = @xml) - xml.at_xpath('./xmlns:content', xmlns: TagManager::XMLNS).content - end - - def content_language(xml = @xml) - xml.at_xpath('./xmlns:content', xmlns: TagManager::XMLNS)['xml:lang']&.presence || 'en' - end - - def content_warning(xml = @xml) - xml.at_xpath('./xmlns:summary', xmlns: TagManager::XMLNS)&.content || '' - end - - def visibility_scope(xml = @xml) - xml.at_xpath('./mastodon:scope', mastodon: TagManager::MTDN_XMLNS)&.content&.to_sym || :public - end - - def published(xml = @xml) - xml.at_xpath('./xmlns:published', xmlns: TagManager::XMLNS).content - end - - def thread?(xml = @xml) - !xml.at_xpath('./thr:in-reply-to', thr: TagManager::THR_XMLNS).nil? - end - - def thread(xml = @xml) - thr = xml.at_xpath('./thr:in-reply-to', thr: TagManager::THR_XMLNS) - [thr['ref'], thr['href']] - end - - def account?(xml = @xml) - !xml.at_xpath('./xmlns:author', xmlns: TagManager::XMLNS).nil? - end - - def redis - Redis.current - end + def process_entry(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}" + nil end end diff --git a/app/services/reject_follow_service.rb b/app/services/reject_follow_service.rb index 675007938..87fc49b34 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) - AtomSerializer.render(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/unblock_service.rb b/app/services/unblock_service.rb index 3a3fd2d8c..50c2dc2f0 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) - AtomSerializer.render(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 a32e87bff..ede3caad1 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) - AtomSerializer.render(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 9b39f4945..0c9a5f657 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) - AtomSerializer.render(AtomSerializer.new.unfollow_salmon(follow)) + Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.unfollow_salmon(follow)) end end diff --git a/app/workers/pubsubhubbub/distribution_worker.rb b/app/workers/pubsubhubbub/distribution_worker.rb index 7592354cc..9c1fa76cb 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 = AtomSerializer.render(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 = AtomSerializer.render(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| diff --git a/spec/lib/atom_serializer_spec.rb b/spec/lib/ostatus/atom_serializer_spec.rb similarity index 80% rename from spec/lib/atom_serializer_spec.rb rename to spec/lib/ostatus/atom_serializer_spec.rb index d14fc5b40..8caef9355 100644 --- a/spec/lib/atom_serializer_spec.rb +++ b/spec/lib/ostatus/atom_serializer_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe AtomSerializer do +RSpec.describe Ostatus::AtomSerializer do shared_examples 'follow request salmon' do it 'appends author element with account' do account = Fabricate(:account, domain: nil, username: 'username') @@ -108,7 +108,7 @@ RSpec.describe AtomSerializer do it 'returns XML with emojis' do element = Ox::Element.new('tag') element << '💩' - xml = AtomSerializer.render(element) + xml = Ostatus::AtomSerializer.render(element) expect(xml).to eq "\n💩\n" end @@ -116,7 +116,7 @@ RSpec.describe AtomSerializer do it 'returns XML, stripping invalid characters like \b and \v' do element = Ox::Element.new('tag') element << "im l33t\b haxo\b\vr" - xml = AtomSerializer.render(element) + xml = Ostatus::AtomSerializer.render(element) expect(xml).to eq "\nim l33t haxor\n" end @@ -127,7 +127,7 @@ RSpec.describe AtomSerializer do it 'appends poco:note element with note for local account' do account = Fabricate(:account, domain: nil, note: '

note

') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) note = author.nodes.find { |node| node.name == 'poco:note' } expect(note.text).to eq '

note

' @@ -136,7 +136,7 @@ RSpec.describe AtomSerializer do it 'appends poco:note element with tags-stripped note for remote account' do account = Fabricate(:account, domain: 'remote', note: '

note

') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) note = author.nodes.find { |node| node.name == 'poco:note' } expect(note.text).to eq 'note' @@ -144,7 +144,7 @@ RSpec.describe AtomSerializer do it 'appends summary element with type attribute and simplified note if present' do account = Fabricate(:account, note: 'note') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) expect(author.summary.text).to eq '

note

' expect(author.summary[:type]).to eq 'html' end @@ -153,27 +153,27 @@ RSpec.describe AtomSerializer do context 'when note is not present' do it 'does not append poco:note element' do account = Fabricate(:account, note: '') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) author.nodes.each { |node| expect(node.name).not_to eq 'poco:note' } end it 'does not append summary element' do account = Fabricate(:account, note: '') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) author.nodes.each { |node| expect(node.name).not_to eq 'summary' } end end it 'returns author element' do account = Fabricate(:account) - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) expect(author.name).to eq 'author' end it 'appends activity:object-type element with person type' do account = Fabricate(:account, domain: nil, username: 'username') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) object_type = author.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq TagManager::TYPES[:person] @@ -181,20 +181,20 @@ RSpec.describe AtomSerializer do it 'appends email element with username and domain for local account' do account = Fabricate(:account, username: 'username') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) expect(author.email.text).to eq 'username@cb6e6126.ngrok.io' end it 'appends email element with username and domain for remote user' do account = Fabricate(:account, domain: 'domain', username: 'username') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) expect(author.email.text).to eq 'username@domain' end it 'appends link element for an alternative' do account = Fabricate(:account, domain: nil, username: 'username') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) link = author.nodes.find { |node| node.name == 'link' && node[:rel] == 'alternate' } expect(link[:type]).to eq 'text/html' @@ -205,7 +205,7 @@ RSpec.describe AtomSerializer do it 'has link element for avatar if present' do account = Fabricate(:account, avatar: attachment_fixture('avatar.gif')) - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) link = author.nodes.find { |node| node.name == 'link' && node[:rel] == 'avatar' } expect(link[:type]).to eq 'image/gif' @@ -217,7 +217,7 @@ RSpec.describe AtomSerializer do it 'does not have link element for avatar if not present' do account = Fabricate(:account, avatar: nil) - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) author.nodes.each do |node| expect(node[:rel]).not_to eq 'avatar' if node.name == 'link' @@ -227,7 +227,7 @@ RSpec.describe AtomSerializer do it 'appends link element for header if present' do account = Fabricate(:account, header: attachment_fixture('avatar.gif')) - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) link = author.nodes.find { |node| node.name == 'link' && node[:rel] == 'header' } expect(link[:type]).to eq 'image/gif' @@ -239,7 +239,7 @@ RSpec.describe AtomSerializer do it 'does not append link element for header if not present' do account = Fabricate(:account, header: nil) - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) author.nodes.each do |node| expect(node[:rel]).not_to eq 'header' if node.name == 'link' @@ -249,7 +249,7 @@ RSpec.describe AtomSerializer do it 'appends poco:displayName element with display name if present' do account = Fabricate(:account, display_name: 'display name') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) display_name = author.nodes.find { |node| node.name == 'poco:displayName' } expect(display_name.text).to eq 'display name' @@ -257,14 +257,14 @@ RSpec.describe AtomSerializer do it 'does not append poco:displayName element with display name if not present' do account = Fabricate(:account, display_name: '') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) author.nodes.each { |node| expect(node.name).not_to eq 'poco:displayName' } end it "appends mastodon:scope element with 'private' if locked" do account = Fabricate(:account, locked: true) - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) scope = author.nodes.find { |node| node.name == 'mastodon:scope' } expect(scope.text).to eq 'private' @@ -273,7 +273,7 @@ RSpec.describe AtomSerializer do it "appends mastodon:scope element with 'public' if unlocked" do account = Fabricate(:account, locked: false) - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) scope = author.nodes.find { |node| node.name == 'mastodon:scope' } expect(scope.text).to eq 'public' @@ -282,7 +282,7 @@ RSpec.describe AtomSerializer do it 'includes URI' do account = Fabricate(:account, domain: nil, username: 'username') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) expect(author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username' expect(author.uri.text).to eq 'https://cb6e6126.ngrok.io/users/username' @@ -291,7 +291,7 @@ RSpec.describe AtomSerializer do it 'includes username' do account = Fabricate(:account, username: 'username') - author = AtomSerializer.new.author(account) + author = Ostatus::AtomSerializer.new.author(account) name = author.nodes.find { |node| node.name == 'name' } username = author.nodes.find { |node| node.name == 'poco:preferredUsername' } @@ -317,7 +317,7 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize stream_entry = Fabricate(:stream_entry) - AtomSerializer.new.entry(stream_entry, true) + Ostatus::AtomSerializer.new.entry(stream_entry, true) end end @@ -325,7 +325,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, username: 'username') status = Fabricate(:status, account: account) - entry = AtomSerializer.new.entry(status.stream_entry, true) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry, true) expect(entry.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username' end @@ -334,14 +334,14 @@ RSpec.describe AtomSerializer do context 'if status is present' do include_examples 'status attributes' do def serialize(status) - AtomSerializer.new.entry(status.stream_entry, true) + Ostatus::AtomSerializer.new.entry(status.stream_entry, true) end end it 'appends link element for the public collection if status is publicly visible' do status = Fabricate(:status, visibility: :public) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) mentioned_person = entry.nodes.find do |node| node.name == 'link' && @@ -354,7 +354,7 @@ RSpec.describe AtomSerializer do it 'does not append link element for the public collection if status is not publicly visible' do status = Fabricate(:status, visibility: :private) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) entry.nodes.each do |node| if node.name == 'link' && @@ -369,14 +369,14 @@ RSpec.describe AtomSerializer do tag = Fabricate(:tag, name: 'tag') status = Fabricate(:status, tags: [ tag ]) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) expect(entry.category[:term]).to eq 'tag' end it 'appends category element for NSFW if status is sensitive' do status = Fabricate(:status, sensitive: true) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) expect(entry.category[:term]).to eq 'nsfw' end @@ -385,7 +385,7 @@ RSpec.describe AtomSerializer do media_attachment = Fabricate(:media_attachment, file: file) status = Fabricate(:status, media_attachments: [ media_attachment ]) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) enclosure = entry.nodes.find { |node| node.name == 'link' && node[:rel] == 'enclosure' } expect(enclosure[:type]).to eq 'image/jpeg' @@ -395,7 +395,7 @@ RSpec.describe AtomSerializer do it 'appends mastodon:scope element with visibility' do status = Fabricate(:status, visibility: :public) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) scope = entry.nodes.find { |node| node.name == 'mastodon:scope' } expect(scope.text).to eq 'public' @@ -406,8 +406,8 @@ RSpec.describe AtomSerializer do remote_status = Fabricate(:status, account: remote_account) remote_status.stream_entry.update!(created_at: '2000-01-01T00:00:00Z') - entry = AtomSerializer.new.entry(remote_status.stream_entry, true) - xml = AtomSerializer.render(entry).gsub('cb6e6126.ngrok.io', 'remote') + entry = Ostatus::AtomSerializer.new.entry(remote_status.stream_entry, true) + xml = Ostatus::AtomSerializer.render(entry).gsub('cb6e6126.ngrok.io', 'remote') remote_status.destroy! remote_account.destroy! @@ -429,7 +429,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status) status.destroy! - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) expect(entry.content.text).to eq 'Deleted status' end @@ -439,7 +439,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status, account: account) status.destroy! - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) expect(entry.title.text).to eq 'username deleted status' end @@ -447,19 +447,19 @@ RSpec.describe AtomSerializer do context 'it is not root' do let(:stream_entry) { Fabricate(:stream_entry) } - subject { AtomSerializer.new.entry(stream_entry, false) } + subject { Ostatus::AtomSerializer.new.entry(stream_entry, false) } include_examples 'not root' end context 'without root parameter' do let(:stream_entry) { Fabricate(:stream_entry) } - subject { AtomSerializer.new.entry(stream_entry) } + subject { Ostatus::AtomSerializer.new.entry(stream_entry) } include_examples 'not root' end it 'returns entry element' do stream_entry = Fabricate(:stream_entry) - entry = AtomSerializer.new.entry(stream_entry) + entry = Ostatus::AtomSerializer.new.entry(stream_entry) expect(entry.name).to eq 'entry' end @@ -467,33 +467,33 @@ RSpec.describe AtomSerializer do status = Fabricate(:status, reblog_of_id: nil) status.stream_entry.update!(created_at: '2000-01-01T00:00:00Z') - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) expect(entry.id.text).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{status.id}:objectType=Status" end it 'appends published element with created date' do stream_entry = Fabricate(:stream_entry, created_at: '2000-01-01T00:00:00Z') - entry = AtomSerializer.new.entry(stream_entry) + entry = Ostatus::AtomSerializer.new.entry(stream_entry) expect(entry.published.text).to eq '2000-01-01T00:00:00Z' end it 'appends updated element with updated date' do stream_entry = Fabricate(:stream_entry, updated_at: '2000-01-01T00:00:00Z') - entry = AtomSerializer.new.entry(stream_entry) + entry = Ostatus::AtomSerializer.new.entry(stream_entry) expect(entry.updated.text).to eq '2000-01-01T00:00:00Z' end it 'appends title element with status title' do account = Fabricate(:account, username: 'username') status = Fabricate(:status, account: account, reblog_of_id: nil) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) expect(entry.title.text).to eq 'New status by username' end it 'appends activity:object-type element with object type' do status = Fabricate(:status) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) object_type = entry.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq TagManager::TYPES[:note] end @@ -501,7 +501,7 @@ RSpec.describe AtomSerializer do it 'appends activity:verb element with object type' do status = Fabricate(:status) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) object_type = entry.nodes.find { |node| node.name == 'activity:verb' } expect(object_type.text).to eq TagManager::VERBS[:post] @@ -511,7 +511,7 @@ RSpec.describe AtomSerializer do reblogged = Fabricate(:status, created_at: '2000-01-01T00:00:00Z') reblog = Fabricate(:status, reblog: reblogged) - entry = AtomSerializer.new.entry(reblog.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(reblog.stream_entry) object = entry.nodes.find { |node| node.name == 'activity:object' } expect(object.id.text).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{reblogged.id}:objectType=Status" @@ -519,7 +519,7 @@ RSpec.describe AtomSerializer do it 'does not append activity:object element if target is not present' do status = Fabricate(:status, reblog_of_id: nil) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) entry.nodes.each { |node| expect(node.name).not_to eq 'activity:object' } end @@ -527,7 +527,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, username: 'username') status = Fabricate(:status, account: account) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) link = entry.nodes.find { |node| node.name == 'link' && node[:rel] == 'alternate' } expect(link[:type]).to eq 'text/html' @@ -538,7 +538,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, username: 'username') status = Fabricate(:status, account: account) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) link = entry.nodes.find { |node| node.name == 'link' && node[:rel] == 'self' } expect(link[:type]).to eq 'application/atom+xml' @@ -549,7 +549,7 @@ RSpec.describe AtomSerializer do in_reply_to_status = Fabricate(:status, created_at: '2000-01-01T00:00:00Z', reblog_of_id: nil) reply_status = Fabricate(:status, in_reply_to_id: in_reply_to_status.id) - entry = AtomSerializer.new.entry(reply_status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(reply_status.stream_entry) in_reply_to = entry.nodes.find { |node| node.name == 'thr:in-reply-to' } expect(in_reply_to[:ref]).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{in_reply_to_status.id}:objectType=Status" @@ -557,7 +557,7 @@ RSpec.describe AtomSerializer do it 'does not append thr:in-reply-to element if not threaded' do status = Fabricate(:status) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) entry.nodes.each { |node| expect(node.name).not_to eq 'thr:in-reply-to' } end @@ -565,7 +565,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status) status.conversation.update!(created_at: '2000-01-01T00:00:00Z') - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) conversation = entry.nodes.find { |node| node.name == 'ostatus:conversation' } expect(conversation[:ref]).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{status.conversation_id}:objectType=Conversation" @@ -575,7 +575,7 @@ RSpec.describe AtomSerializer do status = Fabricate.build(:status, conversation_id: nil) status.save!(validate: false) - entry = AtomSerializer.new.entry(status.stream_entry) + entry = Ostatus::AtomSerializer.new.entry(status.stream_entry) entry.nodes.each { |node| expect(node.name).not_to eq 'ostatus:conversation' } end @@ -585,62 +585,62 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize account = Fabricate(:account) - AtomSerializer.new.feed(account, []) + Ostatus::AtomSerializer.new.feed(account, []) end end it 'returns feed element' do account = Fabricate(:account) - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) expect(feed.name).to eq 'feed' end it 'appends id element with account Atom URL' do account = Fabricate(:account, username: 'username') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) expect(feed.id.text).to eq 'https://cb6e6126.ngrok.io/users/username.atom' end it 'appends title element with account display name if present' do account = Fabricate(:account, display_name: 'display name') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) expect(feed.title.text).to eq 'display name' end it 'does not append title element with account username if account display name is not present' do account = Fabricate(:account, display_name: '', username: 'username') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) expect(feed.title.text).to eq 'username' end it 'appends subtitle element with account note' do account = Fabricate(:account, note: 'note') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) expect(feed.subtitle.text).to eq 'note' end it 'appends updated element with date account got updated' do account = Fabricate(:account, updated_at: '2000-01-01T00:00:00Z') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) expect(feed.updated.text).to eq '2000-01-01T00:00:00Z' end it 'appends logo element with full asset URL for original account avatar' do account = Fabricate(:account, avatar: attachment_fixture('avatar.gif')) - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) expect(feed.logo.text).to match /^https:\/\/cb6e6126.ngrok.io\/system\/accounts\/avatars\/.+\/original\/avatar.gif/ end it 'appends author element' do account = Fabricate(:account, username: 'username') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) expect(feed.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username' end it 'appends link element for an alternative' do account = Fabricate(:account, username: 'username') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) link = feed.nodes.find { |node| node.name == 'link' && node[:rel] == 'alternate' } expect(link[:type]).to eq 'text/html' @@ -650,7 +650,7 @@ RSpec.describe AtomSerializer do it 'appends link element for itself' do account = Fabricate(:account, username: 'username') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) link = feed.nodes.find { |node| node.name == 'link' && node[:rel] == 'self' } expect(link[:type]).to eq 'application/atom+xml' @@ -661,7 +661,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, username: 'username') stream_entry = Fabricate(:stream_entry) - feed = AtomSerializer.new.feed(account, Array.new(20, stream_entry)) + feed = Ostatus::AtomSerializer.new.feed(account, Array.new(20, stream_entry)) link = feed.nodes.find { |node| node.name == 'link' && node[:rel] == 'next' } expect(link[:type]).to eq 'application/atom+xml' @@ -671,7 +671,7 @@ RSpec.describe AtomSerializer do it 'does not append link element for the next if it does not have 20 stream entries' do account = Fabricate(:account, username: 'username') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) feed.nodes.each do |node| expect(node[:rel]).not_to eq 'next' if node.name == 'link' @@ -681,7 +681,7 @@ RSpec.describe AtomSerializer do it 'appends link element for hub' do account = Fabricate(:account, username: 'username') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) link = feed.nodes.find { |node| node.name == 'link' && node[:rel] == 'hub' } expect(link[:href]).to eq 'https://cb6e6126.ngrok.io/api/push' @@ -690,7 +690,7 @@ RSpec.describe AtomSerializer do it 'appends link element for Salmon' do account = Fabricate(:account, username: 'username') - feed = AtomSerializer.new.feed(account, []) + feed = Ostatus::AtomSerializer.new.feed(account, []) link = feed.nodes.find { |node| node.name == 'link' && node[:rel] == 'salmon' } expect(link[:href]).to start_with 'https://cb6e6126.ngrok.io/api/salmon/' @@ -700,7 +700,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, username: 'username') status = Fabricate(:status, account: account) - feed = AtomSerializer.new.feed(account, [status.stream_entry]) + feed = Ostatus::AtomSerializer.new.feed(account, [status.stream_entry]) expect(feed.entry.title.text).to eq 'New status by username' end @@ -710,13 +710,13 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize block = Fabricate(:block) - AtomSerializer.new.block_salmon(block) + Ostatus::AtomSerializer.new.block_salmon(block) end end it 'returns entry element' do block = Fabricate(:block) - block_salmon = AtomSerializer.new.block_salmon(block) + block_salmon = Ostatus::AtomSerializer.new.block_salmon(block) expect(block_salmon.name).to eq 'entry' end @@ -724,7 +724,7 @@ RSpec.describe AtomSerializer do block = Fabricate(:block) time_before = Time.now - block_salmon = AtomSerializer.new.block_salmon(block) + block_salmon = Ostatus::AtomSerializer.new.block_salmon(block) time_after = Time.now expect(block_salmon.id.text).to( @@ -738,7 +738,7 @@ RSpec.describe AtomSerializer do target_account = Fabricate(:account, domain: 'remote', username: 'target_account') block = Fabricate(:block, account: account, target_account: target_account) - block_salmon = AtomSerializer.new.block_salmon(block) + block_salmon = Ostatus::AtomSerializer.new.block_salmon(block) expect(block_salmon.title.text).to eq 'account no longer wishes to interact with target_account@remote' end @@ -747,7 +747,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, domain: nil, username: 'account') block = Fabricate(:block, account: account) - block_salmon = AtomSerializer.new.block_salmon(block) + block_salmon = Ostatus::AtomSerializer.new.block_salmon(block) expect(block_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/account' end @@ -755,7 +755,7 @@ RSpec.describe AtomSerializer do it 'appends activity:object-type element with activity type' do block = Fabricate(:block) - block_salmon = AtomSerializer.new.block_salmon(block) + block_salmon = Ostatus::AtomSerializer.new.block_salmon(block) object_type = block_salmon.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq TagManager::TYPES[:activity] @@ -764,7 +764,7 @@ RSpec.describe AtomSerializer do it 'appends activity:verb element with block' do block = Fabricate(:block) - block_salmon = AtomSerializer.new.block_salmon(block) + block_salmon = Ostatus::AtomSerializer.new.block_salmon(block) verb = block_salmon.nodes.find { |node| node.name == 'activity:verb' } expect(verb.text).to eq TagManager::VERBS[:block] @@ -774,7 +774,7 @@ RSpec.describe AtomSerializer do target_account = Fabricate(:account, domain: 'domain', uri: 'https://domain/id') block = Fabricate(:block, target_account: target_account) - block_salmon = AtomSerializer.new.block_salmon(block) + block_salmon = Ostatus::AtomSerializer.new.block_salmon(block) object = block_salmon.nodes.find { |node| node.name == 'activity:object' } expect(object.id.text).to eq 'https://domain/id' @@ -782,8 +782,8 @@ RSpec.describe AtomSerializer do it 'returns element whose rendered view triggers block when processed' do block = Fabricate(:block) - block_salmon = AtomSerializer.new.block_salmon(block) - xml = AtomSerializer.render(block_salmon) + block_salmon = Ostatus::AtomSerializer.new.block_salmon(block) + xml = Ostatus::AtomSerializer.render(block_salmon) envelope = OStatus2::Salmon.new.pack(xml, block.account.keypair) block.destroy! @@ -797,13 +797,13 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize block = Fabricate(:block) - AtomSerializer.new.unblock_salmon(block) + Ostatus::AtomSerializer.new.unblock_salmon(block) end end it 'returns entry element' do block = Fabricate(:block) - unblock_salmon = AtomSerializer.new.unblock_salmon(block) + unblock_salmon = Ostatus::AtomSerializer.new.unblock_salmon(block) expect(unblock_salmon.name).to eq 'entry' end @@ -811,7 +811,7 @@ RSpec.describe AtomSerializer do block = Fabricate(:block) time_before = Time.now - unblock_salmon = AtomSerializer.new.unblock_salmon(block) + unblock_salmon = Ostatus::AtomSerializer.new.unblock_salmon(block) time_after = Time.now expect(unblock_salmon.id.text).to( @@ -825,7 +825,7 @@ RSpec.describe AtomSerializer do target_account = Fabricate(:account, domain: 'remote', username: 'target_account') block = Fabricate(:block, account: account, target_account: target_account) - unblock_salmon = AtomSerializer.new.unblock_salmon(block) + unblock_salmon = Ostatus::AtomSerializer.new.unblock_salmon(block) expect(unblock_salmon.title.text).to eq 'account no longer blocks target_account@remote' end @@ -834,7 +834,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, domain: nil, username: 'account') block = Fabricate(:block, account: account) - unblock_salmon = AtomSerializer.new.unblock_salmon(block) + unblock_salmon = Ostatus::AtomSerializer.new.unblock_salmon(block) expect(unblock_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/account' end @@ -842,7 +842,7 @@ RSpec.describe AtomSerializer do it 'appends activity:object-type element with activity type' do block = Fabricate(:block) - unblock_salmon = AtomSerializer.new.unblock_salmon(block) + unblock_salmon = Ostatus::AtomSerializer.new.unblock_salmon(block) object_type = unblock_salmon.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq TagManager::TYPES[:activity] @@ -851,7 +851,7 @@ RSpec.describe AtomSerializer do it 'appends activity:verb element with block' do block = Fabricate(:block) - unblock_salmon = AtomSerializer.new.unblock_salmon(block) + unblock_salmon = Ostatus::AtomSerializer.new.unblock_salmon(block) verb = unblock_salmon.nodes.find { |node| node.name == 'activity:verb' } expect(verb.text).to eq TagManager::VERBS[:unblock] @@ -861,7 +861,7 @@ RSpec.describe AtomSerializer do target_account = Fabricate(:account, domain: 'domain', uri: 'https://domain/id') block = Fabricate(:block, target_account: target_account) - unblock_salmon = AtomSerializer.new.unblock_salmon(block) + unblock_salmon = Ostatus::AtomSerializer.new.unblock_salmon(block) object = unblock_salmon.nodes.find { |node| node.name == 'activity:object' } expect(object.id.text).to eq 'https://domain/id' @@ -869,8 +869,8 @@ RSpec.describe AtomSerializer do it 'returns element whose rendered view triggers block when processed' do block = Fabricate(:block) - unblock_salmon = AtomSerializer.new.unblock_salmon(block) - xml = AtomSerializer.render(unblock_salmon) + unblock_salmon = Ostatus::AtomSerializer.new.unblock_salmon(block) + xml = Ostatus::AtomSerializer.render(unblock_salmon) envelope = OStatus2::Salmon.new.pack(xml, block.account.keypair) ProcessInteractionService.new.call(envelope, block.target_account) @@ -883,19 +883,19 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize favourite = Fabricate(:favourite) - AtomSerializer.new.favourite_salmon(favourite) + Ostatus::AtomSerializer.new.favourite_salmon(favourite) end end it 'returns entry element' do favourite = Fabricate(:favourite) - favourite_salmon = AtomSerializer.new.favourite_salmon(favourite) + favourite_salmon = Ostatus::AtomSerializer.new.favourite_salmon(favourite) expect(favourite_salmon.name).to eq 'entry' end it 'appends id element with unique tag' do favourite = Fabricate(:favourite, created_at: '2000-01-01T00:00:00Z') - favourite_salmon = AtomSerializer.new.favourite_salmon(favourite) + favourite_salmon = Ostatus::AtomSerializer.new.favourite_salmon(favourite) expect(favourite_salmon.id.text).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{favourite.id}:objectType=Favourite" end @@ -903,7 +903,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, domain: nil, username: 'username') favourite = Fabricate(:favourite, account: account) - favourite_salmon = AtomSerializer.new.favourite_salmon(favourite) + favourite_salmon = Ostatus::AtomSerializer.new.favourite_salmon(favourite) expect(favourite_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username' end @@ -911,7 +911,7 @@ RSpec.describe AtomSerializer do it 'appends activity:object-type element with activity type' do favourite = Fabricate(:favourite) - favourite_salmon = AtomSerializer.new.favourite_salmon(favourite) + favourite_salmon = Ostatus::AtomSerializer.new.favourite_salmon(favourite) object_type = favourite_salmon.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq 'http://activitystrea.ms/schema/1.0/activity' @@ -920,7 +920,7 @@ RSpec.describe AtomSerializer do it 'appends activity:verb element with favorite' do favourite = Fabricate(:favourite) - favourite_salmon = AtomSerializer.new.favourite_salmon(favourite) + favourite_salmon = Ostatus::AtomSerializer.new.favourite_salmon(favourite) verb = favourite_salmon.nodes.find { |node| node.name == 'activity:verb' } expect(verb.text).to eq TagManager::VERBS[:favorite] @@ -930,7 +930,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status, created_at: '2000-01-01T00:00:00Z') favourite = Fabricate(:favourite, status: status) - favourite_salmon = AtomSerializer.new.favourite_salmon(favourite) + favourite_salmon = Ostatus::AtomSerializer.new.favourite_salmon(favourite) object = favourite_salmon.nodes.find { |node| node.name == 'activity:object' } expect(object.id.text).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{status.id}:objectType=Status" @@ -941,7 +941,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status, account: status_account, created_at: '2000-01-01T00:00:00Z') favourite = Fabricate(:favourite, status: status) - favourite_salmon = AtomSerializer.new.favourite_salmon(favourite) + favourite_salmon = Ostatus::AtomSerializer.new.favourite_salmon(favourite) in_reply_to = favourite_salmon.nodes.find { |node| node.name == 'thr:in-reply-to' } expect(in_reply_to.ref).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{status.id}:objectType=Status" @@ -954,7 +954,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status, account: status_account) favourite = Fabricate(:favourite, account: account, status: status) - favourite_salmon = AtomSerializer.new.favourite_salmon(favourite) + favourite_salmon = Ostatus::AtomSerializer.new.favourite_salmon(favourite) expect(favourite_salmon.title.text).to eq 'account favourited a status by status_account@remote' expect(favourite_salmon.content.text).to eq 'account favourited a status by status_account@remote' @@ -962,8 +962,8 @@ RSpec.describe AtomSerializer do it 'returns element whose rendered view triggers favourite when processed' do favourite = Fabricate(:favourite) - favourite_salmon = AtomSerializer.new.favourite_salmon(favourite) - xml = AtomSerializer.render(favourite_salmon) + favourite_salmon = Ostatus::AtomSerializer.new.favourite_salmon(favourite) + xml = Ostatus::AtomSerializer.render(favourite_salmon) envelope = OStatus2::Salmon.new.pack(xml, favourite.account.keypair) favourite.destroy! @@ -976,13 +976,13 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize favourite = Fabricate(:favourite) - AtomSerializer.new.favourite_salmon(favourite) + Ostatus::AtomSerializer.new.favourite_salmon(favourite) end end it 'returns entry element' do favourite = Fabricate(:favourite) - unfavourite_salmon = AtomSerializer.new.unfavourite_salmon(favourite) + unfavourite_salmon = Ostatus::AtomSerializer.new.unfavourite_salmon(favourite) expect(unfavourite_salmon.name).to eq 'entry' end @@ -990,7 +990,7 @@ RSpec.describe AtomSerializer do favourite = Fabricate(:favourite) time_before = Time.now - unfavourite_salmon = AtomSerializer.new.unfavourite_salmon(favourite) + unfavourite_salmon = Ostatus::AtomSerializer.new.unfavourite_salmon(favourite) time_after = Time.now expect(unfavourite_salmon.id.text).to( @@ -1003,7 +1003,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, domain: nil, username: 'username') favourite = Fabricate(:favourite, account: account) - unfavourite_salmon = AtomSerializer.new.unfavourite_salmon(favourite) + unfavourite_salmon = Ostatus::AtomSerializer.new.unfavourite_salmon(favourite) expect(unfavourite_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username' end @@ -1011,7 +1011,7 @@ RSpec.describe AtomSerializer do it 'appends activity:object-type element with activity type' do favourite = Fabricate(:favourite) - unfavourite_salmon = AtomSerializer.new.unfavourite_salmon(favourite) + unfavourite_salmon = Ostatus::AtomSerializer.new.unfavourite_salmon(favourite) object_type = unfavourite_salmon.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq 'http://activitystrea.ms/schema/1.0/activity' @@ -1020,7 +1020,7 @@ RSpec.describe AtomSerializer do it 'appends activity:verb element with favorite' do favourite = Fabricate(:favourite) - unfavourite_salmon = AtomSerializer.new.unfavourite_salmon(favourite) + unfavourite_salmon = Ostatus::AtomSerializer.new.unfavourite_salmon(favourite) verb = unfavourite_salmon.nodes.find { |node| node.name == 'activity:verb' } expect(verb.text).to eq TagManager::VERBS[:unfavorite] @@ -1030,7 +1030,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status, created_at: '2000-01-01T00:00:00Z') favourite = Fabricate(:favourite, status: status) - unfavourite_salmon = AtomSerializer.new.unfavourite_salmon(favourite) + unfavourite_salmon = Ostatus::AtomSerializer.new.unfavourite_salmon(favourite) object = unfavourite_salmon.nodes.find { |node| node.name == 'activity:object' } expect(object.id.text).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{status.id}:objectType=Status" @@ -1041,7 +1041,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status, account: status_account, created_at: '2000-01-01T00:00:00Z') favourite = Fabricate(:favourite, status: status) - unfavourite_salmon = AtomSerializer.new.unfavourite_salmon(favourite) + unfavourite_salmon = Ostatus::AtomSerializer.new.unfavourite_salmon(favourite) in_reply_to = unfavourite_salmon.nodes.find { |node| node.name == 'thr:in-reply-to' } expect(in_reply_to.ref).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{status.id}:objectType=Status" @@ -1054,7 +1054,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status, account: status_account) favourite = Fabricate(:favourite, account: account, status: status) - unfavourite_salmon = AtomSerializer.new.unfavourite_salmon(favourite) + unfavourite_salmon = Ostatus::AtomSerializer.new.unfavourite_salmon(favourite) expect(unfavourite_salmon.title.text).to eq 'account no longer favourites a status by status_account@remote' expect(unfavourite_salmon.content.text).to eq 'account no longer favourites a status by status_account@remote' @@ -1062,8 +1062,8 @@ RSpec.describe AtomSerializer do it 'returns element whose rendered view triggers unfavourite when processed' do favourite = Fabricate(:favourite) - unfavourite_salmon = AtomSerializer.new.unfavourite_salmon(favourite) - xml = AtomSerializer.render(unfavourite_salmon) + unfavourite_salmon = Ostatus::AtomSerializer.new.unfavourite_salmon(favourite) + xml = Ostatus::AtomSerializer.render(unfavourite_salmon) envelope = OStatus2::Salmon.new.pack(xml, favourite.account.keypair) ProcessInteractionService.new.call(envelope, favourite.status.account) @@ -1075,19 +1075,19 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize follow = Fabricate(:follow) - AtomSerializer.new.follow_salmon(follow) + Ostatus::AtomSerializer.new.follow_salmon(follow) end end it 'returns entry element' do follow = Fabricate(:follow) - follow_salmon = AtomSerializer.new.follow_salmon(follow) + follow_salmon = Ostatus::AtomSerializer.new.follow_salmon(follow) expect(follow_salmon.name).to eq 'entry' end it 'appends id element with unique tag' do follow = Fabricate(:follow, created_at: '2000-01-01T00:00:00Z') - follow_salmon = AtomSerializer.new.follow_salmon(follow) + follow_salmon = Ostatus::AtomSerializer.new.follow_salmon(follow) expect(follow_salmon.id.text).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{follow.id}:objectType=Follow" end @@ -1095,7 +1095,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, domain: nil, username: 'username') follow = Fabricate(:follow, account: account) - follow_salmon = AtomSerializer.new.follow_salmon(follow) + follow_salmon = Ostatus::AtomSerializer.new.follow_salmon(follow) expect(follow_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username' end @@ -1103,7 +1103,7 @@ RSpec.describe AtomSerializer do it 'appends activity:object-type element with activity type' do follow = Fabricate(:follow) - follow_salmon = AtomSerializer.new.follow_salmon(follow) + follow_salmon = Ostatus::AtomSerializer.new.follow_salmon(follow) object_type = follow_salmon.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq TagManager::TYPES[:activity] @@ -1112,7 +1112,7 @@ RSpec.describe AtomSerializer do it 'appends activity:verb element with follow' do follow = Fabricate(:follow) - follow_salmon = AtomSerializer.new.follow_salmon(follow) + follow_salmon = Ostatus::AtomSerializer.new.follow_salmon(follow) verb = follow_salmon.nodes.find { |node| node.name == 'activity:verb' } expect(verb.text).to eq TagManager::VERBS[:follow] @@ -1122,7 +1122,7 @@ RSpec.describe AtomSerializer do target_account = Fabricate(:account, domain: 'domain', uri: 'https://domain/id') follow = Fabricate(:follow, target_account: target_account) - follow_salmon = AtomSerializer.new.follow_salmon(follow) + follow_salmon = Ostatus::AtomSerializer.new.follow_salmon(follow) object = follow_salmon.nodes.find { |node| node.name == 'activity:object' } expect(object.id.text).to eq 'https://domain/id' @@ -1133,7 +1133,7 @@ RSpec.describe AtomSerializer do target_account = Fabricate(:account, domain: 'remote', username: 'target_account') follow = Fabricate(:follow, account: account, target_account: target_account) - follow_salmon = AtomSerializer.new.follow_salmon(follow) + follow_salmon = Ostatus::AtomSerializer.new.follow_salmon(follow) expect(follow_salmon.title.text).to eq 'account started following target_account@remote' expect(follow_salmon.content.text).to eq 'account started following target_account@remote' @@ -1141,8 +1141,8 @@ RSpec.describe AtomSerializer do it 'returns element whose rendered view triggers follow when processed' do follow = Fabricate(:follow) - follow_salmon = AtomSerializer.new.follow_salmon(follow) - xml = AtomSerializer.render(follow_salmon) + follow_salmon = Ostatus::AtomSerializer.new.follow_salmon(follow) + xml = Ostatus::AtomSerializer.render(follow_salmon) follow.destroy! envelope = OStatus2::Salmon.new.pack(xml, follow.account.keypair) @@ -1157,7 +1157,7 @@ RSpec.describe AtomSerializer do def serialize follow = Fabricate(:follow) follow.destroy! - AtomSerializer.new.unfollow_salmon(follow) + Ostatus::AtomSerializer.new.unfollow_salmon(follow) end end @@ -1165,7 +1165,7 @@ RSpec.describe AtomSerializer do follow = Fabricate(:follow) follow.destroy! - unfollow_salmon = AtomSerializer.new.unfollow_salmon(follow) + unfollow_salmon = Ostatus::AtomSerializer.new.unfollow_salmon(follow) expect(unfollow_salmon.name).to eq 'entry' end @@ -1175,7 +1175,7 @@ RSpec.describe AtomSerializer do follow.destroy! time_before = Time.now - unfollow_salmon = AtomSerializer.new.unfollow_salmon(follow) + unfollow_salmon = Ostatus::AtomSerializer.new.unfollow_salmon(follow) time_after = Time.now expect(unfollow_salmon.id.text).to( @@ -1190,7 +1190,7 @@ RSpec.describe AtomSerializer do follow = Fabricate(:follow, account: account, target_account: target_account) follow.destroy! - unfollow_salmon = AtomSerializer.new.unfollow_salmon(follow) + unfollow_salmon = Ostatus::AtomSerializer.new.unfollow_salmon(follow) expect(unfollow_salmon.title.text).to eq 'account is no longer following target_account@remote' end @@ -1201,7 +1201,7 @@ RSpec.describe AtomSerializer do follow = Fabricate(:follow, account: account, target_account: target_account) follow.destroy! - unfollow_salmon = AtomSerializer.new.unfollow_salmon(follow) + unfollow_salmon = Ostatus::AtomSerializer.new.unfollow_salmon(follow) expect(unfollow_salmon.content.text).to eq 'account is no longer following target_account@remote' end @@ -1211,7 +1211,7 @@ RSpec.describe AtomSerializer do follow = Fabricate(:follow, account: account) follow.destroy! - unfollow_salmon = AtomSerializer.new.unfollow_salmon(follow) + unfollow_salmon = Ostatus::AtomSerializer.new.unfollow_salmon(follow) expect(unfollow_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username' end @@ -1220,7 +1220,7 @@ RSpec.describe AtomSerializer do follow = Fabricate(:follow) follow.destroy! - unfollow_salmon = AtomSerializer.new.unfollow_salmon(follow) + unfollow_salmon = Ostatus::AtomSerializer.new.unfollow_salmon(follow) object_type = unfollow_salmon.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq TagManager::TYPES[:activity] @@ -1230,7 +1230,7 @@ RSpec.describe AtomSerializer do follow = Fabricate(:follow) follow.destroy! - unfollow_salmon = AtomSerializer.new.unfollow_salmon(follow) + unfollow_salmon = Ostatus::AtomSerializer.new.unfollow_salmon(follow) verb = unfollow_salmon.nodes.find { |node| node.name == 'activity:verb' } expect(verb.text).to eq TagManager::VERBS[:unfollow] @@ -1241,7 +1241,7 @@ RSpec.describe AtomSerializer do follow = Fabricate(:follow, target_account: target_account) follow.destroy! - unfollow_salmon = AtomSerializer.new.unfollow_salmon(follow) + unfollow_salmon = Ostatus::AtomSerializer.new.unfollow_salmon(follow) object = unfollow_salmon.nodes.find { |node| node.name == 'activity:object' } expect(object.id.text).to eq 'https://domain/id' @@ -1250,8 +1250,8 @@ RSpec.describe AtomSerializer do it 'returns element whose rendered view triggers unfollow when processed' do follow = Fabricate(:follow) follow.destroy! - unfollow_salmon = AtomSerializer.new.unfollow_salmon(follow) - xml = AtomSerializer.render(unfollow_salmon) + unfollow_salmon = Ostatus::AtomSerializer.new.unfollow_salmon(follow) + xml = Ostatus::AtomSerializer.render(unfollow_salmon) follow.account.follow!(follow.target_account) envelope = OStatus2::Salmon.new.pack(xml, follow.account.keypair) @@ -1265,13 +1265,13 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize follow_request = Fabricate(:follow_request) - AtomSerializer.new.follow_request_salmon(follow_request) + Ostatus::AtomSerializer.new.follow_request_salmon(follow_request) end end context do def serialize(follow_request) - AtomSerializer.new.follow_request_salmon(follow_request) + Ostatus::AtomSerializer.new.follow_request_salmon(follow_request) end it_behaves_like 'follow request salmon' @@ -1293,7 +1293,7 @@ RSpec.describe AtomSerializer do it 'returns element whose rendered view triggers follow request when processed' do follow_request = Fabricate(:follow_request) follow_request_salmon = serialize(follow_request) - xml = AtomSerializer.render(follow_request_salmon) + xml = Ostatus::AtomSerializer.render(follow_request_salmon) envelope = OStatus2::Salmon.new.pack(xml, follow_request.account.keypair) follow_request.destroy! @@ -1308,13 +1308,13 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize follow_request = Fabricate(:follow_request) - AtomSerializer.new.authorize_follow_request_salmon(follow_request) + Ostatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request) end end it_behaves_like 'follow request salmon' do def serialize(follow_request) - authorize_follow_request_salmon = AtomSerializer.new.authorize_follow_request_salmon(follow_request) + authorize_follow_request_salmon = Ostatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request) authorize_follow_request_salmon.nodes.find { |node| node.name == 'activity:object' } end end @@ -1323,7 +1323,7 @@ RSpec.describe AtomSerializer do follow_request = Fabricate(:follow_request) time_before = Time.now - authorize_follow_request_salmon = AtomSerializer.new.authorize_follow_request_salmon(follow_request) + authorize_follow_request_salmon = Ostatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request) time_after = Time.now expect(authorize_follow_request_salmon.id.text).to( @@ -1337,7 +1337,7 @@ RSpec.describe AtomSerializer do target_account = Fabricate(:account, domain: nil, username: 'target_account') follow_request = Fabricate(:follow_request, account: account, target_account: target_account) - authorize_follow_request_salmon = AtomSerializer.new.authorize_follow_request_salmon(follow_request) + authorize_follow_request_salmon = Ostatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request) expect(authorize_follow_request_salmon.title.text).to eq 'target_account authorizes follow request by account@remote' end @@ -1345,7 +1345,7 @@ RSpec.describe AtomSerializer do it 'appends activity:object-type element with activity type' do follow_request = Fabricate(:follow_request) - authorize_follow_request_salmon = AtomSerializer.new.authorize_follow_request_salmon(follow_request) + authorize_follow_request_salmon = Ostatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request) object_type = authorize_follow_request_salmon.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq TagManager::TYPES[:activity] @@ -1354,7 +1354,7 @@ RSpec.describe AtomSerializer do it 'appends activity:verb element with authorize' do follow_request = Fabricate(:follow_request) - authorize_follow_request_salmon = AtomSerializer.new.authorize_follow_request_salmon(follow_request) + authorize_follow_request_salmon = Ostatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request) verb = authorize_follow_request_salmon.nodes.find { |node| node.name == 'activity:verb' } expect(verb.text).to eq TagManager::VERBS[:authorize] @@ -1362,8 +1362,8 @@ RSpec.describe AtomSerializer do it 'returns element whose rendered view creates follow from follow request when processed' do follow_request = Fabricate(:follow_request) - authorize_follow_request_salmon = AtomSerializer.new.authorize_follow_request_salmon(follow_request) - xml = AtomSerializer.render(authorize_follow_request_salmon) + authorize_follow_request_salmon = Ostatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request) + xml = Ostatus::AtomSerializer.render(authorize_follow_request_salmon) envelope = OStatus2::Salmon.new.pack(xml, follow_request.target_account.keypair) ProcessInteractionService.new.call(envelope, follow_request.account) @@ -1377,13 +1377,13 @@ RSpec.describe AtomSerializer do include_examples 'namespaces' do def serialize follow_request = Fabricate(:follow_request) - AtomSerializer.new.reject_follow_request_salmon(follow_request) + Ostatus::AtomSerializer.new.reject_follow_request_salmon(follow_request) end end it_behaves_like 'follow request salmon' do def serialize(follow_request) - reject_follow_request_salmon = AtomSerializer.new.reject_follow_request_salmon(follow_request) + reject_follow_request_salmon = Ostatus::AtomSerializer.new.reject_follow_request_salmon(follow_request) reject_follow_request_salmon.nodes.find { |node| node.name == 'activity:object' } end end @@ -1392,7 +1392,7 @@ RSpec.describe AtomSerializer do follow_request = Fabricate(:follow_request) time_before = Time.now - reject_follow_request_salmon = AtomSerializer.new.reject_follow_request_salmon(follow_request) + reject_follow_request_salmon = Ostatus::AtomSerializer.new.reject_follow_request_salmon(follow_request) time_after = Time.now expect(reject_follow_request_salmon.id.text).to( @@ -1405,28 +1405,28 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, domain: 'remote', username: 'account') target_account = Fabricate(:account, domain: nil, username: 'target_account') follow_request = Fabricate(:follow_request, account: account, target_account: target_account) - reject_follow_request_salmon = AtomSerializer.new.reject_follow_request_salmon(follow_request) + reject_follow_request_salmon = Ostatus::AtomSerializer.new.reject_follow_request_salmon(follow_request) expect(reject_follow_request_salmon.title.text).to eq 'target_account rejects follow request by account@remote' end it 'appends activity:object-type element with activity type' do follow_request = Fabricate(:follow_request) - reject_follow_request_salmon = AtomSerializer.new.reject_follow_request_salmon(follow_request) + reject_follow_request_salmon = Ostatus::AtomSerializer.new.reject_follow_request_salmon(follow_request) object_type = reject_follow_request_salmon.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq TagManager::TYPES[:activity] end it 'appends activity:verb element with authorize' do follow_request = Fabricate(:follow_request) - reject_follow_request_salmon = AtomSerializer.new.reject_follow_request_salmon(follow_request) + reject_follow_request_salmon = Ostatus::AtomSerializer.new.reject_follow_request_salmon(follow_request) verb = reject_follow_request_salmon.nodes.find { |node| node.name == 'activity:verb' } expect(verb.text).to eq TagManager::VERBS[:reject] end it 'returns element whose rendered view deletes follow request when processed' do follow_request = Fabricate(:follow_request) - reject_follow_request_salmon = AtomSerializer.new.reject_follow_request_salmon(follow_request) - xml = AtomSerializer.render(reject_follow_request_salmon) + reject_follow_request_salmon = Ostatus::AtomSerializer.new.reject_follow_request_salmon(follow_request) + xml = Ostatus::AtomSerializer.render(reject_follow_request_salmon) envelope = OStatus2::Salmon.new.pack(xml, follow_request.target_account.keypair) ProcessInteractionService.new.call(envelope, follow_request.account) @@ -1439,31 +1439,31 @@ RSpec.describe AtomSerializer do describe '#object' do include_examples 'status attributes' do def serialize(status) - AtomSerializer.new.object(status) + Ostatus::AtomSerializer.new.object(status) end end it 'returns activity:object element' do status = Fabricate(:status) - object = AtomSerializer.new.object(status) + object = Ostatus::AtomSerializer.new.object(status) expect(object.name).to eq 'activity:object' end it 'appends id element with URL for status' do status = Fabricate(:status, created_at: '2000-01-01T00:00:00Z') - object = AtomSerializer.new.object(status) + object = Ostatus::AtomSerializer.new.object(status) expect(object.id.text).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{status.id}:objectType=Status" end it 'appends published element with created date' do status = Fabricate(:status, created_at: '2000-01-01T00:00:00Z') - object = AtomSerializer.new.object(status) + object = Ostatus::AtomSerializer.new.object(status) expect(object.published.text).to eq '2000-01-01T00:00:00Z' end it 'appends updated element with updated date' do status = Fabricate(:status, updated_at: '2000-01-01T00:00:00Z') - object = AtomSerializer.new.object(status) + object = Ostatus::AtomSerializer.new.object(status) expect(object.updated.text).to eq '2000-01-01T00:00:00Z' end @@ -1471,7 +1471,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, username: 'username') status = Fabricate(:status, account: account) - object = AtomSerializer.new.object(status) + object = Ostatus::AtomSerializer.new.object(status) expect(object.title.text).to eq 'New status by username' end @@ -1480,7 +1480,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, username: 'username') status = Fabricate(:status, account: account) - entry = AtomSerializer.new.object(status) + entry = Ostatus::AtomSerializer.new.object(status) expect(entry.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username' end @@ -1488,7 +1488,7 @@ RSpec.describe AtomSerializer do it 'appends activity:object-type element with object type' do status = Fabricate(:status) - entry = AtomSerializer.new.object(status) + entry = Ostatus::AtomSerializer.new.object(status) object_type = entry.nodes.find { |node| node.name == 'activity:object-type' } expect(object_type.text).to eq TagManager::TYPES[:note] @@ -1497,7 +1497,7 @@ RSpec.describe AtomSerializer do it 'appends activity:verb element with verb' do status = Fabricate(:status) - entry = AtomSerializer.new.object(status) + entry = Ostatus::AtomSerializer.new.object(status) object_type = entry.nodes.find { |node| node.name == 'activity:verb' } expect(object_type.text).to eq TagManager::VERBS[:post] @@ -1507,7 +1507,7 @@ RSpec.describe AtomSerializer do account = Fabricate(:account, username: 'username') status = Fabricate(:status, account: account) - entry = AtomSerializer.new.object(status) + entry = Ostatus::AtomSerializer.new.object(status) link = entry.nodes.find { |node| node.name == 'link' && node[:rel] == 'alternate' } expect(link[:type]).to eq 'text/html' @@ -1519,7 +1519,7 @@ RSpec.describe AtomSerializer do thread = Fabricate(:status, account: account, created_at: '2000-01-01T00:00:00Z') reply = Fabricate(:status, thread: thread) - entry = AtomSerializer.new.object(reply) + entry = Ostatus::AtomSerializer.new.object(reply) in_reply_to = entry.nodes.find { |node| node.name == 'thr:in-reply-to' } expect(in_reply_to.ref).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{thread.id}:objectType=Status" @@ -1528,7 +1528,7 @@ RSpec.describe AtomSerializer do it 'does not append thr:in-reply-to element if thread is nil' do status = Fabricate(:status, thread: nil) - entry = AtomSerializer.new.object(status) + entry = Ostatus::AtomSerializer.new.object(status) entry.nodes.each { |node| expect(node.name).not_to eq 'thr:in-reply-to' } end @@ -1536,7 +1536,7 @@ RSpec.describe AtomSerializer do status = Fabricate.build(:status, conversation_id: nil) status.save!(validate: false) - entry = AtomSerializer.new.object(status) + entry = Ostatus::AtomSerializer.new.object(status) entry.nodes.each { |node| expect(node.name).not_to eq 'ostatus:conversation' } end @@ -1545,7 +1545,7 @@ RSpec.describe AtomSerializer do status = Fabricate(:status) status.conversation.update!(created_at: '2000-01-01T00:00:00Z') - entry = AtomSerializer.new.object(status) + entry = Ostatus::AtomSerializer.new.object(status) conversation = entry.nodes.find { |node| node.name == 'ostatus:conversation' } expect(conversation[:ref]).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{status.conversation.id}:objectType=Conversation" diff --git a/spec/services/process_feed_service_spec.rb b/spec/services/process_feed_service_spec.rb index d85ee3b56..5e34370ee 100644 --- a/spec/services/process_feed_service_spec.rb +++ b/spec/services/process_feed_service_spec.rb @@ -167,6 +167,46 @@ XML expect(created_statuses.first.reblog.text).to eq 'Overwatch rocks' end + it 'ignores reblogs if it failed to retreive reblogged statuses' do + stub_request(:head, 'https://overwatch.com/users/tracer/updates/1').to_return(status: 404) + + actor = Fabricate(:account, username: 'tracer', domain: 'overwatch.com') + + body = < + + tag:overwatch.com,2017-04-27:objectId=4467137:objectType=Status + 2017-04-27T13:49:25Z + 2017-04-27T13:49:25Z + + https://overwatch.com/users/tracer + http://activitystrea.ms/schema/1.0/person + https://overwatch.com/users/tracer + tracer + + http://activitystrea.ms/schema/1.0/activity + http://activitystrea.ms/schema/1.0/share + Overwatch rocks + + tag:overwatch.com,2017-04-27:objectId=4467137:objectType=Status + http://activitystrea.ms/schema/1.0/note + http://activitystrea.ms/schema/1.0/post + + https://overwatch.com/users/tracer + http://activitystrea.ms/schema/1.0/person + https://overwatch.com/users/tracer + tracer + + Overwatch rocks + + +XML + + created_statuses = subject.call(body, actor) + + expect(created_statuses).to eq [] + end + it 'ignores statuses with an out-of-order delete' do sender = Fabricate(:account, username: 'tracer', domain: 'overwatch.com') From 3267e4a7851b57bef7d16da4b7c66764f63d4416 Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Wed, 19 Jul 2017 00:14:43 +0900 Subject: [PATCH 12/16] Add unfollow modal (optional) (#4246) * Add unfollow modal * unfollowing someone * remove unnecessary prop --- .../settings/preferences_controller.rb | 1 + .../mastodon/containers/account_container.js | 24 ++++++++++++++++--- .../containers/header_container.js | 14 ++++++++++- .../features/ui/components/modal_root.js | 2 +- app/javascript/mastodon/locales/ar.json | 2 ++ app/javascript/mastodon/locales/bg.json | 2 ++ app/javascript/mastodon/locales/ca.json | 2 ++ app/javascript/mastodon/locales/de.json | 2 ++ .../mastodon/locales/defaultMessages.json | 21 ++++++++++++++++ app/javascript/mastodon/locales/en.json | 2 ++ app/javascript/mastodon/locales/eo.json | 2 ++ app/javascript/mastodon/locales/es.json | 2 ++ app/javascript/mastodon/locales/fa.json | 2 ++ app/javascript/mastodon/locales/fi.json | 2 ++ app/javascript/mastodon/locales/fr.json | 2 ++ app/javascript/mastodon/locales/he.json | 2 ++ app/javascript/mastodon/locales/hr.json | 2 ++ app/javascript/mastodon/locales/hu.json | 2 ++ app/javascript/mastodon/locales/id.json | 2 ++ app/javascript/mastodon/locales/io.json | 2 ++ app/javascript/mastodon/locales/it.json | 2 ++ app/javascript/mastodon/locales/ja.json | 2 ++ app/javascript/mastodon/locales/ko.json | 2 ++ app/javascript/mastodon/locales/nl.json | 2 ++ app/javascript/mastodon/locales/no.json | 2 ++ app/javascript/mastodon/locales/oc.json | 2 ++ app/javascript/mastodon/locales/pl.json | 2 ++ app/javascript/mastodon/locales/pt-BR.json | 2 ++ app/javascript/mastodon/locales/pt.json | 2 ++ app/javascript/mastodon/locales/ru.json | 2 ++ app/javascript/mastodon/locales/th.json | 2 ++ app/javascript/mastodon/locales/tr.json | 2 ++ app/javascript/mastodon/locales/uk.json | 2 ++ app/javascript/mastodon/locales/zh-CN.json | 2 ++ app/javascript/mastodon/locales/zh-HK.json | 2 ++ app/javascript/mastodon/locales/zh-TW.json | 2 ++ app/lib/user_settings_decorator.rb | 5 ++++ app/models/user.rb | 4 ++++ app/serializers/initial_state_serializer.rb | 1 + app/views/settings/preferences/show.html.haml | 1 + config/locales/simple_form.en.yml | 1 + spec/lib/user_settings_decorator_spec.rb | 7 ++++++ spec/models/user_spec.rb | 8 +++++++ 43 files changed, 146 insertions(+), 5 deletions(-) diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb index a3f5a008b..f107f2b16 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences_controller.rb @@ -35,6 +35,7 @@ class Settings::PreferencesController < ApplicationController params.require(:user).permit( :setting_default_privacy, :setting_default_sensitive, + :setting_unfollow_modal, :setting_boost_modal, :setting_delete_modal, :setting_auto_play_gif, diff --git a/app/javascript/mastodon/containers/account_container.js b/app/javascript/mastodon/containers/account_container.js index 1426bcaa4..ca1efd0e5 100644 --- a/app/javascript/mastodon/containers/account_container.js +++ b/app/javascript/mastodon/containers/account_container.js @@ -1,4 +1,6 @@ +import React from 'react'; import { connect } from 'react-redux'; +import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import { makeGetAccount } from '../selectors'; import Account from '../components/account'; import { @@ -9,6 +11,11 @@ import { muteAccount, unmuteAccount, } from '../actions/accounts'; +import { openModal } from '../actions/modal'; + +const messages = defineMessages({ + unfollowConfirm: { id: 'confirmations.unfollow.confirm', defaultMessage: 'Unfollow' }, +}); const makeMapStateToProps = () => { const getAccount = makeGetAccount(); @@ -16,15 +23,25 @@ const makeMapStateToProps = () => { const mapStateToProps = (state, props) => ({ account: getAccount(state, props.id), me: state.getIn(['meta', 'me']), + unfollowModal: state.getIn(['meta', 'unfollow_modal']), }); return mapStateToProps; }; -const mapDispatchToProps = (dispatch) => ({ +const mapDispatchToProps = (dispatch, { intl }) => ({ + onFollow (account) { if (account.getIn(['relationship', 'following'])) { - dispatch(unfollowAccount(account.get('id'))); + if (this.unfollowModal) { + dispatch(openModal('CONFIRM', { + message: @{account.get('acct')} }} />, + confirm: intl.formatMessage(messages.unfollowConfirm), + onConfirm: () => dispatch(unfollowAccount(account.get('id'))), + })); + } else { + dispatch(unfollowAccount(account.get('id'))); + } } else { dispatch(followAccount(account.get('id'))); } @@ -45,6 +62,7 @@ const mapDispatchToProps = (dispatch) => ({ dispatch(muteAccount(account.get('id'))); } }, + }); -export default connect(makeMapStateToProps, mapDispatchToProps)(Account); +export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Account)); diff --git a/app/javascript/mastodon/features/account_timeline/containers/header_container.js b/app/javascript/mastodon/features/account_timeline/containers/header_container.js index 19dd64699..baa81bbc2 100644 --- a/app/javascript/mastodon/features/account_timeline/containers/header_container.js +++ b/app/javascript/mastodon/features/account_timeline/containers/header_container.js @@ -17,6 +17,7 @@ import { blockDomain, unblockDomain } from '../../../actions/domain_blocks'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; const messages = defineMessages({ + unfollowConfirm: { id: 'confirmations.unfollow.confirm', defaultMessage: 'Unfollow' }, blockConfirm: { id: 'confirmations.block.confirm', defaultMessage: 'Block' }, muteConfirm: { id: 'confirmations.mute.confirm', defaultMessage: 'Mute' }, blockDomainConfirm: { id: 'confirmations.domain_block.confirm', defaultMessage: 'Hide entire domain' }, @@ -28,15 +29,25 @@ const makeMapStateToProps = () => { const mapStateToProps = (state, { accountId }) => ({ account: getAccount(state, Number(accountId)), me: state.getIn(['meta', 'me']), + unfollowModal: state.getIn(['meta', 'unfollow_modal']), }); return mapStateToProps; }; const mapDispatchToProps = (dispatch, { intl }) => ({ + onFollow (account) { if (account.getIn(['relationship', 'following'])) { - dispatch(unfollowAccount(account.get('id'))); + if (this.unfollowModal) { + dispatch(openModal('CONFIRM', { + message: @{account.get('acct')} }} />, + confirm: intl.formatMessage(messages.unfollowConfirm), + onConfirm: () => dispatch(unfollowAccount(account.get('id'))), + })); + } else { + dispatch(unfollowAccount(account.get('id'))); + } } else { dispatch(followAccount(account.get('id'))); } @@ -85,6 +96,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({ onUnblockDomain (domain, accountId) { dispatch(unblockDomain(domain, accountId)); }, + }); export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Header)); diff --git a/app/javascript/mastodon/features/ui/components/modal_root.js b/app/javascript/mastodon/features/ui/components/modal_root.js index 4240871a7..f303088d7 100644 --- a/app/javascript/mastodon/features/ui/components/modal_root.js +++ b/app/javascript/mastodon/features/ui/components/modal_root.js @@ -85,7 +85,7 @@ export default class ModalRoot extends React.PureComponent { > {interpolatedStyles =>
- {interpolatedStyles.map(({ key, data: { type }, style }) => ( + {interpolatedStyles.map(({ key, data: { type, props }, style }) => (
diff --git a/app/javascript/mastodon/locales/ar.json b/app/javascript/mastodon/locales/ar.json index 7b890ce64..89ddb2d15 100644 --- a/app/javascript/mastodon/locales/ar.json +++ b/app/javascript/mastodon/locales/ar.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable.", "confirmations.mute.confirm": "أكتم", "confirmations.mute.message": "هل أنت متأكد أنك تريد كتم {name} ؟", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "الأنشطة", "emoji_button.flags": "الأعلام", "emoji_button.food": "الطعام والشراب", diff --git a/app/javascript/mastodon/locales/bg.json b/app/javascript/mastodon/locales/bg.json index 0cf6bf3ac..3dba91b82 100644 --- a/app/javascript/mastodon/locales/bg.json +++ b/app/javascript/mastodon/locales/bg.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable.", "confirmations.mute.confirm": "Mute", "confirmations.mute.message": "Are you sure you want to mute {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Activity", "emoji_button.flags": "Flags", "emoji_button.food": "Food & Drink", diff --git a/app/javascript/mastodon/locales/ca.json b/app/javascript/mastodon/locales/ca.json index 1e44d6fa5..54f2e5e22 100644 --- a/app/javascript/mastodon/locales/ca.json +++ b/app/javascript/mastodon/locales/ca.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Estàs realment, realment segur que vols bloquejar totalment {domain}? En la majoria dels casos bloquejar o silenciar és suficient i preferible.", "confirmations.mute.confirm": "Silenciar", "confirmations.mute.message": "Estàs segur que vols silenciar {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Activitat", "emoji_button.flags": "Flags", "emoji_button.food": "Menjar i Beure", diff --git a/app/javascript/mastodon/locales/de.json b/app/javascript/mastodon/locales/de.json index f73011e73..a041e6655 100644 --- a/app/javascript/mastodon/locales/de.json +++ b/app/javascript/mastodon/locales/de.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable.", "confirmations.mute.confirm": "Mute", "confirmations.mute.message": "Are you sure you want to mute {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Activity", "emoji_button.flags": "Flags", "emoji_button.food": "Food & Drink", diff --git a/app/javascript/mastodon/locales/defaultMessages.json b/app/javascript/mastodon/locales/defaultMessages.json index aaa558c0e..bf462a537 100644 --- a/app/javascript/mastodon/locales/defaultMessages.json +++ b/app/javascript/mastodon/locales/defaultMessages.json @@ -228,6 +228,19 @@ ], "path": "app/javascript/mastodon/components/video_player.json" }, + { + "descriptors": [ + { + "defaultMessage": "Unfollow", + "id": "confirmations.unfollow.confirm" + }, + { + "defaultMessage": "Are you sure you want to unfollow {name}?", + "id": "confirmations.unfollow.message" + } + ], + "path": "app/javascript/mastodon/containers/account_container.json" + }, { "descriptors": [ { @@ -268,6 +281,10 @@ }, { "descriptors": [ + { + "defaultMessage": "Unfollow", + "id": "confirmations.unfollow.confirm" + }, { "defaultMessage": "Block", "id": "confirmations.block.confirm" @@ -280,6 +297,10 @@ "defaultMessage": "Hide entire domain", "id": "confirmations.domain_block.confirm" }, + { + "defaultMessage": "Are you sure you want to unfollow {name}?", + "id": "confirmations.unfollow.message" + }, { "defaultMessage": "Are you sure you want to block {name}?", "id": "confirmations.block.message" diff --git a/app/javascript/mastodon/locales/en.json b/app/javascript/mastodon/locales/en.json index 15afe2309..fe2bd4cb4 100644 --- a/app/javascript/mastodon/locales/en.json +++ b/app/javascript/mastodon/locales/en.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable.", "confirmations.mute.confirm": "Mute", "confirmations.mute.message": "Are you sure you want to mute {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Activity", "emoji_button.flags": "Flags", "emoji_button.food": "Food & Drink", diff --git a/app/javascript/mastodon/locales/eo.json b/app/javascript/mastodon/locales/eo.json index 4f9e26c25..029cef883 100644 --- a/app/javascript/mastodon/locales/eo.json +++ b/app/javascript/mastodon/locales/eo.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable.", "confirmations.mute.confirm": "Mute", "confirmations.mute.message": "Are you sure you want to mute {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Activity", "emoji_button.flags": "Flags", "emoji_button.food": "Food & Drink", diff --git a/app/javascript/mastodon/locales/es.json b/app/javascript/mastodon/locales/es.json index 64ba78716..36ad66ace 100644 --- a/app/javascript/mastodon/locales/es.json +++ b/app/javascript/mastodon/locales/es.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable.", "confirmations.mute.confirm": "Mute", "confirmations.mute.message": "Are you sure you want to mute {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Activity", "emoji_button.flags": "Flags", "emoji_button.food": "Food & Drink", diff --git a/app/javascript/mastodon/locales/fa.json b/app/javascript/mastodon/locales/fa.json index 306937cc2..113daef77 100644 --- a/app/javascript/mastodon/locales/fa.json +++ b/app/javascript/mastodon/locales/fa.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "آیا جدی جدی می‌خواهید کل دامین {domain} را مسدود کنید؟ بیشتر وقت‌ها مسدودکردن یا بی‌صداکردن چند حساب کاربری خاص کافی است و توصیه می‌شود.", "confirmations.mute.confirm": "بی‌صدا کن", "confirmations.mute.message": "آیا واقعاً می‌خواهید {name} را بی‌صدا کنید؟", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "فعالیت", "emoji_button.flags": "پرچم‌ها", "emoji_button.food": "غذا و نوشیدنی", diff --git a/app/javascript/mastodon/locales/fi.json b/app/javascript/mastodon/locales/fi.json index 1b17fb155..da9e5d0f2 100644 --- a/app/javascript/mastodon/locales/fi.json +++ b/app/javascript/mastodon/locales/fi.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable.", "confirmations.mute.confirm": "Mute", "confirmations.mute.message": "Are you sure you want to mute {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Activity", "emoji_button.flags": "Flags", "emoji_button.food": "Food & Drink", diff --git a/app/javascript/mastodon/locales/fr.json b/app/javascript/mastodon/locales/fr.json index b6605295b..c3e743259 100644 --- a/app/javascript/mastodon/locales/fr.json +++ b/app/javascript/mastodon/locales/fr.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Êtes-vous vraiment, vraiment sûr⋅e de vouloir bloquer {domain} en entier ? Dans la plupart des cas, quelques blocages ou masquages ciblés sont suffisants et préférables.", "confirmations.mute.confirm": "Masquer", "confirmations.mute.message": "Confirmez vous le masquage de {name} ?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Activités", "emoji_button.flags": "Drapeaux", "emoji_button.food": "Boire et manger", diff --git a/app/javascript/mastodon/locales/he.json b/app/javascript/mastodon/locales/he.json index 8b63bd26b..c8dc4fe8d 100644 --- a/app/javascript/mastodon/locales/he.json +++ b/app/javascript/mastodon/locales/he.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "באמת באמת לחסום את כל קהילת {domain}? ברב המקרים השתקות נבחרות של מספר משתמשים מסויימים צריכה להספיק.", "confirmations.mute.confirm": "להשתיק", "confirmations.mute.message": "להשתיק את {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "פעילות", "emoji_button.flags": "דגלים", "emoji_button.food": "אוכל ושתיה", diff --git a/app/javascript/mastodon/locales/hr.json b/app/javascript/mastodon/locales/hr.json index 165e3088f..fd669b2b2 100644 --- a/app/javascript/mastodon/locales/hr.json +++ b/app/javascript/mastodon/locales/hr.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Jesi li zaista, zaista siguran da želiš blokirati sve sa {domain}? U većini slučajeva nekoliko ciljanih blokiranja ili utišavanja je dostatno i poželjnije.", "confirmations.mute.confirm": "Utišaj", "confirmations.mute.message": "Jesi li siguran da želiš utišati {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Aktivnost", "emoji_button.flags": "Zastave", "emoji_button.food": "Hrana & Piće", diff --git a/app/javascript/mastodon/locales/hu.json b/app/javascript/mastodon/locales/hu.json index 71dcce505..b3672cb7a 100644 --- a/app/javascript/mastodon/locales/hu.json +++ b/app/javascript/mastodon/locales/hu.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable.", "confirmations.mute.confirm": "Mute", "confirmations.mute.message": "Are you sure you want to mute {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Activity", "emoji_button.flags": "Flags", "emoji_button.food": "Food & Drink", diff --git a/app/javascript/mastodon/locales/id.json b/app/javascript/mastodon/locales/id.json index 0c21877d8..8a17262fe 100644 --- a/app/javascript/mastodon/locales/id.json +++ b/app/javascript/mastodon/locales/id.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable.", "confirmations.mute.confirm": "Bisukan", "confirmations.mute.message": "Apa anda yakin ingin membisukan {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Aktivitas", "emoji_button.flags": "Bendera", "emoji_button.food": "Makanan & Minuman", diff --git a/app/javascript/mastodon/locales/io.json b/app/javascript/mastodon/locales/io.json index 788d09f34..154ca66ce 100644 --- a/app/javascript/mastodon/locales/io.json +++ b/app/javascript/mastodon/locales/io.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable.", "confirmations.mute.confirm": "Mute", "confirmations.mute.message": "Are you sure you want to mute {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Activity", "emoji_button.flags": "Flags", "emoji_button.food": "Food & Drink", diff --git a/app/javascript/mastodon/locales/it.json b/app/javascript/mastodon/locales/it.json index 9176bfaaf..6cb274bae 100644 --- a/app/javascript/mastodon/locales/it.json +++ b/app/javascript/mastodon/locales/it.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable.", "confirmations.mute.confirm": "Mute", "confirmations.mute.message": "Are you sure you want to mute {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Activity", "emoji_button.flags": "Flags", "emoji_button.food": "Food & Drink", diff --git a/app/javascript/mastodon/locales/ja.json b/app/javascript/mastodon/locales/ja.json index a686cdc03..c62e36482 100644 --- a/app/javascript/mastodon/locales/ja.json +++ b/app/javascript/mastodon/locales/ja.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "本当に{domain}全体を非表示にしますか? 多くの場合は個別にブロックやミュートするだけで充分であり、また好ましいです。", "confirmations.mute.confirm": "ミュート", "confirmations.mute.message": "本当に{name}をミュートしますか?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "活動", "emoji_button.flags": "国旗", "emoji_button.food": "食べ物", diff --git a/app/javascript/mastodon/locales/ko.json b/app/javascript/mastodon/locales/ko.json index 0b47cc990..fbd0098d7 100644 --- a/app/javascript/mastodon/locales/ko.json +++ b/app/javascript/mastodon/locales/ko.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "정말로 {domain} 전체를 숨기시겠습니까? 대부분의 경우 개별 차단이나 뮤트로 충분합니다.", "confirmations.mute.confirm": "뮤트", "confirmations.mute.message": "정말로 {name}를 뮤트하시겠습니까?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "활동", "emoji_button.flags": "국기", "emoji_button.food": "음식", diff --git a/app/javascript/mastodon/locales/nl.json b/app/javascript/mastodon/locales/nl.json index cf6a8bd31..f7b0bbf68 100644 --- a/app/javascript/mastodon/locales/nl.json +++ b/app/javascript/mastodon/locales/nl.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Weet je het echt, echt zeker dat je alles van {domain} wil negeren? In de meeste gevallen is het blokkeren of negeren van een paar specifieke personen voldoende en gewenst.", "confirmations.mute.confirm": "Negeren", "confirmations.mute.message": "Weet je zeker dat je {name} wilt negeren?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Activiteiten", "emoji_button.flags": "Vlaggen", "emoji_button.food": "Eten en drinken", diff --git a/app/javascript/mastodon/locales/no.json b/app/javascript/mastodon/locales/no.json index 1f4082d7b..98f59f774 100644 --- a/app/javascript/mastodon/locales/no.json +++ b/app/javascript/mastodon/locales/no.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Er du sikker på at du vil skjule hele domenet {domain}? I de fleste tilfeller er det bedre med målrettet blokkering eller demping.", "confirmations.mute.confirm": "Demp", "confirmations.mute.message": "Er du sikker på at du vil dempe {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Aktivitet", "emoji_button.flags": "Flagg", "emoji_button.food": "Mat og drikke", diff --git a/app/javascript/mastodon/locales/oc.json b/app/javascript/mastodon/locales/oc.json index dc6dd5e32..ca094c18a 100644 --- a/app/javascript/mastodon/locales/oc.json +++ b/app/javascript/mastodon/locales/oc.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Sètz segur segur de voler blocar complètament {domain} ? De còps cal pas que blocar o rescondre unas personas solament.", "confirmations.mute.confirm": "Metre en silenci", "confirmations.mute.message": "Sètz segur de voler metre en silenci {name} ?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Activitat", "emoji_button.flags": "Drapèus", "emoji_button.food": "Beure e manjar", diff --git a/app/javascript/mastodon/locales/pl.json b/app/javascript/mastodon/locales/pl.json index 233d61995..683f589b1 100644 --- a/app/javascript/mastodon/locales/pl.json +++ b/app/javascript/mastodon/locales/pl.json @@ -55,6 +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}?", "emoji_button.activity": "Aktywność", "emoji_button.flags": "Flagi", "emoji_button.food": "Żywność i napoje", diff --git a/app/javascript/mastodon/locales/pt-BR.json b/app/javascript/mastodon/locales/pt-BR.json index cf2b911f2..3944e33e9 100644 --- a/app/javascript/mastodon/locales/pt-BR.json +++ b/app/javascript/mastodon/locales/pt-BR.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable.", "confirmations.mute.confirm": "Mute", "confirmations.mute.message": "Are you sure you want to mute {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Activity", "emoji_button.flags": "Flags", "emoji_button.food": "Food & Drink", diff --git a/app/javascript/mastodon/locales/pt.json b/app/javascript/mastodon/locales/pt.json index cf2b911f2..3944e33e9 100644 --- a/app/javascript/mastodon/locales/pt.json +++ b/app/javascript/mastodon/locales/pt.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable.", "confirmations.mute.confirm": "Mute", "confirmations.mute.message": "Are you sure you want to mute {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Activity", "emoji_button.flags": "Flags", "emoji_button.food": "Food & Drink", diff --git a/app/javascript/mastodon/locales/ru.json b/app/javascript/mastodon/locales/ru.json index 942a13ede..cffc285f4 100644 --- a/app/javascript/mastodon/locales/ru.json +++ b/app/javascript/mastodon/locales/ru.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Вы на самом деле уверены, что хотите блокировать весь {domain}? В большинстве случаев нескольких отдельных блокировок или глушений достаточно.", "confirmations.mute.confirm": "Заглушить", "confirmations.mute.message": "Вы уверены, что хотите заглушить {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Занятия", "emoji_button.flags": "Флаги", "emoji_button.food": "Еда и напитки", diff --git a/app/javascript/mastodon/locales/th.json b/app/javascript/mastodon/locales/th.json index e9e96c14f..63bed6d8c 100644 --- a/app/javascript/mastodon/locales/th.json +++ b/app/javascript/mastodon/locales/th.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable.", "confirmations.mute.confirm": "Mute", "confirmations.mute.message": "Are you sure you want to mute {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Activity", "emoji_button.flags": "Flags", "emoji_button.food": "Food & Drink", diff --git a/app/javascript/mastodon/locales/tr.json b/app/javascript/mastodon/locales/tr.json index adfa79cd9..5bd308e95 100644 --- a/app/javascript/mastodon/locales/tr.json +++ b/app/javascript/mastodon/locales/tr.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable.", "confirmations.mute.confirm": "Sessize al", "confirmations.mute.message": "{name} kullanıcısını sessize almak istiyor musunuz?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Aktivite", "emoji_button.flags": "Bayraklar", "emoji_button.food": "Yiyecek ve İçecek", diff --git a/app/javascript/mastodon/locales/uk.json b/app/javascript/mastodon/locales/uk.json index 435067281..e1611505d 100644 --- a/app/javascript/mastodon/locales/uk.json +++ b/app/javascript/mastodon/locales/uk.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Ви точно, точно впевнені, що хочете заблокувати весь домен {domain}? У більшості випадків для нормальної роботи краще заблокувати/заглушити лише деяких користувачів.", "confirmations.mute.confirm": "Заглушити", "confirmations.mute.message": "Ви впевнені, що хочете заглушити {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "Заняття", "emoji_button.flags": "Прапори", "emoji_button.food": "Їжа та напої", diff --git a/app/javascript/mastodon/locales/zh-CN.json b/app/javascript/mastodon/locales/zh-CN.json index 0f2c1fcec..18bf872e5 100644 --- a/app/javascript/mastodon/locales/zh-CN.json +++ b/app/javascript/mastodon/locales/zh-CN.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable.", "confirmations.mute.confirm": "静音", "confirmations.mute.message": "想好了,真的要静音 {name}?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "活动", "emoji_button.flags": "旗帜", "emoji_button.food": "食物和饮料", diff --git a/app/javascript/mastodon/locales/zh-HK.json b/app/javascript/mastodon/locales/zh-HK.json index c0b4cfce9..a461085c7 100644 --- a/app/javascript/mastodon/locales/zh-HK.json +++ b/app/javascript/mastodon/locales/zh-HK.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable.", "confirmations.mute.confirm": "靜音", "confirmations.mute.message": "你確定要將{name}靜音嗎?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "活動", "emoji_button.flags": "旗幟", "emoji_button.food": "飲飲食食", diff --git a/app/javascript/mastodon/locales/zh-TW.json b/app/javascript/mastodon/locales/zh-TW.json index 772cc691c..d766fb394 100644 --- a/app/javascript/mastodon/locales/zh-TW.json +++ b/app/javascript/mastodon/locales/zh-TW.json @@ -55,6 +55,8 @@ "confirmations.domain_block.message": "你真的真的確定要封鎖整個 {domain} ?多數情況下,比較推薦封鎖或消音幾個特定目標就好。", "confirmations.mute.confirm": "消音", "confirmations.mute.message": "你確定要消音 {name} ?", + "confirmations.unfollow.confirm": "Unfollow", + "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", "emoji_button.activity": "活動", "emoji_button.flags": "旗幟", "emoji_button.food": "食物與飲料", diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb index c5da18029..62046ed72 100644 --- a/app/lib/user_settings_decorator.rb +++ b/app/lib/user_settings_decorator.rb @@ -19,6 +19,7 @@ class UserSettingsDecorator user.settings['interactions'] = merged_interactions user.settings['default_privacy'] = default_privacy_preference user.settings['default_sensitive'] = default_sensitive_preference + user.settings['unfollow_modal'] = unfollow_modal_preference user.settings['boost_modal'] = boost_modal_preference user.settings['delete_modal'] = delete_modal_preference user.settings['auto_play_gif'] = auto_play_gif_preference @@ -42,6 +43,10 @@ class UserSettingsDecorator boolean_cast_setting 'setting_default_sensitive' end + def unfollow_modal_preference + boolean_cast_setting 'setting_unfollow_modal' + end + def boost_modal_preference boolean_cast_setting 'setting_boost_modal' end diff --git a/app/models/user.rb b/app/models/user.rb index becf0018f..25dc25864 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -83,6 +83,10 @@ class User < ApplicationRecord settings.default_sensitive end + def setting_unfollow_modal + settings.unfollow_modal + end + def setting_boost_modal settings.boost_modal end diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb index 704d29a57..0191948b1 100644 --- a/app/serializers/initial_state_serializer.rb +++ b/app/serializers/initial_state_serializer.rb @@ -15,6 +15,7 @@ class InitialStateSerializer < ActiveModel::Serializer if object.current_account store[:me] = object.current_account.id + store[:unfollow_modal] = object.current_account.user.setting_unfollow_modal store[:boost_modal] = object.current_account.user.setting_boost_modal store[:delete_modal] = object.current_account.user.setting_delete_modal store[:auto_play_gif] = object.current_account.user.setting_auto_play_gif diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml index 3b5d90942..fae6090c8 100644 --- a/app/views/settings/preferences/show.html.haml +++ b/app/views/settings/preferences/show.html.haml @@ -44,6 +44,7 @@ = f.input :setting_noindex, as: :boolean, wrapper: :with_label .fields-group + = f.input :setting_unfollow_modal, as: :boolean, wrapper: :with_label = f.input :setting_boost_modal, as: :boolean, wrapper: :with_label = f.input :setting_delete_modal, as: :boolean, wrapper: :with_label diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 476ccc773..536bb06e1 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -42,6 +42,7 @@ en: setting_default_sensitive: Always mark media as sensitive setting_delete_modal: Show confirmation dialog before deleting a toot setting_system_font_ui: Use system's default font + setting_unfollow_modal: Show confirmation dialog before unfollowing someone setting_noindex: Opt-out of search engine indexing severity: Severity type: Import type diff --git a/spec/lib/user_settings_decorator_spec.rb b/spec/lib/user_settings_decorator_spec.rb index a67487779..6fbf6536b 100644 --- a/spec/lib/user_settings_decorator_spec.rb +++ b/spec/lib/user_settings_decorator_spec.rb @@ -35,6 +35,13 @@ describe UserSettingsDecorator do expect(user.settings['default_sensitive']).to eq true end + it 'updates the user settings value for unfollow modal' do + values = { 'setting_unfollow_modal' => '0' } + + settings.update(values) + expect(user.settings['unfollow_modal']).to eq false + end + it 'updates the user settings value for boost modal' do values = { 'setting_boost_modal' => '1' } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 2019ec0f6..ef45818b9 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -219,6 +219,14 @@ RSpec.describe User, type: :model do end end + describe '#setting_unfollow_modal' do + it 'returns unfollow modal setting' do + user = Fabricate(:user) + user.settings[:unfollow_modal] = true + expect(user.setting_unfollow_modal).to eq true + end + end + describe '#setting_delete_modal' do it 'returns delete modal setting' do user = Fabricate(:user) From bb4c3831b2466438d04f5b7064ac688c2a30cb98 Mon Sep 17 00:00:00 2001 From: unarist Date: Wed, 19 Jul 2017 00:23:35 +0900 Subject: [PATCH 13/16] Add Japanese translation for #4199 (#4247) --- config/locales/simple_form.ja.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/locales/simple_form.ja.yml b/config/locales/simple_form.ja.yml index 74cf91de4..58975e426 100644 --- a/config/locales/simple_form.ja.yml +++ b/config/locales/simple_form.ja.yml @@ -8,6 +8,8 @@ ja: header: 2MBまでのPNGやGIF、JPGが利用可能です。 700x335pxまで縮小されます。 locked: フォロワーを手動で承認する必要があります。 note: あと%{count}文字入力できます。 + setting_noindex: 公開プロフィールおよび各投稿ページに影響します + imports: data: 他の Mastodon インスタンスからエクスポートしたCSVファイルを選択して下さい sessions: @@ -37,6 +39,7 @@ ja: setting_default_sensitive: メディアを常に閲覧注意としてマークする setting_delete_modal: トゥートを削除する前に確認ダイアログを表示する setting_system_font_ui: システムのデフォルトフォントを使う + setting_noindex: 検索エンジンによるインデックスを拒否する severity: 重大性 type: インポートする項目 username: ユーザー名 From 02f896c12efce87e33af15d0c88b77ad050a7fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Tue, 18 Jul 2017 18:42:45 +0200 Subject: [PATCH 14/16] Fix broken CSS reload due to webpack upgrade (#4250) --- package.json | 4 ++-- yarn.lock | 51 +++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index aede6df2e..c90e49db5 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "es6-symbol": "^3.1.1", "escape-html": "^1.0.3", "express": "^4.15.2", - "extract-text-webpack-plugin": "^3.0.0", + "extract-text-webpack-plugin": "^2.1.2", "file-loader": "^0.11.2", "font-awesome": "^4.7.0", "glob": "^7.1.1", @@ -112,7 +112,7 @@ "tiny-queue": "^0.2.1", "uuid": "^3.1.0", "uws": "^8.14.0", - "webpack": "^3.2.0", + "webpack": "^3.0.0", "webpack-bundle-analyzer": "^2.8.2", "webpack-manifest-plugin": "^1.1.2", "webpack-merge": "^4.1.0", diff --git a/yarn.lock b/yarn.lock index defd8599f..dcf09643e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -415,7 +415,7 @@ async@^1.5.2: version "1.5.2" resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a" -async@^2.1.2, async@^2.1.4, async@^2.1.5, async@^2.4.1: +async@^2.1.2, async@^2.1.4, async@^2.1.5: version "2.5.0" resolved "https://registry.yarnpkg.com/async/-/async-2.5.0.tgz#843190fd6b7357a0b9e1c956edddd5ec8462b54d" dependencies: @@ -1657,7 +1657,7 @@ cheerio@^0.22.0: lodash.reject "^4.4.0" lodash.some "^4.4.0" -chokidar@^1.4.3, chokidar@^1.6.0: +chokidar@^1.4.3, chokidar@^1.6.0, chokidar@^1.7.0: version "1.7.0" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468" dependencies: @@ -2868,12 +2868,12 @@ extglob@^0.3.1: dependencies: is-extglob "^1.0.0" -extract-text-webpack-plugin@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/extract-text-webpack-plugin/-/extract-text-webpack-plugin-3.0.0.tgz#90caa7907bc449f335005e3ac7532b41b00de612" +extract-text-webpack-plugin@^2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/extract-text-webpack-plugin/-/extract-text-webpack-plugin-2.1.2.tgz#756ef4efa8155c3681833fbc34da53b941746d6c" dependencies: - async "^2.4.1" - loader-utils "^1.1.0" + async "^2.1.2" + loader-utils "^1.0.2" schema-utils "^0.3.0" webpack-sources "^1.0.1" @@ -7328,6 +7328,14 @@ watchpack@^1.3.1: chokidar "^1.4.3" graceful-fs "^4.1.2" +watchpack@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.4.0.tgz#4a1472bcbb952bd0a9bb4036801f954dfb39faac" + dependencies: + async "^2.1.2" + chokidar "^1.7.0" + graceful-fs "^4.1.2" + wbuf@^1.1.0, wbuf@^1.7.2: version "1.7.2" resolved "https://registry.yarnpkg.com/wbuf/-/wbuf-1.7.2.tgz#d697b99f1f59512df2751be42769c1580b5801fe" @@ -7425,7 +7433,7 @@ webpack-sources@^1.0.1: source-list-map "^2.0.0" source-map "~0.5.3" -"webpack@^2.5.1 || ^3.0.0", webpack@^3.2.0: +"webpack@^2.5.1 || ^3.0.0": version "3.2.0" resolved "https://registry.yarnpkg.com/webpack/-/webpack-3.2.0.tgz#8b0cae0e1a9fd76bfbf0eab61a8c2ada848c312f" dependencies: @@ -7452,6 +7460,33 @@ webpack-sources@^1.0.1: webpack-sources "^1.0.1" yargs "^6.0.0" +webpack@^3.0.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-3.3.0.tgz#ce2f9e076566aba91f74887133a883fd7da187bc" + dependencies: + acorn "^5.0.0" + acorn-dynamic-import "^2.0.0" + ajv "^5.1.5" + ajv-keywords "^2.0.0" + async "^2.1.2" + enhanced-resolve "^3.3.0" + escope "^3.6.0" + interpret "^1.0.0" + json-loader "^0.5.4" + json5 "^0.5.1" + loader-runner "^2.3.0" + loader-utils "^1.1.0" + memory-fs "~0.4.1" + mkdirp "~0.5.0" + node-libs-browser "^2.0.0" + source-map "^0.5.3" + supports-color "^3.1.0" + tapable "~0.2.5" + uglifyjs-webpack-plugin "^0.4.6" + watchpack "^1.4.0" + webpack-sources "^1.0.1" + yargs "^6.0.0" + websocket-driver@>=0.5.1: version "0.6.5" resolved "https://registry.yarnpkg.com/websocket-driver/-/websocket-driver-0.6.5.tgz#5cb2556ceb85f4373c6d8238aa691c8454e13a36" From 0ccd47f413fe249c2c848596789b83bdd228a58b Mon Sep 17 00:00:00 2001 From: lindwurm Date: Wed, 19 Jul 2017 01:42:59 +0900 Subject: [PATCH 15/16] Update Japanese translations for new landing page (#4159) Signed-off-by: lindwurm --- app/javascript/mastodon/locales/ja.json | 2 +- config/locales/ja.yml | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/javascript/mastodon/locales/ja.json b/app/javascript/mastodon/locales/ja.json index c62e36482..f58395d10 100644 --- a/app/javascript/mastodon/locales/ja.json +++ b/app/javascript/mastodon/locales/ja.json @@ -151,7 +151,7 @@ "report.target": "問題のユーザー", "search.placeholder": "検索", "search_results.total": "{count, number}件の結果", - "standalone.public_title": "A look inside...", + "standalone.public_title": "連合タイムライン", "status.cannot_reblog": "この投稿はブーストできません", "status.delete": "削除", "status.favourite": "お気に入り", diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 2897e864f..fc5a98d09 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -1,15 +1,28 @@ --- ja: about: - about_mastodon: Mastodon は自由でオープンソースなソーシャルネットワークです。商用プラットフォームの代替となる分散型を採用し、あなたのやりとりが一つの会社によって独占されるのを防ぎます。信頼できるインスタンスを選択してください — どのインスタンスを選んでも、誰とでもやりとりすることができます。 だれでも自分の Mastodon インスタンスを作ることができ、シームレスにソーシャルネットワークに参加できます。 + about_mastodon_html: Mastodon は、オープンなウェブプロトコルを採用した、自由でオープンソースなソーシャルネットワークです。電子メールのような分散型の仕組みを採っています。 about_this: このインスタンスについて business_email: 'ビジネスメールアドレス:' - closed_registrations: 現在このインスタンスでの新規登録は受け付けていません。 + closed_registrations: 現在このインスタンスでの新規登録は受け付けていません。しかし、他のインスタンスにアカウントを作成しても全く同じネットワークに参加することができます。 contact: 連絡先 description_headline: "%{domain} とは?" domain_count_after: 個のインスタンス domain_count_before: 接続中 + features: + humane_approach_body: 他の SNS の失敗から学び、Mastodon はソーシャルメディアが誤った使い方をされることの無いように倫理的な設計を目指しています。 + humane_approach_title: より思いやりのある設計 + not_a_product_body: Mastodon は営利的な SNS ではありません。広告や、データの収集・解析は無く、またユーザーの囲い込みもありません。 + not_a_product_title: あなたは人間であり、商品ではありません + real_conversation_body: 好きなように書ける500文字までの投稿や、文章やメディアの内容に警告をつけられる機能で、思い通りに自分自身を表現することができます。 + real_conversation_title: 本当のコミュニケーションのために + within_reach_body: デベロッパーフレンドリーな API により実現された、iOS や Android、その他様々なプラットフォームのためのアプリでどこでも友人とやりとりできます。 + within_reach_title: いつでも身近に + find_another_instance: 他のインスタンスを探す + generic_description: "%{domain} は、Mastodon インスタンスの一つです。" get_started: 参加する + hosted_on: Mastodon hosted on %{domain} + learn_more: もっと詳しく links: リンク other_instances: 他のインスタンス source_code: ソースコード @@ -19,6 +32,7 @@ ja: user_count_after: 人 user_count_before: ユーザー数 version: バージョン + what_is_mastodon: Mastodon とは? accounts: follow: フォロー followers: フォロワー @@ -205,9 +219,10 @@ ja: applications: invalid_url: URLが無効です auth: + agreement_html: 登録すると 利用規約プライバシーポリシー に同意したことになります。 change_password: セキュリティ delete_account: アカウントの削除 - delete_account_html: アカウントを削除したい場合、こちらから手続きが行えます。削除前には確認画面があります。 + delete_account_html: アカウントを削除したい場合、こちら から手続きが行えます。削除する前に、確認画面があります。 didnt_get_confirmation: 確認メールを受信できませんか? forgot_password: パスワードをお忘れですか? login: ログイン From 0b4006fc47dcd3d57ffdd0b95c95ad4c40a4918f Mon Sep 17 00:00:00 2001 From: lindwurm Date: Wed, 19 Jul 2017 01:43:19 +0900 Subject: [PATCH 16/16] Add Japanese translation for #4246 (#4249) Signed-off-by: lindwurm --- app/javascript/mastodon/locales/ja.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/javascript/mastodon/locales/ja.json b/app/javascript/mastodon/locales/ja.json index f58395d10..b3943f646 100644 --- a/app/javascript/mastodon/locales/ja.json +++ b/app/javascript/mastodon/locales/ja.json @@ -55,8 +55,8 @@ "confirmations.domain_block.message": "本当に{domain}全体を非表示にしますか? 多くの場合は個別にブロックやミュートするだけで充分であり、また好ましいです。", "confirmations.mute.confirm": "ミュート", "confirmations.mute.message": "本当に{name}をミュートしますか?", - "confirmations.unfollow.confirm": "Unfollow", - "confirmations.unfollow.message": "Are you sure you want to unfollow {name}?", + "confirmations.unfollow.confirm": "フォロー解除", + "confirmations.unfollow.message": "本当に{name}のフォローを解除しますか?", "emoji_button.activity": "活動", "emoji_button.flags": "国旗", "emoji_button.food": "食べ物",