up
This commit is contained in:
+138
-3
@@ -904,6 +904,10 @@ if (!isset($_SESSION['user_id'])) {
|
||||
<div id="bot-toggle-container" style="display:flex;align-items:center;gap:6px;margin-right:8px;">
|
||||
<button class="btn btn-sm btn-outline-secondary" id="bot-toggle">Bot: On</button>
|
||||
</div>
|
||||
<!-- Botón solicitar archivo grande -->
|
||||
<button class="btn btn-sm btn-outline-info" id="request-large-file-btn" title="Solicitar archivo grande al cliente">
|
||||
<i class="fas fa-cloud-upload-alt"></i>
|
||||
</button>
|
||||
<!-- Botón programar recordatorio -->
|
||||
<button class="btn btn-sm btn-success" id="schedule-reminder-btn" title="Programar recordatorio">
|
||||
<i class="fas fa-calendar-plus"></i>
|
||||
@@ -947,8 +951,10 @@ if (!isset($_SESSION['user_id'])) {
|
||||
📎
|
||||
</button>
|
||||
<div id="attach-menu" class="attach-menu" style="display:none;">
|
||||
<button class="attach-option" data-action="file">Enviar archivo</button>
|
||||
<button class="attach-option" data-action="template">Enviar plantilla</button>
|
||||
<button class="attach-option" data-action="file"><i class="fas fa-file me-2"></i>Enviar archivo</button>
|
||||
<button class="attach-option" data-action="template"><i class="fas fa-file-alt me-2"></i>Enviar plantilla</button>
|
||||
<hr style="margin:4px 0; border-color:#eee;">
|
||||
<button class="attach-option" data-action="large-file" style="color:#075e54; font-weight:600;"><i class="fas fa-cloud-upload-alt me-2"></i>Solicitar archivo grande</button>
|
||||
</div>
|
||||
<div style="display:flex; gap:8px; align-items:center;">
|
||||
<!-- <select id="message-type" class="form-select form-select-sm" style="width:auto; margin-right:8px;">
|
||||
@@ -1580,7 +1586,9 @@ if (!isset($_SESSION['user_id'])) {
|
||||
// explicit attention flags
|
||||
notification.type === 'attention' || notification.system === 'attention' || notification.level === 'attention' || notification.attention ||
|
||||
// known event types/tags for user-sent documents
|
||||
notification.type === 'usersentdocuments' || notification.tag === 'usersentdocuments' || notification.system === 'usersentdocuments'
|
||||
notification.type === 'usersentdocuments' || notification.tag === 'usersentdocuments' || notification.system === 'usersentdocuments' ||
|
||||
// file upload notifications (large file request feature)
|
||||
notification.type === 'file_uploaded' || notification.type === 'file_request_sent'
|
||||
);
|
||||
if (notification.cool || notification.type === 'cool') toast.classList.add('cool');
|
||||
if (notification.level === 'urgent' || notification.urgent) toast.classList.add('urgent');
|
||||
@@ -2078,6 +2086,8 @@ if (!isset($_SESSION['user_id'])) {
|
||||
attachMenu.style.display = 'none';
|
||||
if (action === 'file') {
|
||||
if (fileInput) fileInput.click();
|
||||
} else if (action === 'large-file') {
|
||||
self.requestLargeFile();
|
||||
} else if (action === 'template') {
|
||||
// switch to template mode and focus selector
|
||||
const typeSelect = document.getElementById('message-type');
|
||||
@@ -2271,6 +2281,12 @@ if (!isset($_SESSION['user_id'])) {
|
||||
if (reminderBtn) {
|
||||
reminderBtn.addEventListener('click', () => this.showReminderModal());
|
||||
}
|
||||
|
||||
// Botón solicitar archivo grande (header)
|
||||
const requestLargeFileBtn = document.getElementById('request-large-file-btn');
|
||||
if (requestLargeFileBtn) {
|
||||
requestLargeFileBtn.addEventListener('click', () => this.requestLargeFile());
|
||||
}
|
||||
|
||||
// Botón de guardar recordatorio
|
||||
const saveReminderBtn = document.getElementById('save-reminder-btn');
|
||||
@@ -5360,6 +5376,125 @@ if (!isset($_SESSION['user_id'])) {
|
||||
}
|
||||
}
|
||||
|
||||
async deleteCurrentConversation() {
|
||||
if (!confirm('¿Eliminar esta conversación? Se borrará todo el historial.')) return;
|
||||
try {
|
||||
const resp = await fetch('api/delete_conversation.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ user_id: this.currentUserId }),
|
||||
cache: 'no-store'
|
||||
});
|
||||
const json = await resp.json();
|
||||
if (json && json.success) {
|
||||
this.showSuccess('Conversación eliminada');
|
||||
// reset UI
|
||||
document.getElementById('chat-area').style.display = 'none';
|
||||
document.getElementById('no-conversation').style.display = 'block';
|
||||
this.currentUserId = null;
|
||||
this.loadConversations();
|
||||
} else {
|
||||
this.showError('No se pudo eliminar la conversación');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
this.showError('Error eliminando la conversación');
|
||||
}
|
||||
}
|
||||
|
||||
// ========== SOLICITAR ARCHIVO GRANDE ==========
|
||||
|
||||
async requestLargeFile() {
|
||||
if (!this.currentUserId) {
|
||||
showAlert('Selecciona una conversación primero', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
const phoneNumber = this.getConversationPhone(this.currentUserId);
|
||||
if (!phoneNumber) {
|
||||
showAlert('No se encontró el número de teléfono del cliente', 'danger');
|
||||
return;
|
||||
}
|
||||
|
||||
// Confirmar con el operador
|
||||
const userName = document.getElementById('chat-name-text')?.textContent?.trim() || phoneNumber;
|
||||
if (!confirm(`¿Enviar enlace de carga de archivos grandes a ${userName}?\n\nSe enviará un mensaje por WhatsApp con un enlace seguro donde el cliente podrá subir archivos de hasta 50 MB.`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Deshabilitar botones mientras se procesa
|
||||
const headerBtn = document.getElementById('request-large-file-btn');
|
||||
if (headerBtn) {
|
||||
headerBtn.disabled = true;
|
||||
headerBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i>';
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('api/request_large_file.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify({
|
||||
user_id: this.currentUserId,
|
||||
phone_number: phoneNumber,
|
||||
}),
|
||||
cache: 'no-store',
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result && result.success) {
|
||||
showAlert('✅ Enlace de carga enviado al cliente por WhatsApp', 'success');
|
||||
console.log('📎 File request created:', result);
|
||||
|
||||
// Agregar mensaje visual al chat con texto más detallado
|
||||
this.addMessageToView(
|
||||
`📎 Enlace para enviar archivos grandes\n\n` +
|
||||
`Hola.\n\n` +
|
||||
`Le enviamos este enlace seguro para que pueda subir archivos de gran tamaño (hasta 50 MB):\n\n` +
|
||||
`👉 ${result.upload_url}\n\n` +
|
||||
`✅ Puede subir imágenes o documentos.\n` +
|
||||
`🔒 El enlace es seguro y exclusivo para usted.\n` +
|
||||
`⏰ Válido por 24 horas.\n\n` +
|
||||
`Si tiene alguna duda, estamos aquí para ayudarle.`,
|
||||
'outgoing',
|
||||
{ message_type: 'text' }
|
||||
);
|
||||
|
||||
// Recargar mensajes después de un breve delay
|
||||
setTimeout(() => {
|
||||
this.loadMessages(this.currentUserId, false, true);
|
||||
}, 2000);
|
||||
|
||||
} else {
|
||||
showAlert('Error: ' + (result.error || 'No se pudo enviar el enlace'), 'danger');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error en requestLargeFile:', error);
|
||||
showAlert('Error al enviar la solicitud: ' + (error.message || error), 'danger');
|
||||
} finally {
|
||||
if (headerBtn) {
|
||||
headerBtn.disabled = false;
|
||||
headerBtn.innerHTML = '<i class="fas fa-cloud-upload-alt"></i>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async getFileRequests() {
|
||||
if (!this.currentUserId) return [];
|
||||
try {
|
||||
const resp = await fetch(`api/get_file_requests.php?user_id=${this.currentUserId}&status=active`, {
|
||||
credentials: 'same-origin',
|
||||
cache: 'no-store',
|
||||
});
|
||||
const data = await resp.json();
|
||||
return data.success ? (data.uploads || []) : [];
|
||||
} catch (e) {
|
||||
console.warn('Error loading file requests:', e);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async searchConversations(query) {
|
||||
console.log('🔍 Buscando conversaciones:', query);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user