2022-07-21 16:15:47 +02:00
|
|
|
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
use Symfony\Component\Mercure\HubInterface;
|
|
|
|
use Symfony\Component\Mercure\Update;
|
|
|
|
|
|
|
|
class PublishController extends AbstractController
|
|
|
|
{
|
2022-07-25 17:16:08 +02:00
|
|
|
public function sample($id){
|
|
|
|
return $this->render('Home/publishsample.html.twig',[
|
|
|
|
'id'=>$id
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
public function publish($channel, $id, Request $request, HubInterface $hub): Response
|
|
|
|
{
|
|
|
|
$ret=$request->get("msg");
|
|
|
|
$ret["from"]=[];
|
2022-07-25 17:16:08 +02:00
|
|
|
$ret["from"]["id"]=$this->getUser()->getId();
|
|
|
|
$ret["from"]["username"]=$this->getUser()->getUsername();
|
|
|
|
$ret["from"]["displayname"]=$this->getUser()->getDisplayname();
|
|
|
|
|
|
|
|
|
|
|
|
if(stripos($this->getUser()->getAvatar(),"http")===0)
|
|
|
|
$ret["from"]["avatar"]=$this->getUser()->getAvatar();
|
|
|
|
else
|
|
|
|
$ret["from"]["avatar"]=$this->getParameter('appAlias')."uploads/avatar/".$this->getUser()->getAvatar();
|
|
|
|
|
2022-07-21 16:15:47 +02:00
|
|
|
$update = new Update(
|
|
|
|
$channel."-".$id,
|
|
|
|
json_encode(
|
|
|
|
['ret' => $ret])
|
|
|
|
);
|
|
|
|
|
|
|
|
$hub->publish($update);
|
|
|
|
|
|
|
|
return new Response('published!');
|
|
|
|
}
|
|
|
|
}
|