mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-12 03:14:04 +02:00
Working comment submission
This commit is contained in:
@@ -685,6 +685,67 @@ failure:
|
|||||||
return RequestFailure;
|
return RequestFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RequestStatus Client::AddComment(int saveID, std::string comment)
|
||||||
|
{
|
||||||
|
lastError = "";
|
||||||
|
std::vector<string> * tags = NULL;
|
||||||
|
std::stringstream urlStream;
|
||||||
|
char * data = NULL;
|
||||||
|
int dataStatus, dataLength;
|
||||||
|
urlStream << "http://" << SERVER << "/Browse/Comments.json?ID=" << saveID << "&Key=" << authUser.SessionKey;
|
||||||
|
if(authUser.ID)
|
||||||
|
{
|
||||||
|
std::stringstream userIDStream;
|
||||||
|
userIDStream << authUser.ID;
|
||||||
|
|
||||||
|
char * postNames[] = { "Comment", NULL };
|
||||||
|
char * postDatas[] = { (char*)(comment.c_str()) };
|
||||||
|
int postLengths[] = { comment.length() };
|
||||||
|
data = http_multipart_post((char *)urlStream.str().c_str(), postNames, postDatas, postLengths, (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lastError = "Not authenticated";
|
||||||
|
return RequestFailure;
|
||||||
|
}
|
||||||
|
if(dataStatus == 200 && data)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::istringstream dataStream(data);
|
||||||
|
json::Object objDocument;
|
||||||
|
json::Reader::Read(objDocument, dataStream);
|
||||||
|
|
||||||
|
int status = ((json::Number)objDocument["Status"]).Value();
|
||||||
|
|
||||||
|
if(status!=1)
|
||||||
|
{
|
||||||
|
lastError = ((json::Number)objDocument["Error"]).Value();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(status!=1)
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
catch (json::Exception &e)
|
||||||
|
{
|
||||||
|
lastError = "Could not read response";
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lastError = http_ret_text(dataStatus);
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
if(data)
|
||||||
|
free(data);
|
||||||
|
return RequestOkay;
|
||||||
|
failure:
|
||||||
|
if(data)
|
||||||
|
free(data);
|
||||||
|
return RequestFailure;
|
||||||
|
}
|
||||||
|
|
||||||
RequestStatus Client::FavouriteSave(int saveID, bool favourite)
|
RequestStatus Client::FavouriteSave(int saveID, bool favourite)
|
||||||
{
|
{
|
||||||
lastError = "";
|
lastError = "";
|
||||||
|
@@ -92,6 +92,8 @@ public:
|
|||||||
int GetStampsCount();
|
int GetStampsCount();
|
||||||
SaveFile * GetFirstStamp();
|
SaveFile * GetFirstStamp();
|
||||||
|
|
||||||
|
RequestStatus AddComment(int saveID, std::string comment);
|
||||||
|
|
||||||
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
|
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
|
||||||
LoginStatus Login(string username, string password, User & user);
|
LoginStatus Login(string username, string password, User & user);
|
||||||
void ClearThumbnailRequests();
|
void ClearThumbnailRequests();
|
||||||
|
@@ -27,6 +27,11 @@ Textbox::~Textbox()
|
|||||||
delete actionCallback;
|
delete actionCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Textbox::SetPlaceholder(std::string text)
|
||||||
|
{
|
||||||
|
placeHolder = text;
|
||||||
|
}
|
||||||
|
|
||||||
void Textbox::SetText(std::string newText)
|
void Textbox::SetText(std::string newText)
|
||||||
{
|
{
|
||||||
backingText = newText;
|
backingText = newText;
|
||||||
|
@@ -34,6 +34,8 @@ public:
|
|||||||
virtual void SetText(std::string text);
|
virtual void SetText(std::string text);
|
||||||
virtual std::string GetText();
|
virtual std::string GetText();
|
||||||
|
|
||||||
|
virtual void SetPlaceholder(std::string text);
|
||||||
|
|
||||||
void SetBorder(bool border) { this->border = border; };
|
void SetBorder(bool border) { this->border = border; };
|
||||||
void SetHidden(bool hidden) { masked = hidden; }
|
void SetHidden(bool hidden) { masked = hidden; }
|
||||||
bool GetHidden() { return masked; }
|
bool GetHidden() { return masked; }
|
||||||
|
@@ -60,6 +60,26 @@ void PreviewController::Update()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PreviewController::SubmitComment(std::string comment)
|
||||||
|
{
|
||||||
|
if(comment.length() < 4)
|
||||||
|
{
|
||||||
|
new ErrorMessage("Error", "Comment is too short");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RequestStatus status = Client::Ref().AddComment(saveId, comment);
|
||||||
|
if(status != RequestOkay)
|
||||||
|
{
|
||||||
|
new ErrorMessage("Error Submitting comment", Client::Ref().GetLastError());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
previewModel->UpdateComments(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PreviewController::ShowLogin()
|
void PreviewController::ShowLogin()
|
||||||
{
|
{
|
||||||
loginWindow = new LoginController();
|
loginWindow = new LoginController();
|
||||||
|
@@ -38,6 +38,7 @@ public:
|
|||||||
PreviewView * GetView() { return previewView; }
|
PreviewView * GetView() { return previewView; }
|
||||||
void Update();
|
void Update();
|
||||||
void FavouriteSave();
|
void FavouriteSave();
|
||||||
|
void SubmitComment(std::string comment);
|
||||||
|
|
||||||
void NextCommentPage();
|
void NextCommentPage();
|
||||||
void PrevCommentPage();
|
void PrevCommentPage();
|
||||||
|
@@ -28,6 +28,17 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PreviewView::SubmitCommentAction: public ui::ButtonAction
|
||||||
|
{
|
||||||
|
PreviewView * v;
|
||||||
|
public:
|
||||||
|
SubmitCommentAction(PreviewView * v_){ v = v_; }
|
||||||
|
virtual void ActionCallback(ui::Button * sender)
|
||||||
|
{
|
||||||
|
v->submitComment();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class PreviewView::AutoCommentSizeAction: public ui::TextboxAction
|
class PreviewView::AutoCommentSizeAction: public ui::TextboxAction
|
||||||
{
|
{
|
||||||
PreviewView * v;
|
PreviewView * v;
|
||||||
@@ -361,6 +372,23 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PreviewView::submitComment()
|
||||||
|
{
|
||||||
|
if(addCommentBox)
|
||||||
|
{
|
||||||
|
std::string comment = std::string(addCommentBox->GetText());
|
||||||
|
submitCommentButton->Enabled = false;
|
||||||
|
addCommentBox->SetText("");
|
||||||
|
addCommentBox->SetPlaceholder("Submitting comment");
|
||||||
|
FocusComponent(NULL);
|
||||||
|
|
||||||
|
c->SubmitComment(comment);
|
||||||
|
|
||||||
|
addCommentBox->SetPlaceholder("Add comment");
|
||||||
|
submitCommentButton->Enabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PreviewView::displayComments(int yOffset)
|
void PreviewView::displayComments(int yOffset)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < commentComponents.size(); i++)
|
for(int i = 0; i < commentComponents.size(); i++)
|
||||||
@@ -441,6 +469,7 @@ void PreviewView::NotifyCommentBoxEnabledChanged(PreviewModel * sender)
|
|||||||
addCommentBox->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
addCommentBox->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
AddComponent(addCommentBox);
|
AddComponent(addCommentBox);
|
||||||
submitCommentButton = new ui::Button(ui::Point(Size.X-40, Size.Y-19), ui::Point(40, 19), "Submit");
|
submitCommentButton = new ui::Button(ui::Point(Size.X-40, Size.Y-19), ui::Point(40, 19), "Submit");
|
||||||
|
submitCommentButton->SetActionCallback(new SubmitCommentAction(this));
|
||||||
//submitCommentButton->Enabled = false;
|
//submitCommentButton->Enabled = false;
|
||||||
AddComponent(submitCommentButton);
|
AddComponent(submitCommentButton);
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
class PreviewModel;
|
class PreviewModel;
|
||||||
class PreviewController;
|
class PreviewController;
|
||||||
class PreviewView: public ui::Window {
|
class PreviewView: public ui::Window {
|
||||||
|
class SubmitCommentAction;
|
||||||
class LoginAction;
|
class LoginAction;
|
||||||
class AutoCommentSizeAction;
|
class AutoCommentSizeAction;
|
||||||
PreviewController * c;
|
PreviewController * c;
|
||||||
@@ -56,6 +57,7 @@ class PreviewView: public ui::Window {
|
|||||||
|
|
||||||
void displayComments(int yOffset);
|
void displayComments(int yOffset);
|
||||||
void commentBoxAutoHeight();
|
void commentBoxAutoHeight();
|
||||||
|
void submitComment();
|
||||||
public:
|
public:
|
||||||
void AttachController(PreviewController * controller) { c = controller;}
|
void AttachController(PreviewController * controller) { c = controller;}
|
||||||
PreviewView();
|
PreviewView();
|
||||||
|
Reference in New Issue
Block a user