1
0

PrivacySettings.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. namespace App\Http\Controllers\Settings;
  3. use App\AccountLog;
  4. use App\EmailVerification;
  5. use App\Instance;
  6. use App\Follower;
  7. use App\Media;
  8. use App\Profile;
  9. use App\User;
  10. use App\UserFilter;
  11. use App\Util\Lexer\PrettyNumber;
  12. use App\Util\ActivityPub\Helpers;
  13. use Auth, Cache, DB;
  14. use Illuminate\Http\Request;
  15. use App\Models\UserDomainBlock;
  16. trait PrivacySettings
  17. {
  18. public function privacy()
  19. {
  20. $user = Auth::user();
  21. $settings = $user->settings;
  22. $profile = $user->profile;
  23. $is_private = $profile->is_private;
  24. $settings['is_private'] = (bool) $is_private;
  25. return view('settings.privacy', compact('settings', 'profile'));
  26. }
  27. public function privacyStore(Request $request)
  28. {
  29. $settings = $request->user()->settings;
  30. $profile = $request->user()->profile;
  31. $fields = [
  32. 'is_private',
  33. 'crawlable',
  34. 'public_dm',
  35. 'show_profile_follower_count',
  36. 'show_profile_following_count',
  37. 'indexable',
  38. 'show_atom',
  39. ];
  40. $profile->indexable = $request->input('indexable') == 'on';
  41. $profile->is_suggestable = $request->input('is_suggestable') == 'on';
  42. $profile->save();
  43. foreach ($fields as $field) {
  44. $form = $request->input($field);
  45. if ($field == 'is_private') {
  46. if ($form == 'on') {
  47. $profile->{$field} = true;
  48. $settings->show_guests = false;
  49. $settings->show_discover = false;
  50. $profile->save();
  51. } else {
  52. $profile->{$field} = false;
  53. $profile->save();
  54. }
  55. Cache::forget('profiles:private');
  56. } elseif ($field == 'crawlable') {
  57. if ($form == 'on') {
  58. $settings->{$field} = false;
  59. } else {
  60. $settings->{$field} = true;
  61. }
  62. } elseif ($field == 'public_dm') {
  63. if ($form == 'on') {
  64. $settings->{$field} = true;
  65. } else {
  66. $settings->{$field} = false;
  67. }
  68. } elseif ($field == 'indexable') {
  69. } else {
  70. if ($form == 'on') {
  71. $settings->{$field} = true;
  72. } else {
  73. $settings->{$field} = false;
  74. }
  75. }
  76. $settings->save();
  77. }
  78. $pid = $profile->id;
  79. Cache::forget('profile:settings:' . $pid);
  80. Cache::forget('user:account:id:' . $profile->user_id);
  81. Cache::forget('profile:follower_count:' . $pid);
  82. Cache::forget('profile:following_count:' . $pid);
  83. Cache::forget('profile:atom:enabled:' . $pid);
  84. Cache::forget('profile:embed:' . $pid);
  85. Cache::forget('pf:acct:settings:hidden-followers:' . $pid);
  86. Cache::forget('pf:acct:settings:hidden-following:' . $pid);
  87. Cache::forget('pf:acct-trans:hideFollowing:' . $pid);
  88. Cache::forget('pf:acct-trans:hideFollowers:' . $pid);
  89. Cache::forget('pfc:cached-user:wt:' . strtolower($profile->username));
  90. Cache::forget('pfc:cached-user:wot:' . strtolower($profile->username));
  91. return redirect(route('settings.privacy'))->with('status', 'Settings successfully updated!');
  92. }
  93. public function mutedUsers()
  94. {
  95. $pid = Auth::user()->profile->id;
  96. $ids = (new UserFilter())->mutedUserIds($pid);
  97. $users = Profile::whereIn('id', $ids)->simplePaginate(15);
  98. return view('settings.privacy.muted', compact('users'));
  99. }
  100. public function mutedUsersUpdate(Request $request)
  101. {
  102. $this->validate($request, [
  103. 'profile_id' => 'required|integer|min:1'
  104. ]);
  105. $fid = $request->input('profile_id');
  106. $pid = Auth::user()->profile->id;
  107. DB::transaction(function () use ($fid, $pid) {
  108. $filter = UserFilter::whereUserId($pid)
  109. ->whereFilterableId($fid)
  110. ->whereFilterableType('App\Profile')
  111. ->whereFilterType('mute')
  112. ->firstOrFail();
  113. $filter->delete();
  114. });
  115. return redirect()->back();
  116. }
  117. public function blockedUsers()
  118. {
  119. $pid = Auth::user()->profile->id;
  120. $ids = (new UserFilter())->blockedUserIds($pid);
  121. $users = Profile::whereIn('id', $ids)->simplePaginate(15);
  122. return view('settings.privacy.blocked', compact('users'));
  123. }
  124. public function blockedUsersUpdate(Request $request)
  125. {
  126. $this->validate($request, [
  127. 'profile_id' => 'required|integer|min:1'
  128. ]);
  129. $fid = $request->input('profile_id');
  130. $pid = Auth::user()->profile->id;
  131. DB::transaction(function () use ($fid, $pid) {
  132. $filter = UserFilter::whereUserId($pid)
  133. ->whereFilterableId($fid)
  134. ->whereFilterableType('App\Profile')
  135. ->whereFilterType('block')
  136. ->firstOrFail();
  137. $filter->delete();
  138. });
  139. return redirect()->back();
  140. }
  141. public function blockedInstances()
  142. {
  143. // deprecated
  144. abort(404);
  145. }
  146. public function domainBlocks()
  147. {
  148. return view('settings.privacy.domain-blocks');
  149. }
  150. public function blockedInstanceStore(Request $request)
  151. {
  152. // deprecated
  153. abort(404);
  154. }
  155. public function blockedInstanceUnblock(Request $request)
  156. {
  157. // deprecated
  158. abort(404);
  159. }
  160. public function blockedKeywords()
  161. {
  162. return view('settings.privacy.blocked-keywords');
  163. }
  164. public function privateAccountOptions(Request $request)
  165. {
  166. $this->validate($request, [
  167. 'mode' => 'required|string|in:keep-all,mutual-only,only-followers,remove-all',
  168. 'duration' => 'required|integer|min:60|max:525600',
  169. ]);
  170. $mode = $request->input('mode');
  171. $duration = $request->input('duration');
  172. // $newRequests = $request->input('newrequests');
  173. $profile = Auth::user()->profile;
  174. $settings = Auth::user()->settings;
  175. if($mode !== 'keep-all') {
  176. switch ($mode) {
  177. case 'mutual-only':
  178. $following = $profile->following()->pluck('profiles.id');
  179. Follower::whereFollowingId($profile->id)->whereNotIn('profile_id', $following)->delete();
  180. break;
  181. case 'only-followers':
  182. $ts = now()->subMinutes($duration);
  183. Follower::whereFollowingId($profile->id)->where('created_at', '>', $ts)->delete();
  184. break;
  185. case 'remove-all':
  186. Follower::whereFollowingId($profile->id)->delete();
  187. break;
  188. default:
  189. # code...
  190. break;
  191. }
  192. }
  193. $profile->is_private = true;
  194. $settings->show_guests = false;
  195. $settings->show_discover = false;
  196. $settings->save();
  197. $profile->save();
  198. Cache::forget('profiles:private');
  199. return [200];
  200. }
  201. }