HaikuDepot: Improvements to User Ratings

Change to match the web user interface behaviour;
the user ratings for all architectures are shown
and the list of user ratings is restricted to the
actual repository in use.  This is important
where two repositories have the same package with
different versions.  Also the architecture
is displayed with the version in the package info
page.

Change-Id: I8c024d9ddec6b97f52233b7462c47d2a1c83af09
Reviewed-on: https://review.haiku-os.org/c/haiku/+/1817
Reviewed-by: Andrew Lindesay <apl@lindesay.co.nz>
This commit is contained in:
Andrew Lindesay 2019-09-02 14:07:14 +12:00
parent 75d2b89f76
commit 051ee9d8fc
5 changed files with 66 additions and 32 deletions

View File

@ -63,4 +63,8 @@ enum {
#define LANGUAGE_DEFAULT Language(LANGUAGE_DEFAULT_CODE, "English", true)
#define PACKAGE_INFO_MAX_USER_RATINGS 250
#define STR_MDASH "\xE2\x80\x94"
#endif // HAIKU_DEPOT_CONSTANTS_H

View File

@ -24,6 +24,7 @@
#include <Message.h>
#include <Path.h>
#include "HaikuDepotConstants.h"
#include "Logger.h"
#include "LocaleUtils.h"
#include "StorageUtils.h"
@ -624,15 +625,20 @@ Model::PopulatePackage(const PackageInfoRef& package, uint32 flags)
BMessage info;
BString packageName;
BString architecture;
BString webAppRepositoryCode;
{
BAutolock locker(&fLock);
packageName = package->Name();
architecture = package->Architecture();
const DepotInfo* depot = DepotForName(package->DepotName());
if (depot != NULL)
webAppRepositoryCode = depot->WebAppRepositoryCode();
}
status_t status = fWebAppInterface.RetrieveUserRatings(packageName,
architecture, 0, 50, info);
status_t status = fWebAppInterface
.RetreiveUserRatingsForPackageForDisplay(packageName,
webAppRepositoryCode, 0, PACKAGE_INFO_MAX_USER_RATINGS,
info);
if (status == B_OK) {
// Parse message
BMessage result;
@ -687,17 +693,20 @@ Model::PopulatePackage(const PackageInfoRef& package, uint32 flags)
BString minor = "?";
BString micro = "";
double revision = -1;
BString architectureCode = "";
BMessage version;
if (item.FindMessage("pkgVersion", &version) == B_OK) {
version.FindString("major", &major);
version.FindString("minor", &minor);
version.FindString("micro", &micro);
version.FindDouble("revision", &revision);
version.FindString("architectureCode",
&architectureCode);
}
BString versionString = major;
versionString << ".";
versionString << minor;
if (micro.Length() > 0) {
if (!micro.IsEmpty()) {
versionString << ".";
versionString << micro;
}
@ -706,6 +715,11 @@ Model::PopulatePackage(const PackageInfoRef& package, uint32 flags)
versionString << (int) revision;
}
if (!architectureCode.IsEmpty()) {
versionString << " " << STR_MDASH << " ";
versionString << architectureCode;
}
BDateTime createTimestamp;
double createTimestampMillisF;
if (item.FindDouble("createTimestamp",

View File

@ -327,33 +327,48 @@ WebAppInterface::GetChangelog(const BString& packageName, BMessage& message)
status_t
WebAppInterface::RetrieveUserRatings(const BString& packageName,
const BString& architecture, int resultOffset, int maxResults,
BMessage& message)
WebAppInterface::RetreiveUserRatingsForPackageForDisplay(
const BString& packageName, const BString& webAppRepositoryCode,
int resultOffset, int maxResults, BMessage& message)
{
BString jsonString = JsonBuilder()
.AddValue("jsonrpc", "2.0")
.AddValue("id", ++fRequestIndex)
.AddValue("method", "searchUserRatings")
.AddArray("params")
.AddObject()
.AddValue("pkgName", packageName)
.AddValue("pkgVersionArchitectureCode", architecture)
.AddValue("offset", resultOffset)
.AddValue("limit", maxResults)
.EndObject()
.EndArray()
.End();
// BHttpRequest later takes ownership of this.
BMallocIO* requestEnvelopeData = new BMallocIO();
BJsonTextWriter requestEnvelopeWriter(requestEnvelopeData);
return _SendJsonRequest("userrating", jsonString, 0, message);
requestEnvelopeWriter.WriteObjectStart();
_WriteStandardJsonRpcEnvelopeValues(requestEnvelopeWriter,
"searchUserRatings");
requestEnvelopeWriter.WriteObjectName("params");
requestEnvelopeWriter.WriteArrayStart();
requestEnvelopeWriter.WriteObjectStart();
requestEnvelopeWriter.WriteObjectName("pkgName");
requestEnvelopeWriter.WriteString(packageName.String());
requestEnvelopeWriter.WriteObjectName("offset");
requestEnvelopeWriter.WriteInteger(resultOffset);
requestEnvelopeWriter.WriteObjectName("limit");
requestEnvelopeWriter.WriteInteger(maxResults);
if (!webAppRepositoryCode.IsEmpty()) {
requestEnvelopeWriter.WriteObjectName("repositoryCode");
requestEnvelopeWriter.WriteString(webAppRepositoryCode);
}
requestEnvelopeWriter.WriteObjectEnd();
requestEnvelopeWriter.WriteArrayEnd();
requestEnvelopeWriter.WriteObjectEnd();
return _SendJsonRequest("userrating", requestEnvelopeData,
_LengthAndSeekToZero(requestEnvelopeData), 0,
message);
}
status_t
WebAppInterface::RetrieveUserRating(const BString& packageName,
const BPackageVersion& version, const BString& architecture,
const BString &repositoryCode, const BString& username,
BMessage& message)
WebAppInterface::RetreiveUserRatingForPackageAndVersionByUser(
const BString& packageName, const BPackageVersion& version,
const BString& architecture, const BString &repositoryCode,
const BString& username, BMessage& message)
{
// BHttpRequest later takes ownership of this.
BMallocIO* requestEnvelopeData = new BMallocIO();

View File

@ -56,13 +56,13 @@ public:
const BString& packageName,
BMessage& message);
status_t RetrieveUserRatings(
status_t RetreiveUserRatingsForPackageForDisplay(
const BString& packageName,
const BString& architecture,
const BString& webAppRepositoryCode,
int resultOffset, int maxResults,
BMessage& message);
status_t RetrieveUserRating(
status_t RetreiveUserRatingForPackageAndVersionByUser(
const BString& packageName,
const BPackageVersion& version,
const BString& architecture,

View File

@ -570,9 +570,10 @@ RatePackageWindow::_QueryRatingThread()
package->DepotName().String());
BMessenger(this).SendMessage(B_QUIT_REQUESTED);
} else {
status_t status = interface.RetrieveUserRating(
package->Name(), package->Version(), package->Architecture(),
repositoryCode, username, info);
status_t status = interface
.RetreiveUserRatingForPackageAndVersionByUser(package->Name(),
package->Version(), package->Architecture(), repositoryCode,
username, info);
if (status == B_OK) {
// could be an error or could be a valid response envelope