Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
1eb8418cff | |||
6deb9b30cd | |||
3902207427 |
2
.env
2
.env
@ -26,7 +26,7 @@ APP_SECRET=f024eb6ed2c61908ec7842f29b9a6334
|
|||||||
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
|
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
|
||||||
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4"
|
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4"
|
||||||
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
|
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
|
||||||
DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
|
DATABASE_URL="postgresql://allavenavr:Btssio2024@172.20.96.1:5432/hegresphere?serverVersion=16&charset=utf8"
|
||||||
###< doctrine/doctrine-bundle ###
|
###< doctrine/doctrine-bundle ###
|
||||||
|
|
||||||
###> symfony/messenger ###
|
###> symfony/messenger ###
|
||||||
|
@ -20,7 +20,7 @@ final class MessageController extends AbstractController
|
|||||||
public function index(MessageRepository $messageRepository): Response
|
public function index(MessageRepository $messageRepository): Response
|
||||||
{
|
{
|
||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
$messages = $messageRepository->findByUser($user);
|
$messages = $messageRepository->findLatestMessagesByUser($user);
|
||||||
|
|
||||||
return $this->render('message/index.html.twig', [
|
return $this->render('message/index.html.twig', [
|
||||||
'messages' => $messages,
|
'messages' => $messages,
|
||||||
|
@ -37,4 +37,30 @@ class MessageRepository extends ServiceEntityRepository
|
|||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findLatestMessagesByUser(UserApp $user): array
|
||||||
|
{
|
||||||
|
$query = $this->createQueryBuilder('m')
|
||||||
|
->where('m.sender = :user OR m.receiver = :user')
|
||||||
|
->setParameter('user', $user)
|
||||||
|
->orderBy('m.sendingDate', 'DESC')
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
$lastMessages = [];
|
||||||
|
foreach ($query as $message) {
|
||||||
|
// Identifier l'autre utilisateur dans la conversation
|
||||||
|
$otherUser = $message->getSender() === $user ? $message->getReceiver() : $message->getSender();
|
||||||
|
$key = $otherUser->getId();
|
||||||
|
|
||||||
|
// Conserver uniquement le dernier message avec cet utilisateur
|
||||||
|
if (!isset($lastMessages[$key])) {
|
||||||
|
$lastMessages[$key] = $message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $lastMessages;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,20 +17,25 @@
|
|||||||
<!-- Liste des messages reçus -->
|
<!-- Liste des messages reçus -->
|
||||||
<div class="max-w-4xl mx-auto">
|
<div class="max-w-4xl mx-auto">
|
||||||
{% for message in messages %}
|
{% for message in messages %}
|
||||||
{% if message.receiver == app.user or message.sender == app.user %}
|
<div class="bg-white p-6 rounded-lg shadow mb-4">
|
||||||
<div class="bg-white p-6 rounded-lg shadow mb-4">
|
<div class="flex justify-between items-center">
|
||||||
<div class="flex justify-between items-center">
|
<div>
|
||||||
<div>
|
<h2 class="text-xl font-semibold">
|
||||||
<h2 class="text-xl font-semibold">De : {{ message.sender.nickname }}</h2>
|
De :
|
||||||
<p class="text-gray-600">{{ message.sendingDate|date('d/m/Y H:i') }}</p>
|
{% if message.sender == app.user %}
|
||||||
</div>
|
{{ message.receiver.nickname }}
|
||||||
<a href="{{ path('app_message_conversation', { id: message.id }) }}" class="bg-teal-500 text-white px-4 py-2 rounded hover:bg-teal-600">
|
{% else %}
|
||||||
Voir la Conversation
|
{{ message.sender.nickname }}
|
||||||
</a>
|
{% endif %}
|
||||||
|
</h2>
|
||||||
|
<p class="text-gray-600">{{ message.sendingDate|date('d/m/Y H:i') }}</p>
|
||||||
</div>
|
</div>
|
||||||
<p class="mt-4 text-gray-700">{{ message.content }}</p>
|
<a href="{{ path('app_message_conversation', { id: message.id }) }}" class="bg-teal-500 text-white px-4 py-2 rounded hover:bg-teal-600">
|
||||||
|
Voir la Conversation
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
<p class="mt-4 text-gray-700">{{ message.content }}</p>
|
||||||
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p class="text-center text-gray-500">Vous n'avez reçu aucun message.</p>
|
<p class="text-center text-gray-500">Vous n'avez reçu aucun message.</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
Loading…
Reference in New Issue
Block a user