[haiku-commits] haiku: hrev53468 - in src/apps/haikudepot: server model ui

  • From: Andrew Lindesay <apl@xxxxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 9 Sep 2019 04:15:40 -0400 (EDT)

hrev53468 adds 1 changeset to branch 'master'
old head: 75d2b89f762cea1d8414e8a0c134c6b1aba73d46
new head: 051ee9d8fc6cb92b0429810609366643b3bb7d6b
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=051ee9d8fc6c+%5E75d2b89f762c

----------------------------------------------------------------------------

051ee9d8fc6c: 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@xxxxxxxxxxxxxx>

                                    [ Andrew Lindesay <apl@xxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev53468
Commit:      051ee9d8fc6cb92b0429810609366643b3bb7d6b
URL:         https://git.haiku-os.org/haiku/commit/?id=051ee9d8fc6c
Author:      Andrew Lindesay <apl@xxxxxxxxxxxxxx>
Date:        Mon Sep  2 02:07:14 2019 UTC

----------------------------------------------------------------------------

5 files changed, 66 insertions(+), 32 deletions(-)
src/apps/haikudepot/HaikuDepotConstants.h      |  4 ++
src/apps/haikudepot/model/Model.cpp            | 24 +++++++--
src/apps/haikudepot/server/WebAppInterface.cpp | 57 ++++++++++++++--------
src/apps/haikudepot/server/WebAppInterface.h   |  6 +--
src/apps/haikudepot/ui/RatePackageWindow.cpp   |  7 +--

----------------------------------------------------------------------------

diff --git a/src/apps/haikudepot/HaikuDepotConstants.h 
b/src/apps/haikudepot/HaikuDepotConstants.h
index 97014a1d20..752869e0ce 100644
--- a/src/apps/haikudepot/HaikuDepotConstants.h
+++ b/src/apps/haikudepot/HaikuDepotConstants.h
@@ -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
\ No newline at end of file
diff --git a/src/apps/haikudepot/model/Model.cpp 
b/src/apps/haikudepot/model/Model.cpp
index d9758ee0cf..4a2bb36f9f 100644
--- a/src/apps/haikudepot/model/Model.cpp
+++ b/src/apps/haikudepot/model/Model.cpp
@@ -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",
diff --git a/src/apps/haikudepot/server/WebAppInterface.cpp 
b/src/apps/haikudepot/server/WebAppInterface.cpp
index 3928b50d45..218e14c470 100644
--- a/src/apps/haikudepot/server/WebAppInterface.cpp
+++ b/src/apps/haikudepot/server/WebAppInterface.cpp
@@ -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();
diff --git a/src/apps/haikudepot/server/WebAppInterface.h 
b/src/apps/haikudepot/server/WebAppInterface.h
index 4eb8ac29d4..36246235f4 100644
--- a/src/apps/haikudepot/server/WebAppInterface.h
+++ b/src/apps/haikudepot/server/WebAppInterface.h
@@ -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,
diff --git a/src/apps/haikudepot/ui/RatePackageWindow.cpp 
b/src/apps/haikudepot/ui/RatePackageWindow.cpp
index 1743043d29..97ce8c2899 100644
--- a/src/apps/haikudepot/ui/RatePackageWindow.cpp
+++ b/src/apps/haikudepot/ui/RatePackageWindow.cpp
@@ -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


Other related posts:

  • » [haiku-commits] haiku: hrev53468 - in src/apps/haikudepot: server model ui - Andrew Lindesay