User.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace App;
  3. use App\Services\AvatarService;
  4. use App\Util\RateLimit\User as UserRateLimit;
  5. use Illuminate\Database\Eloquent\Factories\HasFactory;
  6. use Illuminate\Database\Eloquent\SoftDeletes;
  7. use Illuminate\Foundation\Auth\User as Authenticatable;
  8. use Illuminate\Notifications\Notifiable;
  9. use Laravel\Passport\HasApiTokens;
  10. use NotificationChannels\Expo\ExpoPushToken;
  11. use NotificationChannels\WebPush\HasPushSubscriptions;
  12. class User extends Authenticatable
  13. {
  14. use HasApiTokens, HasFactory, HasPushSubscriptions, Notifiable, SoftDeletes, UserRateLimit;
  15. /**
  16. * The attributes that should be mutated to dates.
  17. *
  18. * @var array
  19. */
  20. protected function casts(): array
  21. {
  22. return [
  23. 'deleted_at' => 'datetime',
  24. 'email_verified_at' => 'datetime',
  25. '2fa_setup_at' => 'datetime',
  26. 'last_active_at' => 'datetime',
  27. ];
  28. }
  29. /**
  30. * The attributes that are mass assignable.
  31. *
  32. * @var array
  33. */
  34. protected $fillable = [
  35. 'name',
  36. 'username',
  37. 'email',
  38. 'password',
  39. 'app_register_ip',
  40. 'email_verified_at',
  41. 'last_active_at',
  42. 'register_source',
  43. 'expo_token',
  44. 'notify_like',
  45. 'notify_follow',
  46. 'notify_mention',
  47. 'notify_comment',
  48. ];
  49. /**
  50. * The attributes that should be hidden for arrays.
  51. *
  52. * @var array
  53. */
  54. protected $hidden = [
  55. 'email', 'password', 'is_admin', 'remember_token',
  56. 'email_verified_at', '2fa_enabled', '2fa_secret',
  57. '2fa_backup_codes', '2fa_setup_at', 'deleted_at',
  58. 'updated_at',
  59. ];
  60. public function profile()
  61. {
  62. return $this->hasOne(Profile::class);
  63. }
  64. public function url()
  65. {
  66. return url(config('app.url').'/'.$this->username);
  67. }
  68. public function settings()
  69. {
  70. return $this->hasOne(UserSetting::class);
  71. }
  72. public function statuses()
  73. {
  74. return $this->hasManyThrough(
  75. Status::class,
  76. Profile::class
  77. );
  78. }
  79. public function filters()
  80. {
  81. return $this->hasMany(UserFilter::class, 'user_id', 'profile_id');
  82. }
  83. public function receivesBroadcastNotificationsOn()
  84. {
  85. return 'App.User.'.$this->id;
  86. }
  87. public function devices()
  88. {
  89. return $this->hasMany(UserDevice::class);
  90. }
  91. public function storageUsedKey()
  92. {
  93. return 'profile:storage:used:'.$this->id;
  94. }
  95. public function accountLog()
  96. {
  97. return $this->hasMany(AccountLog::class);
  98. }
  99. public function interstitials()
  100. {
  101. return $this->hasMany(AccountInterstitial::class);
  102. }
  103. public function avatarUrl()
  104. {
  105. if (! $this->profile_id || $this->status) {
  106. return config('app.url').'/storage/avatars/default.jpg';
  107. }
  108. return AvatarService::get($this->profile_id);
  109. }
  110. public function routeNotificationForExpo()
  111. {
  112. return $this->expo_token;
  113. }
  114. }