accounts_helper.rb 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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([logo_as_symbol, 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([logo_as_symbol, 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([logo_as_symbol, 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([logo_as_symbol, 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)
  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 account.user_role&.highlighted?
  63. content_tag(:div, content_tag(:div, account.user_role.name, class: "account-role user-role-#{account.user_role.id}"), class: 'roles')
  64. end
  65. end
  66. def account_description(account)
  67. prepend_str = [
  68. [
  69. number_to_human(account.statuses_count, precision: 3, strip_insignificant_zeros: true),
  70. I18n.t('accounts.posts', count: account.statuses_count),
  71. ].join(' '),
  72. [
  73. number_to_human(account.following_count, precision: 3, strip_insignificant_zeros: true),
  74. I18n.t('accounts.following', count: account.following_count),
  75. ].join(' '),
  76. [
  77. number_to_human(account.followers_count, precision: 3, strip_insignificant_zeros: true),
  78. I18n.t('accounts.followers', count: account.followers_count),
  79. ].join(' '),
  80. ].join(', ')
  81. [prepend_str, account.note].join(' · ')
  82. end
  83. end