25 lines
844 B
PHP
25 lines
844 B
PHP
<?php
|
|
// /messages/api/archive_conversation.php
|
|
declare(strict_types=1);
|
|
require_once __DIR__ . '/../_bootstrap.php';
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
if (!hash_equals($_SESSION['_csrf'] ?? '', $_POST['_csrf'] ?? '')) {
|
|
json_response(['error' => 'csrf'], 419);
|
|
}
|
|
|
|
$role = $GLOBALS['MESSAGES_CTX']['role'];
|
|
$meId = $GLOBALS['MESSAGES_CTX']['me_id'];
|
|
$convId = (int)($_POST['conversation_id'] ?? 0);
|
|
$archive= (int)($_POST['archive'] ?? 1);
|
|
|
|
if ($convId <= 0) json_response(['error' => 'bad_params'], 400);
|
|
|
|
assert_conversation_access($pdo, $convId, $role, $meId);
|
|
|
|
$col = ($role === 'praticien') ? 'archived_by_praticien' : 'archived_by_client';
|
|
$pdo->prepare("UPDATE conversations SET $col = ? WHERE id = ?")->execute([$archive ? 1 : 0, $convId]);
|
|
|
|
json_response(['ok' => true, 'archived' => (bool)$archive]);
|