-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathUnfollow.class.php
More file actions
53 lines (44 loc) · 1.45 KB
/
Unfollow.class.php
File metadata and controls
53 lines (44 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace wcf\system\user\command;
use wcf\data\user\follow\UserFollow;
use wcf\data\user\follow\UserFollowEditor;
use wcf\data\user\User;
use wcf\system\user\activity\event\UserActivityEventHandler;
use wcf\system\user\storage\UserStorageHandler;
/**
* Saves that a user is unfollowing another user.
*
* @author Marcel Werk
* @copyright 2001-2024 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.1
*/
final class Unfollow
{
public function __construct(
private readonly User $user,
private readonly User $target,
) {}
public function __invoke(): void
{
$follow = UserFollow::getFollow($this->user->userID, $this->target->userID);
if ($follow->followID) {
$followEditor = new UserFollowEditor($follow);
$followEditor->delete();
$this->removeActivityEvent();
}
$this->resetUserStorage();
}
private function removeActivityEvent(): void
{
UserActivityEventHandler::getInstance()->removeEvent(
'com.woltlab.wcf.user.recentActivityEvent.follow',
$this->target->userID
);
}
private function resetUserStorage(): void
{
UserStorageHandler::getInstance()->reset([$this->target->userID], 'followerUserIDs');
UserStorageHandler::getInstance()->reset([$this->user->userID], 'followingUserIDs');
}
}