Skip to content

Commit 844698d

Browse files
BurntimeXdtdesign
authored andcommitted
--Restore Unfollow.class.php
1 parent a862cbf commit 844698d

File tree

1 file changed

+52
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)