<?php
require_once __DIR__ . '/config.php';
$me = must_auth();
$b  = json_decode(file_get_contents('php://input'),true) ?: array();
$id   = isset($b['id'])   ? (int)$b['id']    : 0;
$star = !empty($b['star']);
if (!$id) fail('Missing id');
db()->prepare("UPDATE messages SET starred=? WHERE id=? AND (from_user=? OR to_user=?)")->execute(array($star?1:0,$id,$me,$me));
ok();
