fixed comment lock

This commit is contained in:
Tony Yang 2019-09-25 16:39:30 +08:00
parent 45b778484a
commit 2017b71a20
Signed by: t510599
GPG Key ID: D88388851C28715D
2 changed files with 9 additions and 5 deletions

View File

@ -12,7 +12,7 @@ $user = validate_user();
if (!$user->valid) { if (!$user->valid) {
http_response_code(403); http_response_code(403);
header("Content-Type: applcation/json"); header("Content-Type: applcation/json");
echo json_encode(array('status' => 'invalid')); echo json_encode(array('status' => 'novalid'));
exit; exit;
} }
@ -53,7 +53,7 @@ if (!isset($_GET['pid']) && !isset($_GET['del']) && !isset($_POST['pid']) && !is
"time" => round($_SERVER['REQUEST_TIME_FLOAT'] * 1000) "time" => round($_SERVER['REQUEST_TIME_FLOAT'] * 1000)
); );
} else if (isset($_POST['content'])) { } else if (isset($_POST['content'])) {
if (isset($_POST['pid']) && trim($_POST['pid']) && isset($_SESSION['cavern_comment_time']) && $_SERVER['REQUEST_TIME'] - $_SESSION['cavern_comment_time'] < 10) { if (isset($_POST['pid']) && trim($_POST['pid']) != "" && isset($_SESSION['cavern_comment_time']) && $_SERVER['REQUEST_TIME'] - $_SESSION['cavern_comment_time'] < 10) {
// user can create one comment per 10 seconds // user can create one comment per 10 seconds
$remain_second = 10 - ($_SERVER['REQUEST_TIME'] - $_SESSION['cavern_comment_time']); $remain_second = 10 - ($_SERVER['REQUEST_TIME'] - $_SESSION['cavern_comment_time']);
header('Retry-After: ' . $remain_second); header('Retry-After: ' . $remain_second);
@ -99,6 +99,7 @@ if (!isset($_GET['pid']) && !isset($_GET['del']) && !isset($_POST['pid']) && !is
do { do {
$u = $commenters['row']['username']; $u = $commenters['row']['username'];
if (!in_array($u, $username_list) && $u != $article->author && $u != $user->username) { if (!in_array($u, $username_list) && $u != $article->author && $u != $user->username) {
$username_list[] = $u;
cavern_notify_user($u, "在你回應的文章 [{$article->title}] 中有了新的回應", "post.php?pid={$article->pid}#comment-$comment_id", "comment"); cavern_notify_user($u, "在你回應的文章 [{$article->title}] 中有了新的回應", "post.php?pid={$article->pid}#comment-$comment_id", "comment");
} }
} while ($commenters['row'] = $commenters['query']->fetch_assoc()); } while ($commenters['row'] = $commenters['query']->fetch_assoc());
@ -112,6 +113,7 @@ if (!isset($_GET['pid']) && !isset($_GET['del']) && !isset($_POST['pid']) && !is
do { do {
$u = $likers['row']['username']; $u = $likers['row']['username'];
if (!in_array($u, $username_list) && $u != $article->author && $u != $user->username) { if (!in_array($u, $username_list) && $u != $article->author && $u != $user->username) {
$username_list[] = $u;
cavern_notify_user($u, "在你喜歡的文章 [{$article->title}] 中有了新的回應", "post.php?pid={$article->pid}#comment-$comment_id", "comment"); cavern_notify_user($u, "在你喜歡的文章 [{$article->title}] 中有了新的回應", "post.php?pid={$article->pid}#comment-$comment_id", "comment");
} }
} while ($likers['row'] = $likers['query']->fetch_assoc()); } while ($likers['row'] = $likers['query']->fetch_assoc());
@ -235,4 +237,4 @@ function send_error($code, $message) {
echo json_encode(array('status' => $message, 'fetch' => round($_SERVER['REQUEST_TIME_FLOAT'] * 1000))); // to fit javascript timestamp echo json_encode(array('status' => $message, 'fetch' => round($_SERVER['REQUEST_TIME_FLOAT'] * 1000))); // to fit javascript timestamp
exit; exit;
} }
?> ?>

View File

@ -221,8 +221,10 @@ function parseComments(data) {
return false; return false;
} }
if (commentLock) { if (commentLock) {
snackbar(`${commentRate} 秒只能發一則留言。`); if (!commentContainer.dataset.editId) {
return false; snackbar(`${commentRate} 秒只能發一則留言。`);
return false;
}
} else if (!commentContainer.dataset.editId) { } else if (!commentContainer.dataset.editId) {
// only new comment should be limited // only new comment should be limited
commentLock = true; commentLock = true;