Skip to content
This repository has been archived by the owner on Aug 31, 2024. It is now read-only.

Commit

Permalink
implement undo follows
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpk committed Sep 1, 2018
1 parent 3655e57 commit b7c4078
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Console/Commands/GenerateToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function handle()
$user = User::where('username', $this->argument('username'))->first();

if(!$user)
$this->error('User not found');
return $this->error('User not found');

$token = new Token();

Expand Down
59 changes: 59 additions & 0 deletions app/Jobs/ActivityPub/Undo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
namespace App\Jobs\ActivityPub;
use App\Jobs\ActivityPubHandler;
use App\Inbox, App\Follower, App\Activity, App\User;
use Log;

class Undo extends ActivityPubHandler
{
public function handle()
{
Log::info('Handling undo request '.$this->_data->id);

$data = json_decode($this->_data->data, true);

if(!isset($data['object'])) {
Log::error('No object was found in the Undo request');
return;
}

if(!is_array($data['object'])) {
Log::error('The "object" of the Undo request was not an object');
return;
}

if(!isset($data['object']['type']) && $data['object']['type'] == 'Follow') {

if(!\p3k\url\host_matches($data['object']['object'], env('APP_URL'))) {
// Check if this is a follow request to a hosted account
if(parse_url($data['object']['object'], PHP_URL_PATH) == '/.well-known/user.json') {
$host = parse_url($data['object']['object'], PHP_URL_HOST);
$user = User::where('id', $this->_data->user_id)->first();
if($user->external_domain != $host) {
Log::error('Received an Undo Follow request for an external URL not hosted by this website');
return;
}
} else {
Log::error('Received a Undo Follow request for an object not on this website');
return;
}
}

$follower = Follower::where('user_id', $this->_data->user_id)
->where('profile_id', $this->_data->profile_id)
->first();

if($follower) {
Log::info('Profile '.$this->_data->profile_id.' unfollowed user '.$this->_data->user_id);
$follower->delete();
}

return;
}

if(!isset($data['object']['type']) && $data['object']['type'] == 'Create') {

}

}
}

0 comments on commit b7c4078

Please sign in to comment.