diff --git a/Gemfile b/Gemfile index 486e72cc4ad..637bf53eebe 100644 --- a/Gemfile +++ b/Gemfile @@ -24,6 +24,7 @@ gem 'addressable', '~> 2.5' gem 'bootsnap' gem 'browser' gem 'charlock_holmes', '~> 0.7.5' +gem 'iso-639' gem 'cld3', '~> 3.1' gem 'devise', '~> 4.2' gem 'devise-two-factor', '~> 3.0' diff --git a/Gemfile.lock b/Gemfile.lock index ef99e0d7b3c..ddb97dd940a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -225,6 +225,7 @@ GEM terminal-table (>= 1.5.1) idn-ruby (0.1.0) ipaddress (0.8.3) + iso-639 (0.2.8) jmespath (1.3.1) json (2.1.0) json-ld (2.1.5) @@ -560,6 +561,7 @@ DEPENDENCIES httplog (~> 0.99) i18n-tasks (~> 0.9) idn-ruby + iso-639 json-ld-preloaded (~> 2.2.1) kaminari (~> 1.0) letter_opener (~> 1.4) diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index af950aa634f..369a4568099 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -30,6 +30,7 @@ module SettingsHelper th: 'ภาษาไทย', tr: 'Türkçe', uk: 'Українська', + zh: '中文', 'zh-CN': '简体中文', 'zh-HK': '繁體中文(香港)', 'zh-TW': '繁體中文(臺灣)', @@ -39,6 +40,10 @@ module SettingsHelper HUMAN_LOCALES[locale] end + def filterable_languages + I18n.available_locales.map { |locale| locale.to_s.split('-').first.to_sym }.uniq + end + def hash_to_object(hash) HashObject.new(hash) end diff --git a/app/javascript/mastodon/actions/compose.js b/app/javascript/mastodon/actions/compose.js index 5a486f9bbd2..5f265a75011 100644 --- a/app/javascript/mastodon/actions/compose.js +++ b/app/javascript/mastodon/actions/compose.js @@ -1,6 +1,11 @@ import api from '../api'; -import { updateTimeline } from './timelines'; +import { + updateTimeline, + refreshHomeTimeline, + refreshCommunityTimeline, + refreshPublicTimeline, +} from './timelines'; export const COMPOSE_CHANGE = 'COMPOSE_CHANGE'; export const COMPOSE_SUBMIT_REQUEST = 'COMPOSE_SUBMIT_REQUEST'; @@ -98,16 +103,20 @@ export function submitCompose() { dispatch(submitComposeSuccess({ ...response.data })); // To make the app more responsive, immediately get the status into the columns - dispatch(updateTimeline('home', { ...response.data })); + + const insertOrRefresh = (timelineId, refreshAction) => { + if (getState().getIn(['timelines', timelineId, 'online'])) { + dispatch(updateTimeline(timelineId, { ...response.data })); + } else if (getState().getIn(['timelines', timelineId, 'loaded'])) { + dispatch(refreshAction()); + } + }; + + insertOrRefresh('home', refreshHomeTimeline); if (response.data.in_reply_to_id === null && response.data.visibility === 'public') { - if (getState().getIn(['timelines', 'community', 'loaded'])) { - dispatch(updateTimeline('community', { ...response.data })); - } - - if (getState().getIn(['timelines', 'public', 'loaded'])) { - dispatch(updateTimeline('public', { ...response.data })); - } + insertOrRefresh('community', refreshCommunityTimeline); + insertOrRefresh('public', refreshPublicTimeline); } }).catch(function (error) { dispatch(submitComposeFail(error)); diff --git a/app/javascript/mastodon/actions/pin_statuses.js b/app/javascript/mastodon/actions/pin_statuses.js new file mode 100644 index 00000000000..01bf8930b28 --- /dev/null +++ b/app/javascript/mastodon/actions/pin_statuses.js @@ -0,0 +1,39 @@ +import api from '../api'; + +export const PINNED_STATUSES_FETCH_REQUEST = 'PINNED_STATUSES_FETCH_REQUEST'; +export const PINNED_STATUSES_FETCH_SUCCESS = 'PINNED_STATUSES_FETCH_SUCCESS'; +export const PINNED_STATUSES_FETCH_FAIL = 'PINNED_STATUSES_FETCH_FAIL'; + +export function fetchPinnedStatuses() { + return (dispatch, getState) => { + dispatch(fetchPinnedStatusesRequest()); + + const accountId = getState().getIn(['meta', 'me']); + api(getState).get(`/api/v1/accounts/${accountId}/statuses`, { params: { pinned: true } }).then(response => { + dispatch(fetchPinnedStatusesSuccess(response.data, null)); + }).catch(error => { + dispatch(fetchPinnedStatusesFail(error)); + }); + }; +}; + +export function fetchPinnedStatusesRequest() { + return { + type: PINNED_STATUSES_FETCH_REQUEST, + }; +}; + +export function fetchPinnedStatusesSuccess(statuses, next) { + return { + type: PINNED_STATUSES_FETCH_SUCCESS, + statuses, + next, + }; +}; + +export function fetchPinnedStatusesFail(error) { + return { + type: PINNED_STATUSES_FETCH_FAIL, + error, + }; +}; diff --git a/app/javascript/mastodon/components/scrollable_list.js b/app/javascript/mastodon/components/scrollable_list.js index e47b1e9aa5e..723dd322b06 100644 --- a/app/javascript/mastodon/components/scrollable_list.js +++ b/app/javascript/mastodon/components/scrollable_list.js @@ -27,6 +27,10 @@ export default class ScrollableList extends PureComponent { trackScroll: true, }; + state = { + lastMouseMove: null, + }; + intersectionObserverWrapper = new IntersectionObserverWrapper(); handleScroll = throttle(() => { @@ -47,6 +51,14 @@ export default class ScrollableList extends PureComponent { trailing: true, }); + handleMouseMove = throttle(() => { + this._lastMouseMove = new Date(); + }, 300); + + handleMouseLeave = () => { + this._lastMouseMove = null; + } + componentDidMount () { this.attachScrollListener(); this.attachIntersectionObserver(); @@ -56,17 +68,20 @@ export default class ScrollableList extends PureComponent { } componentDidUpdate (prevProps) { + const someItemInserted = React.Children.count(prevProps.children) > 0 && + React.Children.count(prevProps.children) < React.Children.count(this.props.children) && + this.getFirstChildKey(prevProps) !== this.getFirstChildKey(this.props); + // Reset the scroll position when a new child comes in in order not to // jerk the scrollbar around if you're already scrolled down the page. - if (React.Children.count(prevProps.children) < React.Children.count(this.props.children) && this._oldScrollPosition && this.node.scrollTop > 0) { - if (this.getFirstChildKey(prevProps) !== this.getFirstChildKey(this.props)) { - const newScrollTop = this.node.scrollHeight - this._oldScrollPosition; - if (this.node.scrollTop !== newScrollTop) { - this.node.scrollTop = newScrollTop; - } - } else { - this._oldScrollPosition = this.node.scrollHeight - this.node.scrollTop; + if (someItemInserted && this._oldScrollPosition && this.node.scrollTop > 0) { + const newScrollTop = this.node.scrollHeight - this._oldScrollPosition; + + if (this.node.scrollTop !== newScrollTop) { + this.node.scrollTop = newScrollTop; } + } else { + this._oldScrollPosition = this.node.scrollHeight - this.node.scrollTop; } } @@ -114,6 +129,10 @@ export default class ScrollableList extends PureComponent { this.props.onScrollToBottom(); } + _recentlyMoved () { + return this._lastMouseMove !== null && ((new Date()) - this._lastMouseMove < 600); + } + handleKeyDown = (e) => { if (['PageDown', 'PageUp'].includes(e.key) || (e.ctrlKey && ['End', 'Home'].includes(e.key))) { const article = (() => { @@ -149,7 +168,7 @@ export default class ScrollableList extends PureComponent { if (isLoading || childrenCount > 0 || !emptyMessage) { scrollableArea = ( -
Bonjorn <%= @resource.email %> !
+
Bonjorn <%= @resource.email %> !
Venètz de vos crear un compte sus <%= @instance %> e vos mercegem :)
-Per confirmar vòstre inscripcion, mercés de clicar sul ligam seguent :
+
Per confirmar vòstre inscripcion, mercés de clicar sul ligam seguent :
<%= link_to 'Confirmar mon compte', confirmation_url(@resource, confirmation_token: @token) %>
Aprèp vòstra primièra connexion, poiretz accedir a la documentacion de l’aisina.
diff --git a/app/views/user_mailer/confirmation_instructions.oc.text.erb b/app/views/user_mailer/confirmation_instructions.oc.text.erb index ff1abf62dd7..444d296ce68 100644 --- a/app/views/user_mailer/confirmation_instructions.oc.text.erb +++ b/app/views/user_mailer/confirmation_instructions.oc.text.erb @@ -1,8 +1,8 @@ -Bonjorn <%= @resource.email %> ! +Bonjorn <%= @resource.email %> ! Venètz de vos crear un compte sus <%= @instance %> e vos mercegem :) -er confirmar vòstre inscripcion, mercés de clicar sul ligam seguent : +er confirmar vòstre inscripcion, mercés de clicar sul ligam seguent : <%= link_to 'Confirmar mon compte', confirmation_url(@resource, confirmation_token: @token) %> Aprèp vòstra primièra connexion, poiretz accedir a la documentacion de l’aisina. diff --git a/app/views/user_mailer/password_change.oc.html.erb b/app/views/user_mailer/password_change.oc.html.erb index a6b506f5e07..476db95366f 100644 --- a/app/views/user_mailer/password_change.oc.html.erb +++ b/app/views/user_mailer/password_change.oc.html.erb @@ -1,3 +1,3 @@ -Bonjorn <%= @resource.email %> !
+Bonjorn <%= @resource.email %> !
-Vos contactem per vos avisar que vòstre senhal per Mastodon es ben estat cambiat.
+Vos contactem per vos avisar qu’avèm ben cambiat vòstre senhal Mastodon.
diff --git a/app/views/user_mailer/password_change.oc.text.erb b/app/views/user_mailer/password_change.oc.text.erb index 1caebde69a1..e6caa045cd7 100644 --- a/app/views/user_mailer/password_change.oc.text.erb +++ b/app/views/user_mailer/password_change.oc.text.erb @@ -1,3 +1,3 @@ -Bonjorn <%= @resource.email %> ! +Bonjorn <%= @resource.email %> ! -Vos contactem per vos avisar que vòstre senhal per Mastodon es ben estat cambiat. +Vos contactem per vos avisar qu’avèm ben cambiat vòstre senhal Mastodon. diff --git a/app/views/user_mailer/reset_password_instructions.oc.html.erb b/app/views/user_mailer/reset_password_instructions.oc.html.erb index acf2c0abde1..7363ee4b6a5 100644 --- a/app/views/user_mailer/reset_password_instructions.oc.html.erb +++ b/app/views/user_mailer/reset_password_instructions.oc.html.erb @@ -1,4 +1,4 @@ -Bonjorn <%= @resource.email %> !
+Bonjorn <%= @resource.email %> !
Qualqu’un a demandat una reĩnicializacion de vòstre senhal per Mastodon. Podètz realizar la reĩnicializacion en clicant sul ligam çai-jos.
diff --git a/app/views/user_mailer/reset_password_instructions.oc.text.erb b/app/views/user_mailer/reset_password_instructions.oc.text.erb index 211974cc270..a95a1ae8cd3 100644 --- a/app/views/user_mailer/reset_password_instructions.oc.text.erb +++ b/app/views/user_mailer/reset_password_instructions.oc.text.erb @@ -1,4 +1,4 @@ -Bonjorn <%= @resource.email %> ! +Bonjorn <%= @resource.email %> ! Qualqu’un a demandat una reĩnicializacion de vòstre senhal per Mastodon. Podètz realizar la reĩnicializacion en clicant sul ligam çai-jos. diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 61e13133647..0ee77730e8a 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -9,6 +9,9 @@ end Sidekiq.configure_server do |config| config.redis = redis_params + config.client_middleware do |chain| + chain.add Mastodon::UniqueRetryJobMiddleware + end end Sidekiq.configure_client do |config| diff --git a/config/locales/pl.yml b/config/locales/pl.yml index 842baef451d..88125f69232 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -451,11 +451,11 @@ pl: show_more: Pokaż więcej visibilities: private: Tylko dla śledzących - private_long: Widoczny tylko dla osób, które Cię śledzą - public: Publiczny - public_long: Widoczny dla wszystkich użytkowników - unlisted: Niewypisany - unlisted_long: Widoczny dla wszystkich, ale nie wyświetlany na publicznych osiach czasu + private_long: Widoczne tylko dla osób, które Cię śledzą + public: Publiczne + public_long: Widoczne dla wszystkich użytkowników + unlisted: Niewypisane + unlisted_long: Widoczne dla wszystkich, ale nie wyświetlane na publicznych osiach czasu stream_entries: click_to_show: Naciśnij aby wyświetlić pinned: Przypięty wpis diff --git a/lib/mastodon/version.rb b/lib/mastodon/version.rb index de2516d6c29..3ab705e2608 100644 --- a/lib/mastodon/version.rb +++ b/lib/mastodon/version.rb @@ -21,7 +21,7 @@ module Mastodon end def flags - 'rc2' + 'rc4' end def to_a diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake index 307bc240db6..3c65ece4bea 100644 --- a/lib/tasks/mastodon.rake +++ b/lib/tasks/mastodon.rake @@ -47,7 +47,7 @@ namespace :mastodon do confirm = STDIN.gets.chomp puts - if confirm.casecmp?('y') + if confirm.casecmp('y').zero? password = SecureRandom.hex user = User.new(email: email, password: password, account_attributes: { username: username }) if user.save @@ -289,13 +289,13 @@ namespace :mastodon do puts 'Delete records and associated files from deprecated preview cards? [y/N]: ' confirm = STDIN.gets.chomp - if confirm.casecmp?('y') + if confirm.casecmp('y').zero? DeprecatedPreviewCard.in_batches.destroy_all puts 'Drop deprecated preview cards table? [y/N]: ' confirm = STDIN.gets.chomp - if confirm.casecmp?('y') + if confirm.casecmp('y').zero? ActiveRecord::Migration.drop_table :deprecated_preview_cards end end diff --git a/public/embed.js b/public/embed.js new file mode 100644 index 00000000000..dac50745376 --- /dev/null +++ b/public/embed.js @@ -0,0 +1,43 @@ +(function() { + 'use strict'; + + var ready = function(loaded) { + if (['interactive', 'complete'].indexOf(document.readyState) !== -1) { + loaded(); + } else { + document.addEventListener('DOMContentLoaded', loaded); + } + }; + + ready(function() { + var iframes = []; + + window.addEventListener('message', function(e) { + var data = e.data || {}; + + if (data.type !== 'setHeight' || !iframes[data.id]) { + return; + } + + iframes[data.id].height = data.height; + }); + + [].forEach.call(document.querySelectorAll('iframe.mastodon-embed'), function(iframe) { + iframe.scrolling = 'no'; + iframe.style.overflow = 'hidden'; + + iframes.push(iframe); + + var id = iframes.length - 1; + + iframe.onload = function() { + iframe.contentWindow.postMessage({ + type: 'setHeight', + id: id, + }, '*'); + }; + + iframe.onload(); + }); + }); +})(); diff --git a/spec/helpers/settings_helper_spec.rb b/spec/helpers/settings_helper_spec.rb index 5a51e0ef1f1..092c3758369 100644 --- a/spec/helpers/settings_helper_spec.rb +++ b/spec/helpers/settings_helper_spec.rb @@ -4,10 +4,10 @@ require 'rails_helper' describe SettingsHelper do describe 'the HUMAN_LOCALES constant' do - it 'has the same number of keys as I18n locales exist' do + it 'includes all I18n locales' do options = I18n.available_locales - expect(described_class::HUMAN_LOCALES.keys).to eq(options) + expect(described_class::HUMAN_LOCALES.keys).to include(*options) end end diff --git a/spec/lib/activitypub/activity/update_spec.rb b/spec/lib/activitypub/activity/update_spec.rb index 0bd6d00d9ca..ea308e35cd5 100644 --- a/spec/lib/activitypub/activity/update_spec.rb +++ b/spec/lib/activitypub/activity/update_spec.rb @@ -2,12 +2,16 @@ require 'rails_helper' RSpec.describe ActivityPub::Activity::Update do let!(:sender) { Fabricate(:account) } - + before do + stub_request(:get, actor_json[:outbox]).to_return(status: 404) + stub_request(:get, actor_json[:followers]).to_return(status: 404) + stub_request(:get, actor_json[:following]).to_return(status: 404) + sender.update!(uri: ActivityPub::TagManager.instance.uri_for(sender)) end - let(:modified_sender) do + let(:modified_sender) do sender.dup.tap do |modified_sender| modified_sender.display_name = 'Totally modified now' end diff --git a/spec/lib/activitypub/tag_manager_spec.rb b/spec/lib/activitypub/tag_manager_spec.rb index 8f7662e24a3..dea8abc6559 100644 --- a/spec/lib/activitypub/tag_manager_spec.rb +++ b/spec/lib/activitypub/tag_manager_spec.rb @@ -91,9 +91,35 @@ RSpec.describe ActivityPub::TagManager do end describe '#uri_to_resource' do - it 'returns the local resource' do + it 'returns the local account' do account = Fabricate(:account) expect(subject.uri_to_resource(subject.uri_for(account), Account)).to eq account end + + it 'returns the remote account by matching URI without fragment part' do + account = Fabricate(:account, uri: 'https://example.com/123') + expect(subject.uri_to_resource('https://example.com/123#456', Account)).to eq account + end + + it 'returns the local status for ActivityPub URI' do + status = Fabricate(:status) + expect(subject.uri_to_resource(subject.uri_for(status), Status)).to eq status + end + + it 'returns the local status for OStatus tag: URI' do + status = Fabricate(:status) + expect(subject.uri_to_resource(::TagManager.instance.uri_for(status), Status)).to eq status + end + + it 'returns the local status for OStatus StreamEntry URL' do + status = Fabricate(:status) + stream_entry_url = account_stream_entry_url(status.account, status.stream_entry) + expect(subject.uri_to_resource(stream_entry_url, Status)).to eq status + end + + it 'returns the remote status by matching URI without fragment part' do + status = Fabricate(:status, uri: 'https://example.com/123') + expect(subject.uri_to_resource('https://example.com/123#456', Status)).to eq status + end end end diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index 6c272384570..d40ebf6dc3d 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -21,4 +21,18 @@ describe Report do expect(report.media_attachments).to eq [media_attachment] end end + + describe 'validatiions' do + it 'has a valid fabricator' do + report = Fabricate(:report) + report.valid? + expect(report).to be_valid + end + + it 'is invalid if comment is longer than 1000 characters' do + report = Fabricate.build(:report, comment: Faker::Lorem.characters(1001)) + report.valid? + expect(report).to model_have_error_on_field(:comment) + end + end end diff --git a/spec/services/activitypub/fetch_remote_account_service_spec.rb b/spec/services/activitypub/fetch_remote_account_service_spec.rb index 391d051c1a1..ed7e9bba839 100644 --- a/spec/services/activitypub/fetch_remote_account_service_spec.rb +++ b/spec/services/activitypub/fetch_remote_account_service_spec.rb @@ -41,7 +41,7 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do before do actor[:inbox] = nil - + stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor)) stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) end diff --git a/spec/services/unsubscribe_service_spec.rb b/spec/services/unsubscribe_service_spec.rb index c81772037e1..2a02f4c7555 100644 --- a/spec/services/unsubscribe_service_spec.rb +++ b/spec/services/unsubscribe_service_spec.rb @@ -26,7 +26,7 @@ RSpec.describe UnsubscribeService do stub_request(:post, 'http://hub.example.com/').to_raise(HTTP::Error) subject.call(account) - expect(logger).to have_received(:debug).with(/PuSH subscription request for bob@example.com could not be made due to HTTP or SSL error/) + expect(logger).to have_received(:debug).with(/unsubscribe for bob@example.com failed/) end def stub_logger