Unified message display, scroll to newest after sending or deleting
This commit is contained in:
parent
9e5f0ff854
commit
d9e4bf3cac
|
@ -16,38 +16,28 @@
|
|||
<div class="col-12 col-lg-8 offset-lg-2">
|
||||
<div class="row conversation">
|
||||
{% for msg in messages %}
|
||||
{% if msg.user_id == user.id %}
|
||||
<div class="col-12"{% if loop.last %} id="newest"{% endif %}>
|
||||
<div class="d-flex justify-content-end">
|
||||
<div class="message alert alert-primary">
|
||||
<p>{{ msg.text | nl2br }}</p>
|
||||
<div class="text-end">
|
||||
{% set own_message = msg.user_id == user.id %}
|
||||
<div class="col-12"{% if loop.last %} id="newest"{% endif %}>
|
||||
<div class="d-flex{% if own_message %} justify-content-end{% endif %}">
|
||||
<div class="message alert {% if own_message %}alert-primary{% else %}alert-secondary{% endif %}">
|
||||
<p>{{ msg.text | nl2br }}</p>
|
||||
<div class="text-end">
|
||||
<small class="opacity-75">{{ msg.created_at.format(__('Y-m-d H:i')) }}</small>
|
||||
{% if own_message %}
|
||||
<form action="{{ url('/messages/' ~ other_user.id ~ '/' ~ msg.id) }}"
|
||||
enctype="multipart/form-data" method="post"
|
||||
enctype="multipart/form-data" method="post" class="float-end"
|
||||
>
|
||||
{{ csrf() }}
|
||||
<small class="opacity-75">{{ msg.created_at.format(__('Y-m-d H:i')) }}</small>
|
||||
{{ f.submit(m.icon('trash'), {'btn_type': 'primary', 'size': 'sm'}) }}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="col-12"{% if loop.last %} id="newest"{% endif %}>
|
||||
<div>
|
||||
<div class="message alert alert-secondary position-relative">
|
||||
<div>{{ msg.text | nl2br }}</div>
|
||||
<div class="text-end">
|
||||
<small class="opacity-75">{{ msg.created_at.format(__('Y-m-d H:i')) }}</small>
|
||||
</div>
|
||||
{% if msg.read == false %}
|
||||
<span class="position-absolute top-0 start-100 translate-middle-x p-2 bg-danger rounded-circle"></span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if not own_message and msg.read == false %}
|
||||
<span class="position-absolute top-0 start-100 translate-middle-x p-2 bg-danger rounded-circle"></span>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
|
@ -56,7 +46,7 @@
|
|||
|
||||
<div class="input-group">
|
||||
<label for="message" class="visually-hidden">{{ __('message.message') }}</label>
|
||||
<textarea class="form-control" id="message" name="text" required="" rows="2"></textarea>
|
||||
<textarea class="form-control" id="message" name="text" required="" rows="3"></textarea>
|
||||
{{ f.submit(m.icon('send-fill')) }}
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue