Skip to content

Commit

Permalink
HaikuDepot: Improvements to User Ratings
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
andponlin committed Sep 9, 2019
1 parent 75d2b89 commit 051ee9d
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 32 deletions.
4 changes: 4 additions & 0 deletions src/apps/haikudepot/HaikuDepotConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 19 additions & 5 deletions src/apps/haikudepot/model/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <Message.h>
#include <Path.h>

#include "HaikuDepotConstants.h"
#include "Logger.h"
#include "LocaleUtils.h"
#include "StorageUtils.h"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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",
Expand Down
57 changes: 36 additions & 21 deletions src/apps/haikudepot/server/WebAppInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/apps/haikudepot/server/WebAppInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ class WebAppInterface {
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,
Expand Down
7 changes: 4 additions & 3 deletions src/apps/haikudepot/ui/RatePackageWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 051ee9d

Please sign in to comment.