From 77f571de7d268f6973523c0f083abb29b79e8ea2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mike=20Schw=C3=B6rer?=
+ You can modify the displayed timestamp of a message by sending the timestamp
parameter. The format must be a valid UNIX timestamp (elapsed seconds since 1970-01-01 GMT)
+
+ But the custom timestamp must be within 48 hoours of the current time. This parameter is only intended to supply a more precise value in case the message sending was delayed +
+curl \ + --data "user_id={userid}" \ + --data "user_key={userkey}" \ + --data "title={message_title}" \ + --data "timestamp={unix_timestamp}" \ + https://scn.blackforestbytes.com/send.php+
+ Be aware that the server only saves send messages for a short amount of time. Because of that you can only use this to prevent duplicates in a short time-frame, older messages with the same ID are probably already deleted and the message will be send again. +
+@@ -227,6 +246,7 @@ user_key="???????????????????????????????????????? title=$1 content="" +sendtime=$(date +%s) if [ "$#" -gt 1 ]; then content=$2 @@ -243,7 +263,7 @@ usr_msg_id=$(uuidgen) while true ; do curlresp=$(curl -s -o /dev/null -w "%{http_code}" \ - -d "user_id=$user_id" -d "user_key=$user_key" -d "title=$title" \ + -d "user_id=$user_id" -d "user_key=$user_key" -d "title=$title" -d "timestamp=$sendtime" \ -d "content=$content" -d "priority=$priority" -d "msg_id=$usr_msg_id" \ https://scn.blackforestbytes.com/send.php) diff --git a/web/send.php b/web/send.php index 1703546..915f605 100644 --- a/web/send.php +++ b/web/send.php @@ -5,8 +5,6 @@ include_once 'api/model.php'; try { -//------------------------------------------------------------------ -//sleep(1); //------------------------------------------------------------------ if ($_SERVER['REQUEST_METHOD'] !== 'POST') api_return(400, ['success' => false, 'error' => ERR::REQ_METHOD, 'errhighlight' => -1, 'message' => 'Invalid request method (must be POST)']); @@ -19,16 +17,18 @@ try //------------------------------------------------------------------ - $user_id = $INPUT['user_id']; $user_key = $INPUT['user_key']; $message = $INPUT['title']; - $content = isset($INPUT['content']) ? $INPUT['content'] : ''; - $priority = isset($INPUT['priority']) ? $INPUT['priority'] : '1'; - $usrmsgid = isset($INPUT['msg_id']) ? $INPUT['msg_id'] : null; + $content = isset($INPUT['content']) ? $INPUT['content'] : ''; + $priority = isset($INPUT['priority']) ? $INPUT['priority'] : '1'; + $usrmsgid = isset($INPUT['msg_id']) ? $INPUT['msg_id'] : null; + $time = isset($INPUT['timestamp']) ? $INPUT['timestamp'] : time(); //------------------------------------------------------------------ + if (abs($time - time()) > 60*60*24*2) api_return(400, ['success' => false, 'error' => ERR::TIMESTAMP_OUT_OF_RANGE, 'errhighlight' => -1, 'message' => 'The timestamp mus be within 24 hours of now()']); + if ($priority !== '0' && $priority !== '1' && $priority !== '2') api_return(400, ['success' => false, 'error' => ERR::INVALID_PRIO, 'errhighlight' => 105, 'message' => 'Invalid priority']); if (strlen(trim($message)) == 0) api_return(400, ['success' => false, 'error' => ERR::NO_TITLE, 'errhighlight' => 103, 'message' => 'No title specified']); @@ -95,13 +95,14 @@ try $pdo->beginTransaction(); - $stmt = $pdo->prepare('INSERT INTO messages (sender_user_id, title, content, priority, fcm_message_id, usr_message_id) VALUES (:suid, :t, :c, :p, :fmid, :umid)'); + $stmt = $pdo->prepare('INSERT INTO messages (sender_user_id, title, content, priority, sendtime, fcm_message_id, usr_message_id) VALUES (:suid, :t, :c, :p, :ts, :fmid, :umid)'); $stmt->execute( [ 'suid' => $user_id, 't' => $message, 'c' => $content, 'p' => $priority, + 'ts' => $time, 'fmid' => null, 'umid' => $usrmsgid, ]); @@ -125,7 +126,7 @@ try 'body' => str_limit($content, 1900), 'trimmed' => (strlen($content) > 1900), 'priority' => $priority, - 'timestamp' => time(), + 'timestamp' => $time, 'usr_msg_id' => $usrmsgid, 'scn_msg_id' => $scn_msg_id, ]