You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
4.1 KiB

  1. # frozen_string_literal: true
  2. module AccountsHelper
  3. def display_name(account, **options)
  4. if options[:custom_emojify]
  5. Formatter.instance.format_display_name(account, **options)
  6. else
  7. account.display_name.presence || account.username
  8. end
  9. end
  10. def acct(account)
  11. if account.local?
  12. "@#{account.acct}@#{site_hostname}"
  13. else
  14. "@#{account.pretty_acct}"
  15. end
  16. end
  17. def account_action_button(account)
  18. if user_signed_in?
  19. if account.id == current_user.account_id
  20. link_to settings_profile_url, class: 'button logo-button' do
  21. safe_join([svg_logo, t('settings.edit_profile')])
  22. end
  23. elsif current_account.following?(account) || current_account.requested?(account)
  24. link_to account_unfollow_path(account), class: 'button logo-button button--destructive', data: { method: :post } do
  25. safe_join([svg_logo, t('accounts.unfollow')])
  26. end
  27. elsif !(account.memorial? || account.moved?)
  28. link_to account_follow_path(account), class: "button logo-button#{account.blocking?(current_account) ? ' disabled' : ''}", data: { method: :post } do
  29. safe_join([svg_logo, t('accounts.follow')])
  30. end
  31. end
  32. elsif !(account.memorial? || account.moved?)
  33. link_to account_remote_follow_path(account), class: 'button logo-button modal-button', target: '_new' do
  34. safe_join([svg_logo, t('accounts.follow')])
  35. end
  36. end
  37. end
  38. def minimal_account_action_button(account)
  39. if user_signed_in?
  40. return if account.id == current_user.account_id
  41. if current_account.following?(account) || current_account.requested?(account)
  42. link_to account_unfollow_path(account), class: 'icon-button active', data: { method: :post }, title: t('accounts.unfollow') do
  43. fa_icon('user-times fw')
  44. end
  45. elsif !(account.memorial? || account.moved?)
  46. link_to account_follow_path(account), class: "icon-button#{account.blocking?(current_account) ? ' disabled' : ''}", data: { method: :post }, title: t('accounts.follow') do
  47. fa_icon('user-plus fw')
  48. end
  49. end
  50. elsif !(account.memorial? || account.moved?)
  51. link_to account_remote_follow_path(account), class: 'icon-button modal-button', target: '_new', title: t('accounts.follow') do
  52. fa_icon('user-plus fw')
  53. end
  54. end
  55. end
  56. def account_badge(account, all: false)
  57. if account.bot?
  58. content_tag(:div, content_tag(:div, t('accounts.roles.bot'), class: 'account-role bot'), class: 'roles')
  59. elsif account.group?
  60. content_tag(:div, content_tag(:div, t('accounts.roles.group'), class: 'account-role group'), class: 'roles')
  61. elsif (Setting.show_staff_badge && account.user_staff?) || all
  62. content_tag(:div, class: 'roles') do
  63. if all && !account.user_staff?
  64. content_tag(:div, t('admin.accounts.roles.user'), class: 'account-role')
  65. elsif account.user_admin?
  66. content_tag(:div, t('accounts.roles.admin'), class: 'account-role admin')
  67. elsif account.user_moderator?
  68. content_tag(:div, t('accounts.roles.moderator'), class: 'account-role moderator')
  69. end
  70. end
  71. end
  72. end
  73. def account_description(account)
  74. prepend_str = [
  75. [
  76. number_to_human(account.statuses_count, precision: 3, strip_insignificant_zeros: true),
  77. I18n.t('accounts.posts', count: account.statuses_count),
  78. ].join(' '),
  79. [
  80. number_to_human(account.following_count, precision: 3, strip_insignificant_zeros: true),
  81. I18n.t('accounts.following', count: account.following_count),
  82. ].join(' '),
  83. [
  84. number_to_human(account.followers_count, precision: 3, strip_insignificant_zeros: true),
  85. I18n.t('accounts.followers', count: account.followers_count),
  86. ].join(' '),
  87. ].join(', ')
  88. [prepend_str, account.note].join(' · ')
  89. end
  90. def svg_logo
  91. content_tag(:svg, tag(:use, 'xlink:href' => '#mastodon-svg-logo'), 'viewBox' => '0 0 216.4144 232.00976')
  92. end
  93. def svg_logo_full
  94. content_tag(:svg, tag(:use, 'xlink:href' => '#mastodon-svg-logo-full'), 'viewBox' => '0 0 713.35878 175.8678')
  95. end
  96. end