From d9e4bf3cac29971c56e5b2ef6361b4a5d430b4b0 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Mon, 6 Jun 2022 16:07:03 +0200 Subject: [PATCH] Unified message display, scroll to newest after sending or deleting --- .../views/pages/messages/conversation.twig | 38 +++++++------------ src/Controllers/MessagesController.php | 4 +- .../Controllers/MessagesControllerTest.php | 6 +-- 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/resources/views/pages/messages/conversation.twig b/resources/views/pages/messages/conversation.twig index 7e1bcb40..d9eb03c9 100644 --- a/resources/views/pages/messages/conversation.twig +++ b/resources/views/pages/messages/conversation.twig @@ -16,38 +16,28 @@
{% for msg in messages %} - {% if msg.user_id == user.id %} -
-
-
-

{{ msg.text | nl2br }}

-
+ {% set own_message = msg.user_id == user.id %} +
+
+
+

{{ msg.text | nl2br }}

+
+ {{ msg.created_at.format(__('Y-m-d H:i')) }} + {% if own_message %}
{{ csrf() }} - {{ msg.created_at.format(__('Y-m-d H:i')) }} {{ f.submit(m.icon('trash'), {'btn_type': 'primary', 'size': 'sm'}) }}
-
-
-
-
- {% else %} -
-
-
-
{{ msg.text | nl2br }}
-
- {{ msg.created_at.format(__('Y-m-d H:i')) }} -
- {% if msg.read == false %} - {% endif %}
+ {% if not own_message and msg.read == false %} + + {% endif %}
- {% endif %} +
{% endfor %}
@@ -56,7 +46,7 @@
- + {{ f.submit(m.icon('send-fill')) }}
diff --git a/src/Controllers/MessagesController.php b/src/Controllers/MessagesController.php index 9be1ebab..3c6db84c 100644 --- a/src/Controllers/MessagesController.php +++ b/src/Controllers/MessagesController.php @@ -179,7 +179,7 @@ class MessagesController extends BaseController $newMessage->read = $otherUser->id == $currentUser->id; // if its to myself, I obviously read it. $newMessage->save(); - return $this->redirect->to('/messages/' . $otherUser->id); + return $this->redirect->to('/messages/' . $otherUser->id . '#newest'); } /** @@ -199,7 +199,7 @@ class MessagesController extends BaseController throw new HttpForbidden('You can not delete a message you haven\'t send'); } - return $this->redirect->to('/messages/' . $otherUserId); + return $this->redirect->to('/messages/' . $otherUserId . '#newest'); } /** diff --git a/tests/Unit/Controllers/MessagesControllerTest.php b/tests/Unit/Controllers/MessagesControllerTest.php index 81243b03..cca8ed96 100644 --- a/tests/Unit/Controllers/MessagesControllerTest.php +++ b/tests/Unit/Controllers/MessagesControllerTest.php @@ -443,7 +443,7 @@ class MessagesControllerTest extends ControllerTest $this->response->expects($this->once()) ->method('redirectTo') - ->with('http://localhost/messages/' . $this->userB->id) + ->with('http://localhost/messages/' . $this->userB->id . '#newest') ->willReturn($this->response); $this->controller->send($this->request); @@ -465,7 +465,7 @@ class MessagesControllerTest extends ControllerTest $this->response->expects($this->once()) ->method('redirectTo') - ->with('http://localhost/messages/' . $this->userA->id) + ->with('http://localhost/messages/' . $this->userA->id . '#newest') ->willReturn($this->response); $this->controller->send($this->request); @@ -511,7 +511,7 @@ class MessagesControllerTest extends ControllerTest $this->response->expects($this->once()) ->method('redirectTo') - ->with('http://localhost/messages/1') + ->with('http://localhost/messages/1#newest') ->willReturn($this->response); $this->controller->delete($this->request);