diff --git a/app/controllers/admin/custom_emojis_controller.rb b/app/controllers/admin/custom_emojis_controller.rb index ccab03de42..d61bafdf02 100644 --- a/app/controllers/admin/custom_emojis_controller.rb +++ b/app/controllers/admin/custom_emojis_controller.rb @@ -3,6 +3,7 @@ module Admin class CustomEmojisController < BaseController before_action :set_custom_emoji, except: [:index, :new, :create] + before_action :set_filter_params def index authorize :custom_emoji, :index? @@ -32,23 +33,26 @@ module Admin if @custom_emoji.update(resource_params) log_action :update, @custom_emoji - redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.updated_msg') + flash[:notice] = I18n.t('admin.custom_emojis.updated_msg') else - redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.update_failed_msg') + flash[:alert] = I18n.t('admin.custom_emojis.update_failed_msg') end + redirect_to admin_custom_emojis_path(page: params[:page], **@filter_params) end def destroy authorize @custom_emoji, :destroy? @custom_emoji.destroy! log_action :destroy, @custom_emoji - redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.destroyed_msg') + flash[:notice] = I18n.t('admin.custom_emojis.destroyed_msg') + redirect_to admin_custom_emojis_path(page: params[:page], **@filter_params) end def copy authorize @custom_emoji, :copy? - emoji = CustomEmoji.find_or_initialize_by(domain: nil, shortcode: @custom_emoji.shortcode) + emoji = CustomEmoji.find_or_initialize_by(domain: nil, + shortcode: @custom_emoji.shortcode) emoji.image = @custom_emoji.image if emoji.save @@ -58,21 +62,23 @@ module Admin flash[:alert] = I18n.t('admin.custom_emojis.copy_failed_msg') end - redirect_to admin_custom_emojis_path(page: params[:page]) + redirect_to admin_custom_emojis_path(page: params[:page], **@filter_params) end def enable authorize @custom_emoji, :enable? @custom_emoji.update!(disabled: false) log_action :enable, @custom_emoji - redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.enabled_msg') + flash[:notice] = I18n.t('admin.custom_emojis.enabled_msg') + redirect_to admin_custom_emojis_path(page: params[:page], **@filter_params) end def disable authorize @custom_emoji, :disable? @custom_emoji.update!(disabled: true) log_action :disable, @custom_emoji - redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.disabled_msg') + flash[:notice] = I18n.t('admin.custom_emojis.disabled_msg') + redirect_to admin_custom_emojis_path(page: params[:page], **@filter_params) end private @@ -81,6 +87,10 @@ module Admin @custom_emoji = CustomEmoji.find(params[:id]) end + def set_filter_params + @filter_params = filter_params.to_hash.symbolize_keys + end + def resource_params params.require(:custom_emoji).permit(:shortcode, :image, :visible_in_picker) end diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index eed5fb6b57..487282dc35 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -17,6 +17,8 @@ module Admin bootstrap_timeline_accounts thumbnail min_invite_role + activity_api_enabled + peers_api_enabled ).freeze BOOLEAN_SETTINGS = %w( @@ -24,6 +26,8 @@ module Admin open_deletion timeline_preview show_staff_badge + activity_api_enabled + peers_api_enabled ).freeze UPLOAD_SETTINGS = %w( diff --git a/app/controllers/api/v1/instances/activity_controller.rb b/app/controllers/api/v1/instances/activity_controller.rb new file mode 100644 index 0000000000..36f52c38d7 --- /dev/null +++ b/app/controllers/api/v1/instances/activity_controller.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +class Api::V1::Instances::ActivityController < Api::BaseController + before_action :require_enabled_api! + + respond_to :json + + def show + render_cached_json('api:v1:instances:activity:show', expires_in: 1.day) { activity } + end + + private + + def activity + weeks = [] + + 12.times do |i| + day = i.weeks.ago.to_date + week_id = day.cweek + week = Date.commercial(day.cwyear, week_id) + + weeks << { + week: week.to_time.to_i.to_s, + statuses: Redis.current.get("activity:statuses:local:#{week_id}") || 0, + logins: Redis.current.pfcount("activity:logins:#{week_id}"), + registrations: Redis.current.get("activity:accounts:local:#{week_id}") || 0, + } + end + + weeks + end + + def require_enabled_api! + head 404 unless Setting.activity_api_enabled + end +end diff --git a/app/controllers/api/v1/instances/peers_controller.rb b/app/controllers/api/v1/instances/peers_controller.rb new file mode 100644 index 0000000000..2070c487df --- /dev/null +++ b/app/controllers/api/v1/instances/peers_controller.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class Api::V1::Instances::PeersController < Api::BaseController + before_action :require_enabled_api! + + respond_to :json + + def index + render_cached_json('api:v1:instances:peers:index', expires_in: 1.day) { Account.remote.domains } + end + + private + + def require_enabled_api! + head 404 unless Setting.peers_api_enabled + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3b2070f39d..46367f2026 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -196,4 +196,13 @@ class ApplicationController < ActionController::Base end end end + + def render_cached_json(cache_key, **options) + data = Rails.cache.fetch(cache_key, { raw: true }.merge(options)) do + yield.to_json + end + + expires_in options[:expires_in], public: true + render json: data + end end diff --git a/app/controllers/auth/confirmations_controller.rb b/app/controllers/auth/confirmations_controller.rb index 5ffa1c9a30..72b8e9dd87 100644 --- a/app/controllers/auth/confirmations_controller.rb +++ b/app/controllers/auth/confirmations_controller.rb @@ -2,14 +2,9 @@ class Auth::ConfirmationsController < Devise::ConfirmationsController layout 'auth' + before_action :set_pack - def show - super do |user| - BootstrapTimelineWorker.perform_async(user.account_id) if user.errors.empty? - end - end - private def set_pack diff --git a/app/controllers/concerns/user_tracking_concern.rb b/app/controllers/concerns/user_tracking_concern.rb index 8663c3086b..1e31329411 100644 --- a/app/controllers/concerns/user_tracking_concern.rb +++ b/app/controllers/concerns/user_tracking_concern.rb @@ -17,6 +17,7 @@ module UserTrackingConcern # Mark as signed-in today current_user.update_tracked_fields!(request) + ActivityTracker.record('activity:logins', current_user.id) # Regenerate feed if needed regenerate_feed! if user_needs_feed_update? diff --git a/app/controllers/well_known/host_meta_controller.rb b/app/controllers/well_known/host_meta_controller.rb index 40f96eaa25..5fb70288a2 100644 --- a/app/controllers/well_known/host_meta_controller.rb +++ b/app/controllers/well_known/host_meta_controller.rb @@ -1,15 +1,19 @@ # frozen_string_literal: true module WellKnown - class HostMetaController < ApplicationController + class HostMetaController < ActionController::Base include RoutingHelper + before_action { response.headers['Vary'] = 'Accept' } + def show @webfinger_template = "#{webfinger_url}?resource={uri}" respond_to do |format| format.xml { render content_type: 'application/xrd+xml' } end + + expires_in(3.days, public: true) end end end diff --git a/app/controllers/well_known/webfinger_controller.rb b/app/controllers/well_known/webfinger_controller.rb index 5cc606808b..28654b61d8 100644 --- a/app/controllers/well_known/webfinger_controller.rb +++ b/app/controllers/well_known/webfinger_controller.rb @@ -1,9 +1,11 @@ # frozen_string_literal: true module WellKnown - class WebfingerController < ApplicationController + class WebfingerController < ActionController::Base include RoutingHelper + before_action { response.headers['Vary'] = 'Accept' } + def show @account = Account.find_local!(username_from_resource) @@ -16,6 +18,8 @@ module WellKnown render content_type: 'application/xrd+xml' end end + + expires_in(3.days, public: true) rescue ActiveRecord::RecordNotFound head 404 end diff --git a/app/javascript/images/mastodon-drawer.png b/app/javascript/images/mastodon-drawer.png new file mode 100644 index 0000000000..a1fb642a00 Binary files /dev/null and b/app/javascript/images/mastodon-drawer.png differ diff --git a/app/javascript/images/mastodon-getting-started.png b/app/javascript/images/mastodon-getting-started.png deleted file mode 100644 index 8fe0df76aa..0000000000 Binary files a/app/javascript/images/mastodon-getting-started.png and /dev/null differ diff --git a/app/javascript/images/wave-drawer.png b/app/javascript/images/wave-drawer.png new file mode 100644 index 0000000000..ca9f9e1d85 Binary files /dev/null and b/app/javascript/images/wave-drawer.png differ diff --git a/app/javascript/mastodon/actions/push_notifications/registerer.js b/app/javascript/mastodon/actions/push_notifications/registerer.js index f851c311c0..1d040bc8c8 100644 --- a/app/javascript/mastodon/actions/push_notifications/registerer.js +++ b/app/javascript/mastodon/actions/push_notifications/registerer.js @@ -51,7 +51,7 @@ const sendSubscriptionToBackend = (subscription, me) => { // Last one checks for payload support: https://web-push-book.gauntface.com/chapter-06/01-non-standards-browsers/#no-payload const supportsPushNotifications = ('serviceWorker' in navigator && 'PushManager' in window && 'getKey' in PushSubscription.prototype); -export default function register () { +export function register () { return (dispatch, getState) => { dispatch(setBrowserSupport(supportsPushNotifications)); const me = getState().getIn(['meta', 'me']); diff --git a/app/javascript/mastodon/features/compose/index.js b/app/javascript/mastodon/features/compose/index.js index 0c66585c98..c3e936ab9b 100644 --- a/app/javascript/mastodon/features/compose/index.js +++ b/app/javascript/mastodon/features/compose/index.js @@ -94,6 +94,7 @@ export default class Compose extends React.PureComponent {