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.

110 lines
4.1 KiB

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