HaikuDepot: Use getUserRatingByUserAndPkgVersion...

... instead of searching for a rating from the given user. This API will
also return deactivated ratings, so the user could re-activate it.
This commit is contained in:
Stephan Aßmus
2014-09-29 22:05:00 +02:00
parent 46bcb34d05
commit cec1192ea0
3 changed files with 53 additions and 28 deletions
+40 -15
View File
@@ -76,24 +76,46 @@ public:
JsonBuilder& AddItem(const char* item)
{
if (fInList)
fString << ",\"";
else
return AddItem(item, false);
}
JsonBuilder& AddItem(const char* item, bool nullIfEmpty)
{
if (item == NULL || (nullIfEmpty && strlen(item) == 0)) {
if (fInList)
fString << ",null";
else
fString << "null";
} else {
if (fInList)
fString << ",\"";
else
fString << '"';
// TODO: Escape item
fString << item;
fString << '"';
// TODO: Escape item
fString << item;
fString << "\"";
}
fInList = true;
return *this;
}
JsonBuilder& AddValue(const char* name, const char* value)
{
return AddValue(name, value, false);
}
JsonBuilder& AddValue(const char* name, const char* value,
bool nullIfEmpty)
{
_StartName(name);
fString << '\"';
// TODO: Escape value
fString << value;
fString << '\"';
if (value == NULL || (nullIfEmpty && strlen(value) == 0)) {
fString << "null";
} else {
fString << '"';
// TODO: Escape value
fString << value;
fString << '"';
}
fInList = true;
return *this;
}
@@ -391,20 +413,23 @@ WebAppInterface::RetrieveUserRatings(const BString& packageName,
status_t
WebAppInterface::RetrieveUserRating(const BString& packageName,
const BString& architecture, const BString& username,
BMessage& message)
const BPackageVersion& version, const BString& architecture,
const BString& username, BMessage& message)
{
BString jsonString = JsonBuilder()
.AddValue("jsonrpc", "2.0")
.AddValue("id", ++fRequestIndex)
.AddValue("method", "searchUserRatings")
.AddValue("method", "getUserRatingByUserAndPkgVersion")
.AddArray("params")
.AddObject()
.AddValue("userNickname", username)
.AddValue("pkgName", packageName)
.AddValue("pkgVersionArchitectureCode", architecture)
.AddValue("offset", 0)
.AddValue("limit", 1)
.AddValue("pkgVersionMajor", version.Major(), true)
.AddValue("pkgVersionMinor", version.Minor(), true)
.AddValue("pkgVersionMicro", version.Micro(), true)
.AddValue("pkgVersionPreRelease", version.PreRelease(), true)
.AddValue("pkgVersionRevision", (int)version.Revision())
.EndObject()
.EndArray()
.End();
@@ -8,12 +8,14 @@
#include <Application.h>
#include <String.h>
#include <package/PackageVersion.h>
#include "List.h"
class BDataIO;
class BMessage;
using BPackageKit::BPackageVersion;
typedef List<BString, false> StringList;
@@ -56,6 +58,7 @@ public:
status_t RetrieveUserRating(
const BString& packageName,
const BPackageVersion& version,
const BString& architecture,
const BString& username,
BMessage& message);
+10 -13
View File
@@ -391,27 +391,24 @@ RatePackageWindow::_QueryRatingThread()
BMessage info;
status_t status = interface.RetrieveUserRating(
package->Title(), package->Architecture(), username, info);
package->Title(), package->Version(), package->Architecture(),
username, info);
// info.PrintToStream();
BMessage result;
BMessage items;
BMessage rating;
if (status == B_OK && info.FindMessage("result", &result) == B_OK
&& result.FindMessage("items", &items) == B_OK
&& items.FindMessage("0", &rating) == B_OK
&& Lock()) {
rating.FindString("code", &fRatingID);
rating.FindBool("active", &fRatingActive);
result.FindString("code", &fRatingID);
result.FindBool("active", &fRatingActive);
BString comment;
if (rating.FindString("comment", &comment) == B_OK) {
if (result.FindString("comment", &comment) == B_OK) {
MarkupParser parser;
fRatingText = parser.CreateDocumentFromMarkup(comment);
fTextView->SetTextDocument(fRatingText);
}
if (rating.FindString("userRatingStabilityCode",
if (result.FindString("userRatingStabilityCode",
&fStability) == B_OK) {
int32 index = -1;
for (int32 i = fStabilityCodes.CountItems() - 1; i >= 0; i--) {
@@ -426,16 +423,16 @@ RatePackageWindow::_QueryRatingThread()
if (item != NULL)
item->SetMarked(true);
}
if (rating.FindString("naturalLanguageCode",
if (result.FindString("naturalLanguageCode",
&fCommentLanguage) == B_OK) {
BMenuItem* item = fCommentLanguageField->Menu()->ItemAt(
fModel.SupportedLanguages().IndexOf(fCommentLanguage));
if (item != NULL)
item->SetMarked(true);
}
double ratingValue;
if (rating.FindDouble("rating", &ratingValue) == B_OK) {
fRating = (float)ratingValue;
double rating;
if (result.FindDouble("rating", &rating) == B_OK) {
fRating = (float)rating;
fSetRatingView->SetPermanentRating(fRating);
}