diff --git a/resources/views/chat/show.blade.php b/resources/views/chat/show.blade.php
index 8be53aef..72df13c2 100644
--- a/resources/views/chat/show.blade.php
+++ b/resources/views/chat/show.blade.php
@@ -107,33 +107,50 @@ document.getElementById('chat-form').addEventListener('submit', function(e) {
const data = new FormData(form);
axios.post('{{ route("chat.send") }}', data, {
- headers: {
- 'X-Socket-ID': window.Echo.socketId()
- }
-})
- .then(response => {
- appendMessage({
- body: response.data.body,
- created_at: response.data.created_at,
- }, true);
+ headers: { 'X-Socket-ID': window.Echo.socketId() }
+ }).then(response => {
+ appendMessage(response.data, true);
scrollBottom();
form.reset();
document.getElementById('attachment-preview').textContent = '';
});
});
+function buildAttachmentHtml(msg, isMine) {
+ if (!msg.attachment) return '';
+ const url = '/storage/' + msg.attachment;
+ const linkClass = isMine ? 'text-white' : 'text-dark';
+ switch (msg.attachment_type) {
+ case 'image':
+ return ``;
+ case 'video':
+ return ``;
+ case 'audio':
+ return ``;
+ default:
+ return `
+ Ver archivo
+ `;
+ }
+}
+
function appendMessage(msg, isMine) {
const div = document.createElement('div');
div.className = `d-flex mb-2 ${isMine ? 'justify-content-end' : 'justify-content-start'}`;
- // formatear hora
- const time = msg.created_at.length > 5
+ const time = typeof msg.created_at === 'string' && msg.created_at.length > 5
? new Date(msg.created_at).toLocaleTimeString('es-MX', {hour:'2-digit', minute:'2-digit'})
: msg.created_at;
div.innerHTML = `