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:
@@ -76,24 +76,46 @@ public:
|
|||||||
|
|
||||||
JsonBuilder& AddItem(const char* item)
|
JsonBuilder& AddItem(const char* item)
|
||||||
{
|
{
|
||||||
if (fInList)
|
return AddItem(item, false);
|
||||||
fString << ",\"";
|
}
|
||||||
else
|
|
||||||
|
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 << '"';
|
fString << '"';
|
||||||
// TODO: Escape item
|
}
|
||||||
fString << item;
|
|
||||||
fString << "\"";
|
|
||||||
fInList = true;
|
fInList = true;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonBuilder& AddValue(const char* name, const char* value)
|
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);
|
_StartName(name);
|
||||||
fString << '\"';
|
if (value == NULL || (nullIfEmpty && strlen(value) == 0)) {
|
||||||
// TODO: Escape value
|
fString << "null";
|
||||||
fString << value;
|
} else {
|
||||||
fString << '\"';
|
fString << '"';
|
||||||
|
// TODO: Escape value
|
||||||
|
fString << value;
|
||||||
|
fString << '"';
|
||||||
|
}
|
||||||
fInList = true;
|
fInList = true;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -391,20 +413,23 @@ WebAppInterface::RetrieveUserRatings(const BString& packageName,
|
|||||||
|
|
||||||
status_t
|
status_t
|
||||||
WebAppInterface::RetrieveUserRating(const BString& packageName,
|
WebAppInterface::RetrieveUserRating(const BString& packageName,
|
||||||
const BString& architecture, const BString& username,
|
const BPackageVersion& version, const BString& architecture,
|
||||||
BMessage& message)
|
const BString& username, BMessage& message)
|
||||||
{
|
{
|
||||||
BString jsonString = JsonBuilder()
|
BString jsonString = JsonBuilder()
|
||||||
.AddValue("jsonrpc", "2.0")
|
.AddValue("jsonrpc", "2.0")
|
||||||
.AddValue("id", ++fRequestIndex)
|
.AddValue("id", ++fRequestIndex)
|
||||||
.AddValue("method", "searchUserRatings")
|
.AddValue("method", "getUserRatingByUserAndPkgVersion")
|
||||||
.AddArray("params")
|
.AddArray("params")
|
||||||
.AddObject()
|
.AddObject()
|
||||||
.AddValue("userNickname", username)
|
.AddValue("userNickname", username)
|
||||||
.AddValue("pkgName", packageName)
|
.AddValue("pkgName", packageName)
|
||||||
.AddValue("pkgVersionArchitectureCode", architecture)
|
.AddValue("pkgVersionArchitectureCode", architecture)
|
||||||
.AddValue("offset", 0)
|
.AddValue("pkgVersionMajor", version.Major(), true)
|
||||||
.AddValue("limit", 1)
|
.AddValue("pkgVersionMinor", version.Minor(), true)
|
||||||
|
.AddValue("pkgVersionMicro", version.Micro(), true)
|
||||||
|
.AddValue("pkgVersionPreRelease", version.PreRelease(), true)
|
||||||
|
.AddValue("pkgVersionRevision", (int)version.Revision())
|
||||||
.EndObject()
|
.EndObject()
|
||||||
.EndArray()
|
.EndArray()
|
||||||
.End();
|
.End();
|
||||||
|
|||||||
@@ -8,12 +8,14 @@
|
|||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
#include <package/PackageVersion.h>
|
||||||
|
|
||||||
#include "List.h"
|
#include "List.h"
|
||||||
|
|
||||||
|
|
||||||
class BDataIO;
|
class BDataIO;
|
||||||
class BMessage;
|
class BMessage;
|
||||||
|
using BPackageKit::BPackageVersion;
|
||||||
|
|
||||||
typedef List<BString, false> StringList;
|
typedef List<BString, false> StringList;
|
||||||
|
|
||||||
@@ -56,6 +58,7 @@ public:
|
|||||||
|
|
||||||
status_t RetrieveUserRating(
|
status_t RetrieveUserRating(
|
||||||
const BString& packageName,
|
const BString& packageName,
|
||||||
|
const BPackageVersion& version,
|
||||||
const BString& architecture,
|
const BString& architecture,
|
||||||
const BString& username,
|
const BString& username,
|
||||||
BMessage& message);
|
BMessage& message);
|
||||||
|
|||||||
@@ -391,27 +391,24 @@ RatePackageWindow::_QueryRatingThread()
|
|||||||
BMessage info;
|
BMessage info;
|
||||||
|
|
||||||
status_t status = interface.RetrieveUserRating(
|
status_t status = interface.RetrieveUserRating(
|
||||||
package->Title(), package->Architecture(), username, info);
|
package->Title(), package->Version(), package->Architecture(),
|
||||||
|
username, info);
|
||||||
|
|
||||||
// info.PrintToStream();
|
// info.PrintToStream();
|
||||||
|
|
||||||
BMessage result;
|
BMessage result;
|
||||||
BMessage items;
|
|
||||||
BMessage rating;
|
|
||||||
if (status == B_OK && info.FindMessage("result", &result) == B_OK
|
if (status == B_OK && info.FindMessage("result", &result) == B_OK
|
||||||
&& result.FindMessage("items", &items) == B_OK
|
|
||||||
&& items.FindMessage("0", &rating) == B_OK
|
|
||||||
&& Lock()) {
|
&& Lock()) {
|
||||||
|
|
||||||
rating.FindString("code", &fRatingID);
|
result.FindString("code", &fRatingID);
|
||||||
rating.FindBool("active", &fRatingActive);
|
result.FindBool("active", &fRatingActive);
|
||||||
BString comment;
|
BString comment;
|
||||||
if (rating.FindString("comment", &comment) == B_OK) {
|
if (result.FindString("comment", &comment) == B_OK) {
|
||||||
MarkupParser parser;
|
MarkupParser parser;
|
||||||
fRatingText = parser.CreateDocumentFromMarkup(comment);
|
fRatingText = parser.CreateDocumentFromMarkup(comment);
|
||||||
fTextView->SetTextDocument(fRatingText);
|
fTextView->SetTextDocument(fRatingText);
|
||||||
}
|
}
|
||||||
if (rating.FindString("userRatingStabilityCode",
|
if (result.FindString("userRatingStabilityCode",
|
||||||
&fStability) == B_OK) {
|
&fStability) == B_OK) {
|
||||||
int32 index = -1;
|
int32 index = -1;
|
||||||
for (int32 i = fStabilityCodes.CountItems() - 1; i >= 0; i--) {
|
for (int32 i = fStabilityCodes.CountItems() - 1; i >= 0; i--) {
|
||||||
@@ -426,16 +423,16 @@ RatePackageWindow::_QueryRatingThread()
|
|||||||
if (item != NULL)
|
if (item != NULL)
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
}
|
}
|
||||||
if (rating.FindString("naturalLanguageCode",
|
if (result.FindString("naturalLanguageCode",
|
||||||
&fCommentLanguage) == B_OK) {
|
&fCommentLanguage) == B_OK) {
|
||||||
BMenuItem* item = fCommentLanguageField->Menu()->ItemAt(
|
BMenuItem* item = fCommentLanguageField->Menu()->ItemAt(
|
||||||
fModel.SupportedLanguages().IndexOf(fCommentLanguage));
|
fModel.SupportedLanguages().IndexOf(fCommentLanguage));
|
||||||
if (item != NULL)
|
if (item != NULL)
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
}
|
}
|
||||||
double ratingValue;
|
double rating;
|
||||||
if (rating.FindDouble("rating", &ratingValue) == B_OK) {
|
if (result.FindDouble("rating", &rating) == B_OK) {
|
||||||
fRating = (float)ratingValue;
|
fRating = (float)rating;
|
||||||
fSetRatingView->SetPermanentRating(fRating);
|
fSetRatingView->SetPermanentRating(fRating);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user