", ...]}. One per emoji per device. $reactEmoji = ['👍', '❤️', '😂']; // Handle a click (a plain POST, so it works with or without JavaScript). if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['chat_action'] ?? '') === 'react') { $reactId = (int)($_POST['chat_id'] ?? 0); $reactPick = (string)($_POST['chat_emoji'] ?? ''); if ($reactId > 0 && in_array($reactPick, $reactEmoji, true)) { chat_update(function (&$msgs) use ($reactId, $reactPick) { foreach ($msgs as &$m) { if (($m['id'] ?? 0) !== $reactId) continue; $list = $m['reactions'][$reactPick] ?? []; if (!is_array($list)) $list = []; $k = array_search(chat_who(), $list, true); if ($k === false) $list[] = chat_who(); else array_splice($list, $k, 1); if ($list) $m['reactions'][$reactPick] = $list; else unset($m['reactions'][$reactPick]); if (empty($m['reactions'])) unset($m['reactions']); } unset($m); return null; }); } } chat_on('msg_bottom', function ($html, $msg) use ($reactEmoji) { foreach ($reactEmoji as $emoji) { $list = $msg['reactions'][$emoji] ?? []; if (!is_array($list)) $list = []; $mine = in_array(chat_who(), $list, true); $html .= '
' . '' . '' . '' . '
'; } return $html; });