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="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="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 ###
|
||||
|
||||
###> symfony/messenger ###
|
||||
|
@ -20,7 +20,7 @@ final class MessageController extends AbstractController
|
||||
public function index(MessageRepository $messageRepository): Response
|
||||
{
|
||||
$user = $this->getUser();
|
||||
$messages = $messageRepository->findByUser($user);
|
||||
$messages = $messageRepository->findLatestMessagesByUser($user);
|
||||
|
||||
return $this->render('message/index.html.twig', [
|
||||
'messages' => $messages,
|
||||
|
@ -37,4 +37,30 @@ class MessageRepository extends ServiceEntityRepository
|
||||
->getQuery()
|
||||
->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,11 +17,17 @@
|
||||
<!-- Liste des messages reçus -->
|
||||
<div class="max-w-4xl mx-auto">
|
||||
{% 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="flex justify-between items-center">
|
||||
<div>
|
||||
<h2 class="text-xl font-semibold">De : {{ message.sender.nickname }}</h2>
|
||||
<h2 class="text-xl font-semibold">
|
||||
De :
|
||||
{% if message.sender == app.user %}
|
||||
{{ message.receiver.nickname }}
|
||||
{% else %}
|
||||
{{ message.sender.nickname }}
|
||||
{% endif %}
|
||||
</h2>
|
||||
<p class="text-gray-600">{{ message.sendingDate|date('d/m/Y H:i') }}</p>
|
||||
</div>
|
||||
<a href="{{ path('app_message_conversation', { id: message.id }) }}" class="bg-teal-500 text-white px-4 py-2 rounded hover:bg-teal-600">
|
||||
@ -30,7 +36,6 @@
|
||||
</div>
|
||||
<p class="mt-4 text-gray-700">{{ message.content }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<p class="text-center text-gray-500">Vous n'avez reçu aucun message.</p>
|
||||
{% endfor %}
|
||||
|
Loading…
Reference in New Issue
Block a user