diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2018-06-15 18:00:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-15 18:00:23 +0200 |
commit | ca85658975dd6c85fbe5cc725698fe3a34d1234e (patch) | |
tree | 10a3d40ea8a1d74e8f4b2a8553d7cb11e23d588c /app | |
parent | 33dd9bf36d7cb7c94f76520357879d1a913c4ccb (diff) |
Add autofollow option to invites (#7805)
* Add autofollow option to invites * Trigger CodeClimate rebuild
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/auth/registrations_controller.rb | 7 | ||||
-rw-r--r-- | app/controllers/invites_controller.rb | 4 | ||||
-rw-r--r-- | app/javascript/styles/mastodon/accounts.scss | 51 | ||||
-rw-r--r-- | app/models/invite.rb | 1 | ||||
-rw-r--r-- | app/services/bootstrap_timeline_service.rb | 18 | ||||
-rw-r--r-- | app/views/auth/registrations/new.html.haml | 5 | ||||
-rw-r--r-- | app/views/authorize_follows/_card.html.haml | 14 | ||||
-rw-r--r-- | app/views/invites/_form.html.haml | 3 |
8 files changed, 86 insertions, 17 deletions
diff --git a/app/controllers/auth/registrations_controller.rb b/app/controllers/auth/registrations_controller.rb index 417e2b63b..c095411c1 100644 --- a/app/controllers/auth/registrations_controller.rb +++ b/app/controllers/auth/registrations_controller.rb @@ -3,6 +3,7 @@ class Auth::RegistrationsController < Devise::RegistrationsController layout :determine_layout + before_action :set_invite, only: [:new, :create] before_action :check_enabled_registrations, only: [:new, :create] before_action :configure_sign_up_params, only: [:create] before_action :set_sessions, only: [:edit, :update] @@ -51,7 +52,7 @@ class Auth::RegistrationsController < Devise::RegistrationsController end def allowed_registrations? - Setting.open_registrations || (invite_code.present? && Invite.find_by(code: invite_code)&.valid_for_use?) + Setting.open_registrations || @invite&.valid_for_use? end def invite_code @@ -68,6 +69,10 @@ class Auth::RegistrationsController < Devise::RegistrationsController @instance_presenter = InstancePresenter.new end + def set_invite + @invite = invite_code.present? ? Invite.find_by(code: invite_code) : nil + end + def determine_layout %w(edit update).include?(action_name) ? 'admin' : 'auth' end diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb index 26ef99b7e..5c30313f4 100644 --- a/app/controllers/invites_controller.rb +++ b/app/controllers/invites_controller.rb @@ -11,7 +11,7 @@ class InvitesController < ApplicationController authorize :invite, :create? @invites = invites - @invite = Invite.new(expires_in: 1.day.to_i) + @invite = Invite.new end def create @@ -42,6 +42,6 @@ class InvitesController < ApplicationController end def resource_params - params.require(:invite).permit(:max_uses, :expires_in) + params.require(:invite).permit(:max_uses, :expires_in, :autofollow) end end diff --git a/app/javascript/styles/mastodon/accounts.scss b/app/javascript/styles/mastodon/accounts.scss index 3ccce383b..14dc5dd62 100644 --- a/app/javascript/styles/mastodon/accounts.scss +++ b/app/javascript/styles/mastodon/accounts.scss @@ -458,23 +458,31 @@ } .account-card { - padding: 14px 10px; - background: $simple-background-color; border-radius: 4px; text-align: left; box-shadow: 0 0 15px rgba($base-shadow-color, 0.2); + background: $simple-background-color; + + &__header { + background-size: cover; + background-position: center center; + height: 90px; + border-radius: 4px 4px 0 0; + } - .detailed-status__display-name { + & > .detailed-status__display-name { display: block; overflow: hidden; - margin-bottom: 15px; + display: flex; + align-items: center; + padding: 10px; &:last-child { margin-bottom: 0; } - & > div { - float: left; + & > div:first-child { + flex: 0 0 auto; margin-right: 10px; width: 48px; height: 48px; @@ -483,9 +491,11 @@ .avatar { display: block; border-radius: 4px; + margin: 0; } .display-name { + flex: 1 0 auto; display: block; max-width: 100%; overflow: hidden; @@ -493,6 +503,10 @@ text-overflow: ellipsis; cursor: default; + & > .detailed-status__display-name { + margin-bottom: 0; + } + strong { font-weight: 500; color: $ui-base-color; @@ -519,9 +533,28 @@ } } - .account__header__content { - font-size: 14px; - color: $inverted-text-color; + .counter { + box-sizing: border-box; + flex: 0 0 auto; + color: $light-text-color; + padding: 0 10px; + cursor: default; + text-align: center; + position: relative; + line-height: 24px; + + .counter-label { + font-size: 12px; + display: block; + text-transform: uppercase; + } + + .counter-number { + font-weight: 500; + font-size: 16px; + color: $inverted-text-color; + font-family: 'mastodon-font-display', sans-serif; + } } } diff --git a/app/models/invite.rb b/app/models/invite.rb index 2250e588e..d0cc427c4 100644 --- a/app/models/invite.rb +++ b/app/models/invite.rb @@ -11,6 +11,7 @@ # uses :integer default(0), not null # created_at :datetime not null # updated_at :datetime not null +# autofollow :boolean default(FALSE), not null # class Invite < ApplicationRecord diff --git a/app/services/bootstrap_timeline_service.rb b/app/services/bootstrap_timeline_service.rb index c01e25824..db2c83e5d 100644 --- a/app/services/bootstrap_timeline_service.rb +++ b/app/services/bootstrap_timeline_service.rb @@ -2,13 +2,25 @@ class BootstrapTimelineService < BaseService def call(source_account) - bootstrap_timeline_accounts.each do |target_account| - FollowService.new.call(source_account, target_account) - end + @source_account = source_account + + autofollow_inviter! + autofollow_bootstrap_timeline_accounts! end private + def autofollow_inviter! + return unless @source_account&.user&.invite&.autofollow? + FollowService.new.call(@source_account, @source_account.user.invite.user.account) + end + + def autofollow_bootstrap_timeline_accounts! + bootstrap_timeline_accounts.each do |target_account| + FollowService.new.call(@source_account, target_account) + end + end + def bootstrap_timeline_accounts return @bootstrap_timeline_accounts if defined?(@bootstrap_timeline_accounts) diff --git a/app/views/auth/registrations/new.html.haml b/app/views/auth/registrations/new.html.haml index 2d4c0f5ac..0fac8e10d 100644 --- a/app/views/auth/registrations/new.html.haml +++ b/app/views/auth/registrations/new.html.haml @@ -7,6 +7,11 @@ = simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| = render 'shared/error_messages', object: resource + - if @invite.present? && @invite.autofollow? + .fields-group{ style: 'margin-bottom: 30px' } + %p.hint{ style: 'text-align: center' }= t('invites.invited_by') + = render 'authorize_follows/card', account: @invite.user.account + = f.simple_fields_for :account do |ff| .input-with-append = ff.input :username, autofocus: true, placeholder: t('simple_form.labels.defaults.username'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.username'), :autocomplete => 'off' } diff --git a/app/views/authorize_follows/_card.html.haml b/app/views/authorize_follows/_card.html.haml index 9abcfd37e..edc03131f 100644 --- a/app/views/authorize_follows/_card.html.haml +++ b/app/views/authorize_follows/_card.html.haml @@ -1,4 +1,5 @@ .account-card + .account-card__header{ style: "background-image: url(#{account.header.url(:original)})" } .detailed-status__display-name %div = image_tag account.avatar.url(:original), alt: '', width: 48, height: 48, class: 'avatar' @@ -9,5 +10,14 @@ %strong.emojify= display_name(account, custom_emojify: true) %span @#{account.acct} - - if account.note? - .account__header__content.emojify= Formatter.instance.simplified_format(account) + .counter + %span.counter-number= number_to_human account.statuses_count, strip_insignificant_zeros: true + %span.counter-label= t('accounts.posts') + + .counter + %span.counter-number= number_to_human account.following_count, strip_insignificant_zeros: true + %span.counter-label= t('accounts.following') + + .counter + %span.counter-number= number_to_human account.followers_count, strip_insignificant_zeros: true + %span.counter-label= t('accounts.followers') diff --git a/app/views/invites/_form.html.haml b/app/views/invites/_form.html.haml index 3f0871f47..42a107bb2 100644 --- a/app/views/invites/_form.html.haml +++ b/app/views/invites/_form.html.haml @@ -5,5 +5,8 @@ = f.input :max_uses, wrapper: :with_label, collection: [1, 5, 10, 25, 50, 100], label_method: lambda { |num| I18n.t('invites.max_uses', count: num) }, prompt: I18n.t('invites.max_uses_prompt') = f.input :expires_in, wrapper: :with_label, collection: [30.minutes, 1.hour, 6.hours, 12.hours, 1.day, 1.week].map(&:to_i), label_method: lambda { |i| I18n.t("invites.expires_in.#{i}") }, prompt: I18n.t('invites.expires_in_prompt') + .fields-group + = f.input :autofollow, wrapper: :with_label + .actions = f.button :button, t('invites.generate'), type: :submit |