2019-10-25 07:50:09 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module AccountsHelper
|
|
|
|
def display_name(account, **options)
|
2022-03-26 12:53:34 +11:00
|
|
|
str = account.display_name.presence || account.username
|
|
|
|
|
2019-10-25 07:50:09 +11:00
|
|
|
if options[:custom_emojify]
|
2022-03-26 12:53:34 +11:00
|
|
|
prerender_custom_emojis(h(str), account.emojis)
|
2019-10-25 07:50:09 +11:00
|
|
|
else
|
2022-03-26 12:53:34 +11:00
|
|
|
str
|
2019-10-25 07:50:09 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def acct(account)
|
|
|
|
if account.local?
|
2020-02-04 04:44:54 +11:00
|
|
|
"@#{account.acct}@#{site_hostname}"
|
2019-10-25 07:50:09 +11:00
|
|
|
else
|
2019-12-31 05:20:43 +11:00
|
|
|
"@#{account.pretty_acct}"
|
2019-10-25 07:50:09 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def account_action_button(account)
|
|
|
|
if user_signed_in?
|
|
|
|
if account.id == current_user.account_id
|
|
|
|
link_to settings_profile_url, class: 'button logo-button' do
|
2022-06-10 06:25:23 +10:00
|
|
|
safe_join([logo_as_symbol, t('settings.edit_profile')])
|
2019-10-25 07:50:09 +11:00
|
|
|
end
|
|
|
|
elsif current_account.following?(account) || current_account.requested?(account)
|
|
|
|
link_to account_unfollow_path(account), class: 'button logo-button button--destructive', data: { method: :post } do
|
2022-06-10 06:25:23 +10:00
|
|
|
safe_join([logo_as_symbol, t('accounts.unfollow')])
|
2019-10-25 07:50:09 +11:00
|
|
|
end
|
|
|
|
elsif !(account.memorial? || account.moved?)
|
|
|
|
link_to account_follow_path(account), class: "button logo-button#{account.blocking?(current_account) ? ' disabled' : ''}", data: { method: :post } do
|
2022-06-10 06:25:23 +10:00
|
|
|
safe_join([logo_as_symbol, t('accounts.follow')])
|
2019-10-25 07:50:09 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
elsif !(account.memorial? || account.moved?)
|
|
|
|
link_to account_remote_follow_path(account), class: 'button logo-button modal-button', target: '_new' do
|
2022-06-10 06:25:23 +10:00
|
|
|
safe_join([logo_as_symbol, t('accounts.follow')])
|
2019-10-25 07:50:09 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def minimal_account_action_button(account)
|
|
|
|
if user_signed_in?
|
|
|
|
return if account.id == current_user.account_id
|
|
|
|
|
|
|
|
if current_account.following?(account) || current_account.requested?(account)
|
|
|
|
link_to account_unfollow_path(account), class: 'icon-button active', data: { method: :post }, title: t('accounts.unfollow') do
|
|
|
|
fa_icon('user-times fw')
|
|
|
|
end
|
|
|
|
elsif !(account.memorial? || account.moved?)
|
|
|
|
link_to account_follow_path(account), class: "icon-button#{account.blocking?(current_account) ? ' disabled' : ''}", data: { method: :post }, title: t('accounts.follow') do
|
|
|
|
fa_icon('user-plus fw')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elsif !(account.memorial? || account.moved?)
|
|
|
|
link_to account_remote_follow_path(account), class: 'icon-button modal-button', target: '_new', title: t('accounts.follow') do
|
|
|
|
fa_icon('user-plus fw')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-05 10:41:40 +10:00
|
|
|
def account_badge(account)
|
2019-10-25 07:50:09 +11:00
|
|
|
if account.bot?
|
|
|
|
content_tag(:div, content_tag(:div, t('accounts.roles.bot'), class: 'account-role bot'), class: 'roles')
|
2019-12-05 10:50:40 +11:00
|
|
|
elsif account.group?
|
|
|
|
content_tag(:div, content_tag(:div, t('accounts.roles.group'), class: 'account-role group'), class: 'roles')
|
2022-07-05 10:41:40 +10:00
|
|
|
elsif account.user_role&.highlighted?
|
|
|
|
content_tag(:div, content_tag(:div, account.user_role.name, class: "account-role user-role-#{account.user_role.id}"), class: 'roles')
|
2019-10-25 07:50:09 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def account_description(account)
|
|
|
|
prepend_str = [
|
|
|
|
[
|
2021-07-08 05:13:08 +10:00
|
|
|
number_to_human(account.statuses_count, precision: 3, strip_insignificant_zeros: true),
|
2019-10-25 07:50:09 +11:00
|
|
|
I18n.t('accounts.posts', count: account.statuses_count),
|
|
|
|
].join(' '),
|
|
|
|
|
|
|
|
[
|
2021-07-08 05:13:08 +10:00
|
|
|
number_to_human(account.following_count, precision: 3, strip_insignificant_zeros: true),
|
2019-10-25 07:50:09 +11:00
|
|
|
I18n.t('accounts.following', count: account.following_count),
|
|
|
|
].join(' '),
|
|
|
|
|
|
|
|
[
|
2021-07-08 05:13:08 +10:00
|
|
|
number_to_human(account.followers_count, precision: 3, strip_insignificant_zeros: true),
|
2019-10-25 07:50:09 +11:00
|
|
|
I18n.t('accounts.followers', count: account.followers_count),
|
|
|
|
].join(' '),
|
|
|
|
].join(', ')
|
|
|
|
|
2022-03-18 02:32:11 +11:00
|
|
|
[prepend_str, account.note].join(' · ')
|
2019-10-25 07:50:09 +11:00
|
|
|
end
|
|
|
|
end
|