user-status.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import React from "react"
  2. export default class extends React.Component {
  3. getClass() {
  4. return getStatusClassName(this.props.status)
  5. }
  6. render() {
  7. return <span className={this.getClass()}>{this.props.children}</span>
  8. }
  9. }
  10. export class StatusIcon extends React.Component {
  11. getIcon() {
  12. if (this.props.status.is_banned) {
  13. return "remove_circle_outline"
  14. } else if (this.props.status.is_hidden) {
  15. return "help_outline"
  16. } else if (this.props.status.is_online_hidden) {
  17. return "label"
  18. } else if (this.props.status.is_offline_hidden) {
  19. return "label_outline"
  20. } else if (this.props.status.is_online) {
  21. return "lens"
  22. } else if (this.props.status.is_offline) {
  23. return "panorama_fish_eye"
  24. }
  25. }
  26. render() {
  27. return <span className="material-icon status-icon">{this.getIcon()}</span>
  28. }
  29. }
  30. export class StatusLabel extends React.Component {
  31. getHelp() {
  32. return getStatusDescription(this.props.user, this.props.status)
  33. }
  34. getLabel() {
  35. if (this.props.status.is_banned) {
  36. return gettext("Banned")
  37. } else if (this.props.status.is_hidden) {
  38. return gettext("Hidden")
  39. } else if (this.props.status.is_online_hidden) {
  40. return gettext("Online (hidden)")
  41. } else if (this.props.status.is_offline_hidden) {
  42. return gettext("Offline (hidden)")
  43. } else if (this.props.status.is_online) {
  44. return gettext("Online")
  45. } else if (this.props.status.is_offline) {
  46. return gettext("Offline")
  47. }
  48. }
  49. render() {
  50. return (
  51. <span
  52. className={this.props.className || "status-label"}
  53. title={this.getHelp()}
  54. >
  55. {this.getLabel()}
  56. </span>
  57. )
  58. }
  59. }
  60. export function getStatusClassName(status) {
  61. let className = ""
  62. if (status.is_banned) {
  63. className = "banned"
  64. } else if (status.is_hidden) {
  65. className = "offline"
  66. } else if (status.is_online_hidden) {
  67. className = "online"
  68. } else if (status.is_offline_hidden) {
  69. className = "offline"
  70. } else if (status.is_online) {
  71. className = "online"
  72. } else if (status.is_offline) {
  73. className = "offline"
  74. }
  75. return "user-status user-" + className
  76. }
  77. export function getStatusDescription(user, status) {
  78. if (status.is_banned) {
  79. if (status.banned_until) {
  80. return interpolate(
  81. gettext("%(username)s is banned until %(ban_expires)s"),
  82. {
  83. username: user.username,
  84. ban_expires: status.banned_until.format("LL, LT")
  85. },
  86. true
  87. )
  88. } else {
  89. return interpolate(
  90. gettext("%(username)s is banned"),
  91. {
  92. username: user.username
  93. },
  94. true
  95. )
  96. }
  97. } else if (status.is_hidden) {
  98. return interpolate(
  99. gettext("%(username)s is hiding presence"),
  100. {
  101. username: user.username
  102. },
  103. true
  104. )
  105. } else if (status.is_online_hidden) {
  106. return interpolate(
  107. gettext("%(username)s is online (hidden)"),
  108. {
  109. username: user.username
  110. },
  111. true
  112. )
  113. } else if (status.is_offline_hidden) {
  114. return interpolate(
  115. gettext("%(username)s was last seen %(last_click)s (hidden)"),
  116. {
  117. username: user.username,
  118. last_click: status.last_click.fromNow()
  119. },
  120. true
  121. )
  122. } else if (status.is_online) {
  123. return interpolate(
  124. gettext("%(username)s is online"),
  125. {
  126. username: user.username
  127. },
  128. true
  129. )
  130. } else if (status.is_offline) {
  131. return interpolate(
  132. gettext("%(username)s was last seen %(last_click)s"),
  133. {
  134. username: user.username,
  135. last_click: status.last_click.fromNow()
  136. },
  137. true
  138. )
  139. }
  140. }