implement usr_msg_id
This commit is contained in:
parent
2163ae4dbf
commit
cae6ff6271
@ -102,29 +102,29 @@ public class SCNApp extends Application implements LifecycleObserver
|
|||||||
/*
|
/*
|
||||||
==TODO==
|
==TODO==
|
||||||
|
|
||||||
- Pro mode
|
[X] - Pro mode
|
||||||
- no ads
|
[X] - no ads
|
||||||
- more quota
|
[X] - more quota
|
||||||
- restore pro mode
|
[X] - restore pro mode
|
||||||
- send pro state to server
|
[X] - send pro state to server
|
||||||
|
|
||||||
- prevent duplicate-send
|
[X] - prevent duplicate-send
|
||||||
- send custom msg-id in API
|
[X] - send custom msg-id in API
|
||||||
- prevent second ack on same msg-id
|
[X] - prevent second ack on same msg-id
|
||||||
|
|
||||||
- more in-depth API doc on website (?)
|
[X] - more in-depth API doc on website (?)
|
||||||
|
|
||||||
- perhaps response codes in api (?)
|
[X] - perhaps response codes in api (?)
|
||||||
|
|
||||||
- test notification channels
|
[ ] - test notification channels
|
||||||
|
|
||||||
- publish (+ HN post ?)
|
[ ] - publish (+ HN post ?)
|
||||||
|
|
||||||
- Use for mscom server errrors
|
[ ] - Use for mscom server errrors
|
||||||
- Use for bfb server errors
|
[ ] - Use for bfb server errors
|
||||||
- Use for transmission state
|
[ ] - Use for transmission state
|
||||||
- Message on connnection lost (seperate process - resend until succ)
|
[ ] - Message on connnection lost (seperate process - resend until succ)
|
||||||
- Message on connnection regained
|
[ ] - Message on connnection regained
|
||||||
- Message on seed-count changed
|
[ ] - Message on seed-count changed
|
||||||
|
|
||||||
*/
|
*/
|
@ -197,3 +197,21 @@ function api_return($http_code, $message)
|
|||||||
echo $message;
|
echo $message;
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param String $str
|
||||||
|
* @param String[] $path
|
||||||
|
*/
|
||||||
|
function try_json($str, $path)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$o = json_decode($str);
|
||||||
|
foreach ($path as $p) $o = $o[$p];
|
||||||
|
return $o;
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -15,3 +15,20 @@ CREATE TABLE `users`
|
|||||||
|
|
||||||
PRIMARY KEY (`user_id`)
|
PRIMARY KEY (`user_id`)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE `messages`
|
||||||
|
(
|
||||||
|
`scn_message_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`sender_user_id` INT(11) NOT NULL,
|
||||||
|
|
||||||
|
`timestamp` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
|
||||||
|
`title` VARCHAR(256) NOT NULL,
|
||||||
|
`content` VARCHAR(12288) NULL,
|
||||||
|
`priority` INT(11) NOT NULL,
|
||||||
|
|
||||||
|
`fcn_message_id` VARCHAR(256) NOT NULL,
|
||||||
|
`usr_message_id` VARCHAR(256) NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (`scn_message_id`)
|
||||||
|
)
|
43
web/send.php
43
web/send.php
@ -23,6 +23,7 @@ try
|
|||||||
$message = $INPUT['title'];
|
$message = $INPUT['title'];
|
||||||
$content = isset($INPUT['content']) ? $INPUT['content'] : '';
|
$content = isset($INPUT['content']) ? $INPUT['content'] : '';
|
||||||
$priority = isset($INPUT['priority']) ? $INPUT['priority'] : '1';
|
$priority = isset($INPUT['priority']) ? $INPUT['priority'] : '1';
|
||||||
|
$usrmsgid = isset($INPUT['msg_id']) ? $INPUT['msg_id'] : null;
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
@ -53,6 +54,29 @@ try
|
|||||||
if ($data['quota_day'] === null || $data['quota_day'] !== date("Y-m-d")) $new_quota=1;
|
if ($data['quota_day'] === null || $data['quota_day'] !== date("Y-m-d")) $new_quota=1;
|
||||||
if ($new_quota > Statics::quota_max($data['is_pro'])) api_return(403, json_encode(['success' => false, 'error' => 2101, 'errhighlight' => -1, 'message' => 'Daily quota reached ('.Statics::quota_max($data['is_pro']).')']));
|
if ($new_quota > Statics::quota_max($data['is_pro'])) api_return(403, json_encode(['success' => false, 'error' => 2101, 'errhighlight' => -1, 'message' => 'Daily quota reached ('.Statics::quota_max($data['is_pro']).')']));
|
||||||
|
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
|
if ($usrmsgid != null)
|
||||||
|
{
|
||||||
|
$stmt = $pdo->prepare('SELECT scn_message_id FROM messages WHERE sender_user_id=:uid AND usr_message_id IS NOT NULL AND usr_message_id=:umid LIMIT 1');
|
||||||
|
$stmt->execute(['uid' => $user_id, 'umid' => $usrmsgid]);
|
||||||
|
|
||||||
|
if (count($stmt->fetchAll(PDO::FETCH_ASSOC))>0)
|
||||||
|
{
|
||||||
|
api_return(200, json_encode(
|
||||||
|
[
|
||||||
|
'success' => true,
|
||||||
|
'message' => 'Message already sent',
|
||||||
|
'suppress_send' => true,
|
||||||
|
'response' => '',
|
||||||
|
'messagecount' => $data['messages_sent']+1,
|
||||||
|
'quota' => $data['quota_today'],
|
||||||
|
'is_pro' => $data['is_pro'],
|
||||||
|
'quota_max' => Statics::quota_max($data['is_pro']),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
$url = "https://fcm.googleapis.com/fcm/send";
|
$url = "https://fcm.googleapis.com/fcm/send";
|
||||||
@ -72,6 +96,7 @@ try
|
|||||||
'body' => $content,
|
'body' => $content,
|
||||||
'priority' => $priority,
|
'priority' => $priority,
|
||||||
'timestamp' => time(),
|
'timestamp' => time(),
|
||||||
|
'usr_msg_id' => $usrmsgid,
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
$header=
|
$header=
|
||||||
@ -83,6 +108,12 @@ try
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
$httpresult = sendPOST($url, $payload, $header);
|
$httpresult = sendPOST($url, $payload, $header);
|
||||||
|
|
||||||
|
if (try_json($httpresult, ['success']) != 1)
|
||||||
|
{
|
||||||
|
reportError("FCM communication failed (success_1 <> true)\n\n".$httpresult);
|
||||||
|
api_return(403, json_encode(['success' => false, 'error' => 9902, 'errhighlight' => -1, 'message' => 'Communication with firebase service failed.']));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
catch (Exception $e)
|
||||||
{
|
{
|
||||||
@ -93,10 +124,22 @@ try
|
|||||||
$stmt = $pdo->prepare('UPDATE users SET timestamp_accessed=NOW(), messages_sent=messages_sent+1, quota_today=:q, quota_day=NOW() WHERE user_id = :uid');
|
$stmt = $pdo->prepare('UPDATE users SET timestamp_accessed=NOW(), messages_sent=messages_sent+1, quota_today=:q, quota_day=NOW() WHERE user_id = :uid');
|
||||||
$stmt->execute(['uid' => $user_id, 'q' => $new_quota]);
|
$stmt->execute(['uid' => $user_id, 'q' => $new_quota]);
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare('INSERT INTO messages (sender_user_id, title, content, priority, fcn_message_id, usr_message_id) VALUES (:suid, :t, :c, :p, :fmid, :umid)');
|
||||||
|
$stmt->execute(
|
||||||
|
[
|
||||||
|
'suid' => $user_id,
|
||||||
|
't' => $message,
|
||||||
|
'c' => $content,
|
||||||
|
'p' => $priority,
|
||||||
|
'fmid' => try_json($httpresult, ['results', 'message_id']),
|
||||||
|
'umid' => $usrmsgid,
|
||||||
|
]);
|
||||||
|
|
||||||
api_return(200, json_encode(
|
api_return(200, json_encode(
|
||||||
[
|
[
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'message' => 'Message sent',
|
'message' => 'Message sent',
|
||||||
|
'suppress_send' => false,
|
||||||
'response' => $httpresult,
|
'response' => $httpresult,
|
||||||
'messagecount' => $data['messages_sent']+1,
|
'messagecount' => $data['messages_sent']+1,
|
||||||
'quota' => $new_quota,
|
'quota' => $new_quota,
|
||||||
|
Loading…
Reference in New Issue
Block a user