Unverified Commit 134a071a authored by Yassine Doghri's avatar Yassine Doghri
Browse files

refactor: rename all occurences of notes to statuses

parent ddeabf56
......@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace Config;
use App\Entities\Actor;
use App\Entities\Note;
use App\Entities\Status;
use App\Entities\User;
use CodeIgniter\Events\Events;
use CodeIgniter\Exceptions\FrameworkException;
......@@ -120,82 +120,82 @@ Events::on('on_undo_follow', function ($actor, $targetActor): void {
});
/**
* @param Note $note
* @param Status $status
*/
Events::on('on_note_add', function ($note): void {
if ($note->in_reply_to_id !== null) {
$note = $note->reply_to_note;
Events::on('on_status_add', function ($status): void {
if ($status->in_reply_to_id !== null) {
$status = $status->reply_to_status;
}
if ($note->episode_id) {
if ($status->episode_id) {
model('EpisodeModel')
->where('id', $note->episode_id)
->increment('notes_total');
->where('id', $status->episode_id)
->increment('statuses_total');
}
if ($note->actor->is_podcast) {
if ($status->actor->is_podcast) {
// Removing all of the podcast pages is a bit overkill, but works to avoid caching bugs
// same for other events below
cache()
->deleteMatching("podcast#{$note->actor->podcast->id}*");
->deleteMatching("podcast#{$status->actor->podcast->id}*");
cache()
->deleteMatching("page_podcast#{$note->actor->podcast->id}*");
->deleteMatching("page_podcast#{$status->actor->podcast->id}*");
}
});
/**
* @param Note $note
* @param Status $status
*/
Events::on('on_note_remove', function ($note): void {
if ($note->in_reply_to_id !== null) {
Events::trigger('on_note_remove', $note->reply_to_note);
Events::on('on_status_remove', function ($status): void {
if ($status->in_reply_to_id !== null) {
Events::trigger('on_status_remove', $status->reply_to_status);
}
if ($episodeId = $note->episode_id) {
if ($episodeId = $status->episode_id) {
model('EpisodeModel')
->where('id', $episodeId)
->decrement('notes_total', 1 + $note->reblogs_count);
->decrement('statuses_total', 1 + $status->reblogs_count);
model('EpisodeModel')
->where('id', $episodeId)
->decrement('reblogs_total', $note->reblogs_count);
->decrement('reblogs_total', $status->reblogs_count);
model('EpisodeModel')
->where('id', $episodeId)
->decrement('favourites_total', $note->favourites_count);
->decrement('favourites_total', $status->favourites_count);
}
if ($note->actor->is_podcast) {
if ($status->actor->is_podcast) {
cache()
->deleteMatching("podcast#{$note->actor->podcast->id}*");
->deleteMatching("podcast#{$status->actor->podcast->id}*");
cache()
->deleteMatching("page_podcast#{$note->actor->podcast->id}*");
->deleteMatching("page_podcast#{$status->actor->podcast->id}*");
}
cache()
->deleteMatching("page_note#{$note->id}*");
->deleteMatching("page_status#{$status->id}*");
});
/**
* @param Actor $actor
* @param Note $note
* @param Status $status
*/
Events::on('on_note_reblog', function ($actor, $note): void {
if ($episodeId = $note->episode_id) {
Events::on('on_status_reblog', function ($actor, $status): void {
if ($episodeId = $status->episode_id) {
model('EpisodeModel')
->where('id', $episodeId)
->increment('reblogs_total');
model('EpisodeModel')
->where('id', $episodeId)
->increment('notes_total');
->increment('statuses_total');
}
if ($note->actor->is_podcast) {
if ($status->actor->is_podcast) {
cache()
->deleteMatching("podcast#{$note->actor->podcast->id}*");
->deleteMatching("podcast#{$status->actor->podcast->id}*");
cache()
->deleteMatching("page_podcast#{$note->actor->podcast->id}*");
->deleteMatching("page_podcast#{$status->actor->podcast->id}*");
}
if ($actor->is_podcast) {
......@@ -205,111 +205,111 @@ Events::on('on_note_reblog', function ($actor, $note): void {
}
cache()
->deleteMatching("page_note#{$note->id}*");
->deleteMatching("page_status#{$status->id}*");
if ($note->in_reply_to_id !== null) {
cache()->deleteMatching("page_note#{$note->in_reply_to_id}");
if ($status->in_reply_to_id !== null) {
cache()->deleteMatching("page_status#{$status->in_reply_to_id}");
}
});
/**
* @param Note $reblogNote
* @param Status $reblogStatus
*/
Events::on('on_note_undo_reblog', function ($reblogNote): void {
$note = $reblogNote->reblog_of_note;
if ($episodeId = $note->episode_id) {
Events::on('on_status_undo_reblog', function ($reblogStatus): void {
$status = $reblogStatus->reblog_of_status;
if ($episodeId = $status->episode_id) {
model('EpisodeModel')
->where('id', $episodeId)
->decrement('reblogs_total');
model('EpisodeModel')
->where('id', $episodeId)
->decrement('notes_total');
->decrement('statuses_total');
}
if ($note->actor->is_podcast) {
if ($status->actor->is_podcast) {
cache()
->deleteMatching("podcast#{$note->actor->podcast->id}*");
->deleteMatching("podcast#{$status->actor->podcast->id}*");
cache()
->deleteMatching("page_podcast#{$note->actor->podcast->id}*");
->deleteMatching("page_podcast#{$status->actor->podcast->id}*");
}
cache()
->deleteMatching("page_note#{$note->id}*");
->deleteMatching("page_status#{$status->id}*");
cache()
->deleteMatching("page_note#{$reblogNote->id}*");
->deleteMatching("page_status#{$reblogStatus->id}*");
if ($note->in_reply_to_id !== null) {
cache()->deleteMatching("page_note#{$note->in_reply_to_id}");
if ($status->in_reply_to_id !== null) {
cache()->deleteMatching("page_status#{$status->in_reply_to_id}");
}
if ($reblogNote->actor->is_podcast) {
if ($reblogStatus->actor->is_podcast) {
cache()
->deleteMatching("podcast#{$reblogNote->actor->podcast->id}*");
->deleteMatching("podcast#{$reblogStatus->actor->podcast->id}*");
cache()
->deleteMatching("page_podcast#{$reblogNote->actor->podcast->id}*");
->deleteMatching("page_podcast#{$reblogStatus->actor->podcast->id}*");
}
});
/**
* @param Note $reply
* @param Status $reply
*/
Events::on('on_note_reply', function ($reply): void {
$note = $reply->reply_to_note;
Events::on('on_status_reply', function ($reply): void {
$status = $reply->reply_to_status;
if ($note->actor->is_podcast) {
if ($status->actor->is_podcast) {
cache()
->deleteMatching("podcast#{$note->actor->podcast->id}*");
->deleteMatching("podcast#{$status->actor->podcast->id}*");
cache()
->deleteMatching("page_podcast#{$note->actor->podcast->id}*");
->deleteMatching("page_podcast#{$status->actor->podcast->id}*");
}
cache()
->deleteMatching("page_note#{$note->id}*");
->deleteMatching("page_status#{$status->id}*");
});
/**
* @param Note $reply
* @param Status $reply
*/
Events::on('on_reply_remove', function ($reply): void {
$note = $reply->reply_to_note;
$status = $reply->reply_to_status;
if ($note->actor->is_podcast) {
if ($status->actor->is_podcast) {
cache()
->deleteMatching("page_podcast#{$note->actor->podcast->id}*");
->deleteMatching("page_podcast#{$status->actor->podcast->id}*");
cache()
->deleteMatching("podcast#{$note->actor->podcast->id}*");
->deleteMatching("podcast#{$status->actor->podcast->id}*");
}
cache()
->deleteMatching("page_note#{$note->id}*");
->deleteMatching("page_status#{$status->id}*");
cache()
->deleteMatching("page_note#{$reply->id}*");
->deleteMatching("page_status#{$reply->id}*");
});
/**
* @param Actor $actor
* @param Note $note
* @param Status $status
*/
Events::on('on_note_favourite', function ($actor, $note): void {
if ($note->episode_id) {
Events::on('on_status_favourite', function ($actor, $status): void {
if ($status->episode_id) {
model('EpisodeModel')
->where('id', $note->episode_id)
->where('id', $status->episode_id)
->increment('favourites_total');
}
if ($note->actor->is_podcast) {
if ($status->actor->is_podcast) {
cache()
->deleteMatching("podcast#{$note->actor->podcast->id}*");
->deleteMatching("podcast#{$status->actor->podcast->id}*");
cache()
->deleteMatching("page_podcast#{$note->actor->podcast->id}*");
->deleteMatching("page_podcast#{$status->actor->podcast->id}*");
}
cache()
->deleteMatching("page_note#{$note->id}*");
->deleteMatching("page_status#{$status->id}*");
if ($note->in_reply_to_id !== null) {
cache()->deleteMatching("page_note#{$note->in_reply_to_id}*");
if ($status->in_reply_to_id !== null) {
cache()->deleteMatching("page_status#{$status->in_reply_to_id}*");
}
if ($actor->is_podcast) {
......@@ -321,27 +321,27 @@ Events::on('on_note_favourite', function ($actor, $note): void {
/**
* @param Actor $actor
* @param Note $note
* @param Status $status
*/
Events::on('on_note_undo_favourite', function ($actor, $note): void {
if ($note->episode_id) {
Events::on('on_status_undo_favourite', function ($actor, $status): void {
if ($status->episode_id) {
model('EpisodeModel')
->where('id', $note->episode_id)
->where('id', $status->episode_id)
->decrement('favourites_total');
}
if ($note->actor->is_podcast) {
if ($status->actor->is_podcast) {
cache()
->deleteMatching("podcast#{$note->actor->podcast->id}*");
->deleteMatching("podcast#{$status->actor->podcast->id}*");
cache()
->deleteMatching("page_podcast#{$note->actor->podcast->id}*");
->deleteMatching("page_podcast#{$status->actor->podcast->id}*");
}
cache()
->deleteMatching("page_note#{$note->id}*");
->deleteMatching("page_status#{$status->id}*");
if ($note->in_reply_to_id !== null) {
cache()->deleteMatching("page_note#{$note->in_reply_to_id}*");
if ($status->in_reply_to_id !== null) {
cache()->deleteMatching("page_status#{$status->in_reply_to_id}*");
}
if ($actor->is_podcast) {
......@@ -356,7 +356,7 @@ Events::on('on_block_actor', function (int $actorId): void {
cache()
->deleteMatching('podcast*');
cache()
->deleteMatching('page_note*');
->deleteMatching('page_status*');
});
Events::on('on_unblock_actor', function (int $actorId): void {
......@@ -364,7 +364,7 @@ Events::on('on_unblock_actor', function (int $actorId): void {
cache()
->deleteMatching('podcast*');
cache()
->deleteMatching('page_note*');
->deleteMatching('page_status*');
});
Events::on('on_block_domain', function (string $domainName): void {
......@@ -372,7 +372,7 @@ Events::on('on_block_domain', function (string $domainName): void {
cache()
->deleteMatching('podcast*');
cache()
->deleteMatching('page_note*');
->deleteMatching('page_status*');
});
Events::on('on_unblock_domain', function (string $domainName): void {
......@@ -380,5 +380,5 @@ Events::on('on_unblock_domain', function (string $domainName): void {
cache()
->deleteMatching('podcast*');
cache()
->deleteMatching('page_note*');
->deleteMatching('page_status*');
});
......@@ -35,7 +35,7 @@ $routes->addPlaceholder('podcastName', '[a-zA-Z0-9\_]{1,32}');
$routes->addPlaceholder('slug', '[a-zA-Z0-9\-]{1,191}');
$routes->addPlaceholder('base64', '[A-Za-z0-9\.\_]+\-{0,2}');
$routes->addPlaceholder('platformType', '\bpodcasting|\bsocial|\bfunding');
$routes->addPlaceholder('noteAction', '\bfavourite|\breblog|\breply');
$routes->addPlaceholder('statusAction', '\bfavourite|\breblog|\breply');
$routes->addPlaceholder('embeddablePlayerTheme', '\blight|\bdark|\blight-transparent|\bdark-transparent');
$routes->addPlaceholder(
'uuid',
......@@ -746,71 +746,71 @@ $routes->post('interact-as-actor', 'AuthController::attemptInteractAsActor', [
* Overwriting ActivityPub routes file
*/
$routes->group('@(:podcastName)', function ($routes): void {
$routes->post('notes/new', 'NoteController::attemptCreate/$1', [
'as' => 'note-attempt-create',
$routes->post('statuses/new', 'StatusController::attemptCreate/$1', [
'as' => 'status-attempt-create',
'filter' => 'permission:podcast-manage_publications',
]);
// Note
$routes->group('notes/(:uuid)', function ($routes): void {
$routes->get('/', 'NoteController::view/$1/$2', [
'as' => 'note',
// Status
$routes->group('statuses/(:uuid)', function ($routes): void {
$routes->get('/', 'StatusController::view/$1/$2', [
'as' => 'status',
'alternate-content' => [
'application/activity+json' => [
'namespace' => 'ActivityPub\Controllers',
'controller-method' => 'NoteController/$2',
'controller-method' => 'StatusController/$2',
],
'application/ld+json; profile="https://www.w3.org/ns/activitystreams' => [
'namespace' => 'ActivityPub\Controllers',
'controller-method' => 'NoteController/$2',
'controller-method' => 'StatusController/$2',
],
],
]);
$routes->get('replies', 'NoteController/$1/$2', [
'as' => 'note-replies',
$routes->get('replies', 'StatusController/$1/$2', [
'as' => 'status-replies',
'alternate-content' => [
'application/activity+json' => [
'namespace' => 'ActivityPub\Controllers',
'controller-method' => 'NoteController::replies/$2',
'controller-method' => 'StatusController::replies/$2',
],
'application/ld+json; profile="https://www.w3.org/ns/activitystreams' => [
'namespace' => 'ActivityPub\Controllers',
'controller-method' => 'NoteController::replies/$2',
'controller-method' => 'StatusController::replies/$2',
],
],
]);
// Actions
$routes->post('action', 'NoteController::attemptAction/$1/$2', [
'as' => 'note-attempt-action',
$routes->post('action', 'StatusController::attemptAction/$1/$2', [
'as' => 'status-attempt-action',
'filter' => 'permission:podcast-interact_as',
]);
$routes->post(
'block-actor',
'NoteController::attemptBlockActor/$1/$2',
'StatusController::attemptBlockActor/$1/$2',
[
'as' => 'note-attempt-block-actor',
'as' => 'status-attempt-block-actor',
'filter' => 'permission:fediverse-block_actors',
],
);
$routes->post(
'block-domain',
'NoteController::attemptBlockDomain/$1/$2',
'StatusController::attemptBlockDomain/$1/$2',
[
'as' => 'note-attempt-block-domain',
'as' => 'status-attempt-block-domain',
'filter' => 'permission:fediverse-block_domains',
],
);
$routes->post('delete', 'NoteController::attemptDelete/$1/$2', [
'as' => 'note-attempt-delete',
$routes->post('delete', 'StatusController::attemptDelete/$1/$2', [
'as' => 'status-attempt-delete',
'filter' => 'permission:podcast-manage_publications',
]);
$routes->get(
'remote/(:noteAction)',
'NoteController::remoteAction/$1/$2/$3',
'remote/(:statusAction)',
'StatusController::remoteAction/$1/$2/$3',
[
'as' => 'note-remote-action',
'as' => 'status-remote-action',
],
);
});
......
......@@ -13,12 +13,12 @@ namespace App\Controllers\Admin;
use App\Entities\Episode;
use App\Entities\Image;
use App\Entities\Location;
use App\Entities\Note;
use App\Entities\Podcast;
use App\Entities\Status;
use App\Models\EpisodeModel;
use App\Models\NoteModel;
use App\Models\PodcastModel;
use App\Models\SoundbiteModel;
use App\Models\StatusModel;
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\I18n\Time;
......@@ -426,7 +426,7 @@ class EpisodeController extends BaseController
$db = db_connect();
$db->transStart();
$newNote = new Note([
$newStatus = new Status([
'actor_id' => $this->podcast->actor_id,
'episode_id' => $this->episode->id,
'message' => $this->request->getPost('message'),
......@@ -453,15 +453,15 @@ class EpisodeController extends BaseController
$this->episode->published_at = Time::now();
}
$newNote->published_at = $this->episode->published_at;
$newStatus->published_at = $this->episode->published_at;
$noteModel = new NoteModel();
if (! $noteModel->addNote($newNote)) {
$statusModel = new StatusModel();
if (! $statusModel->addStatus($newStatus)) {
$db->transRollback();
return redirect()
->back()
->withInput()
->with('errors', $noteModel->errors());
->with('errors', $statusModel->errors());
}
$episodeModel = new EpisodeModel();
......@@ -486,7 +486,7 @@ class EpisodeController extends BaseController
$data = [
'podcast' => $this->podcast,
'episode' => $this->episode,
'note' => (new NoteModel())
'status' => (new StatusModel())
->where([
'actor_id' => $this->podcast->actor_id,
'episode_id' => $this->episode->id,
......@@ -506,7 +506,7 @@ class EpisodeController extends BaseController
public function attemptPublishEdit(): RedirectResponse
{
$rules = [
'note_id' => 'required',
'status_id' => 'required',
'publication_method' => 'required',
'scheduled_publication_date' =>
'valid_date[Y-m-d H:i]|permit_empty',
......@@ -542,19 +542,19 @@ class EpisodeController extends BaseController
$this->episode->published_at = Time::now();
}
$note = (new NoteModel())->getNoteById($this->request->getPost('note_id'));
$status = (new StatusModel())->getStatusById($this->request->getPost('status_id'));
if ($note !== null) {
$note->message = $this->request->getPost('message');
$note->published_at = $this->episode->published_at;
if ($status !== null) {
$status->message = $this->request->getPost('message');
$status->published_at = $this->episode->published_at;
$noteModel = new NoteModel();
if (! $noteModel->editNote($note)) {
$statusModel = new StatusModel();
if (! $statusModel->editStatus($status)) {
$db->transRollback();
return redirect()
->back()
->withInput()
->with('errors', $noteModel->errors());
->with('errors', $statusModel->errors());
}
}
......@@ -609,13 +609,13 @@ class EpisodeController extends BaseController
$db->transStart();
$allNotesLinkedToEpisode = (new NoteModel())
$allStatusesLinkedToEpisode = (new StatusModel())
->where([
'episode_id' => $this->episode->id,
])
->findAll();
foreach ($allNotesLinkedToEpisode as $note) {
(new NoteModel())->removeNote($note);
foreach ($allStatusesLinkedToEpisode as $status) {
(new StatusModel())->removeStatus($status);
}
// set episode published_at to null to unpublish
......
......@@ -13,8 +13,8 @@ namespace App\Controllers;
use Analytics\AnalyticsTrait;
use App\Entities\Podcast;
use App\Models\EpisodeModel;
use App\Models\NoteModel;
use App\Models\PodcastModel;
use App\Models\StatusModel;
use CodeIgniter\Exceptions\PageNotFoundException;
class PodcastController extends BaseController
......@@ -64,7 +64,7 @@ class PodcastController extends BaseController
if (! ($cachedView = cache($cacheName))) {
$data = [
'podcast' => $this->podcast,
'notes' => (new NoteModel())->getActorPublishedNotes($this->podcast->actor_id),
'statuses' => (new StatusModel())->getActorPublishedStatuses($this->podcast->actor_id),
];
// if user is logged in then send to the authenticated activity view
......
......@@ -10,21 +10,21 @@ declare(strict_types=1);
namespace App\Controllers;
use ActivityPub\Controllers\NoteController as ActivityPubNoteController;
use ActivityPub\Entities\Note as ActivityPubNote;
use ActivityPub\Controllers\StatusController as ActivityPubStatusController;
use ActivityPub\Entities\Status as ActivityPubStatus;
use Analytics\AnalyticsTrait;
use App\Entities\Actor;
use App\Entities\Note as CastopodNote;
use App\Entities\Podcast;
use App\Entities\Status as CastopodStatus;
use App\Models\EpisodeModel;
use App\Models\NoteModel;
use App\Models\PodcastModel;
use App\Models\StatusModel;
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\URI;
use CodeIgniter\I18n\Time;
class NoteController extends ActivityPubNoteController
class StatusController extends ActivityPubStatusController
{