๐ Source: get_chats.php
<?php
session_name('INBOXZERO');
session_start();
header('Content-Type: application/json');
// Cache รฎn sesiune pentru 5 secunde
if (isset($_SESSION['chats_cache']) && isset($_SESSION['chats_cache_time']) && (time() - $_SESSION['chats_cache_time']) < 5) {
echo $_SESSION['chats_cache'];
exit();
}
$chats = [];
if (isset($_SESSION['chat_histories'])) {
foreach ($_SESSION['chat_histories'] as $id => $history) {
if (isset($_SESSION['chat_titles'][$id])) {
$title = $_SESSION['chat_titles'][$id];
} else {
$title = 'New Chat';
foreach ($history as $msg) {
if (strpos($msg, 'User:') === 0) {
$content = substr($msg, 6);
$title = strlen($content) > 25 ? substr($content, 0, 25) . '...' : $content;
break;
}
}
}
$chats[] = ['id' => $id, 'title' => $title];
}
}
$chats = array_reverse($chats);
$output = json_encode($chats);
// Salveazฤ รฎn cache
$_SESSION['chats_cache'] = $output;
$_SESSION['chats_cache_time'] = time();
echo $output;
?>
โ Back