Fix some issues with comment submission

- Fix error when submitting comments being ignored, meaning you'd only know if your comment got rejected if your comment wasn't there after the comments refreshed
- Fix issue in Request::ParseResponse where "Could not read response" is always included on all website errors
- Add ability to refresh comments by clicking the Submit button with an empty textbox
This commit is contained in:
jacob1
2024-05-14 23:56:58 -04:00
parent d32873b717
commit bb51daa05f
2 changed files with 13 additions and 5 deletions

View File

@@ -267,6 +267,7 @@ namespace http
{ {
std::istringstream ss(result); std::istringstream ss(result);
Json::Value root; Json::Value root;
int status;
try try
{ {
ss >> root; ss >> root;
@@ -275,11 +276,7 @@ namespace http
{ {
return; return;
} }
int status = root.get("Status", 1).asInt(); status = root.get("Status", 1).asInt();
if (status != 1)
{
throw RequestError(ByteString(root.get("Error", "Unspecified Error").asString()));
}
} }
catch (const std::exception &ex) catch (const std::exception &ex)
{ {
@@ -291,6 +288,11 @@ namespace http
} }
throw RequestError("Could not read response: " + ByteString(ex.what())); throw RequestError("Could not read response: " + ByteString(ex.what()));
} }
if (status != 1)
{
throw RequestError(ByteString(root.get("Error", "Unspecified Error").asString()));
}
} }
break; break;

View File

@@ -427,6 +427,7 @@ void PreviewView::OnTick(float dt)
{ {
try try
{ {
addCommentRequest->Finish();
addCommentBox->SetText(""); addCommentBox->SetText("");
c->CommentAdded(); c->CommentAdded();
} }
@@ -600,6 +601,11 @@ void PreviewView::submitComment()
if (addCommentBox) if (addCommentBox)
{ {
String comment = addCommentBox->GetText(); String comment = addCommentBox->GetText();
if (comment.length() == 0)
{
c->CommentAdded();
return;
}
if (comment.length() < 4) if (comment.length() < 4)
{ {
new ErrorMessage("Error", "Comment is too short"); new ErrorMessage("Error", "Comment is too short");