forked from GNUsocial/gnu-social
[PLUGIN][Repeat] onAppendCardNote added. getNoteRepeats implemented.
This commit is contained in:
@@ -34,6 +34,8 @@ use App\Util\Exception\InvalidFormException;
|
||||
use App\Util\Exception\NoSuchNoteException;
|
||||
use App\Util\Exception\NotFoundException;
|
||||
use App\Util\Exception\RedirectException;
|
||||
use App\Util\Formatting;
|
||||
use Plugin\Repeat\Entity\NoteRepeat;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class Repeat extends NoteHandlerPlugin
|
||||
@@ -64,7 +66,7 @@ class Repeat extends NoteHandlerPlugin
|
||||
} catch (NotFoundException $e) {
|
||||
}
|
||||
|
||||
$is_repeat = DB::count('note_repeat', ['id' => $note->getId()]) >= 1;
|
||||
$is_repeat = DB::count('note_repeat', ['note_id' => $note->getId()]) >= 1;
|
||||
|
||||
// Generating URL for repeat action route
|
||||
$args = ['id' => $note->getId()];
|
||||
@@ -93,10 +95,44 @@ class Repeat extends NoteHandlerPlugin
|
||||
public function onAppendCardNote(array $vars, array &$result) {
|
||||
// if note is the original and user isn't the one who repeated, append on end "user repeated this"
|
||||
// if user is the one who repeated, append on end "you repeated this, remove repeat?"
|
||||
$actor = $vars['actor'];
|
||||
$current_actor_id = (Common::actor())->getId();
|
||||
$note = $vars['note'];
|
||||
|
||||
return Event::next;
|
||||
$complementary_info = '';
|
||||
$repeat_actor = [];
|
||||
$note_repeats = NoteRepeat::getNoteRepeats($note);
|
||||
|
||||
// Get actors who replied
|
||||
foreach ($note_repeats as $reply) {
|
||||
$repeat_actor[] = Actor::getWithPK($reply->getActorId());
|
||||
}
|
||||
if (count($repeat_actor) < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Filter out multiple replies from the same actor
|
||||
$repeat_actor = array_unique($repeat_actor, SORT_REGULAR);
|
||||
|
||||
// Add to complementary info
|
||||
foreach ($repeat_actor as $actor) {
|
||||
$repeat_actor_url = $actor->getUrl();
|
||||
$repeat_actor_nickname = $actor->getNickname();
|
||||
|
||||
if ($actor->getId() === $current_actor_id) {
|
||||
// If the repeat is yours
|
||||
$prepend = "<a href={$repeat_actor_url}>You</a>, " . ($prepend = &$complementary_info);
|
||||
$complementary_info = $prepend;
|
||||
} else {
|
||||
// If the repeat is from someone else
|
||||
$complementary_info .= "<a href={$repeat_actor_url}>{$repeat_actor_nickname}</a>, ";
|
||||
}
|
||||
}
|
||||
|
||||
$complementary_info = rtrim(trim($complementary_info), ',');
|
||||
$complementary_info .= ' repeated this note.';
|
||||
$result[] = Formatting::twigRenderString($complementary_info, []);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function onAddRoute(RouteLoader $r): bool
|
||||
|
Reference in New Issue
Block a user