[gnome-software: 4/25] gs-odrs-provider: Move the refine_app() helper function
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 4/25] gs-odrs-provider: Move the refine_app() helper function
- Date: Tue, 1 Mar 2022 12:28:12 +0000 (UTC)
commit 9b619be5bcc5992791dbb2bede8837b78ae15528
Author: Philip Withnall <pwithnall endlessos org>
Date: Wed Feb 23 14:21:28 2022 +0000
gs-odrs-provider: Move the refine_app() helper function
This moves it closer to where it’s used.
The code isn’t changed at all.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Helps: #1658
lib/gs-odrs-provider.c | 124 ++++++++++++++++++++++++++-----------------------
1 file changed, 65 insertions(+), 59 deletions(-)
---
diff --git a/lib/gs-odrs-provider.c b/lib/gs-odrs-provider.c
index 11fb86db1..a90aeed87 100644
--- a/lib/gs-odrs-provider.c
+++ b/lib/gs-odrs-provider.c
@@ -819,65 +819,6 @@ gs_odrs_provider_fetch_for_app (GsOdrsProvider *self,
return g_steal_pointer (&reviews);
}
-static gboolean
-refine_app (GsOdrsProvider *self,
- GsApp *app,
- GsOdrsProviderRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
-{
- /* not valid */
- if (gs_app_get_kind (app) == AS_COMPONENT_KIND_ADDON)
- return TRUE;
- if (gs_app_get_id (app) == NULL)
- return TRUE;
-
- /* add reviews if possible */
- if (flags & GS_ODRS_PROVIDER_REFINE_FLAGS_GET_REVIEWS) {
- AsReview *review;
- g_autoptr(GPtrArray) reviews = NULL;
-
- if (gs_app_get_reviews (app)->len > 0)
- return TRUE;
-
- /* get from server */
- reviews = gs_odrs_provider_fetch_for_app (self, app, cancellable, error);
- if (reviews == NULL)
- return FALSE;
- for (guint i = 0; i < reviews->len; i++) {
- review = g_ptr_array_index (reviews, i);
-
- /* save this on the application object so we can use it for
- * submitting a new review */
- if (i == 0) {
- gs_app_set_metadata (app, "ODRS::user_skey",
- as_review_get_metadata_item (review, "user_skey"));
- }
-
- /* ignore invalid reviews */
- if (as_review_get_rating (review) == 0)
- continue;
-
- /* the user_hash matches, so mark this as our own review */
- if (g_strcmp0 (as_review_get_reviewer_id (review),
- self->user_hash) == 0) {
- as_review_set_flags (review, AS_REVIEW_FLAG_SELF);
- }
- gs_app_add_review (app, review);
- }
- }
-
- /* add ratings if possible */
- if (flags & GS_ODRS_PROVIDER_REFINE_FLAGS_GET_RATINGS) {
- if (gs_app_get_review_ratings (app) != NULL)
- return TRUE;
- if (!gs_odrs_provider_refine_ratings (self, app, cancellable, error))
- return FALSE;
- }
-
- return TRUE;
-}
-
static gchar *
gs_odrs_provider_trim_version (const gchar *version)
{
@@ -1373,6 +1314,12 @@ gs_odrs_provider_refresh_ratings_finish (GsOdrsProvider *self,
return g_task_propagate_boolean (G_TASK (result), error);
}
+static gboolean refine_app (GsOdrsProvider *self,
+ GsApp *app,
+ GsOdrsProviderRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error);
+
/**
* gs_odrs_provider_refine:
* @self: a #GsOdrsProvider
@@ -1416,6 +1363,65 @@ gs_odrs_provider_refine (GsOdrsProvider *self,
return TRUE;
}
+static gboolean
+refine_app (GsOdrsProvider *self,
+ GsApp *app,
+ GsOdrsProviderRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ /* not valid */
+ if (gs_app_get_kind (app) == AS_COMPONENT_KIND_ADDON)
+ return TRUE;
+ if (gs_app_get_id (app) == NULL)
+ return TRUE;
+
+ /* add reviews if possible */
+ if (flags & GS_ODRS_PROVIDER_REFINE_FLAGS_GET_REVIEWS) {
+ AsReview *review;
+ g_autoptr(GPtrArray) reviews = NULL;
+
+ if (gs_app_get_reviews (app)->len > 0)
+ return TRUE;
+
+ /* get from server */
+ reviews = gs_odrs_provider_fetch_for_app (self, app, cancellable, error);
+ if (reviews == NULL)
+ return FALSE;
+ for (guint i = 0; i < reviews->len; i++) {
+ review = g_ptr_array_index (reviews, i);
+
+ /* save this on the application object so we can use it for
+ * submitting a new review */
+ if (i == 0) {
+ gs_app_set_metadata (app, "ODRS::user_skey",
+ as_review_get_metadata_item (review, "user_skey"));
+ }
+
+ /* ignore invalid reviews */
+ if (as_review_get_rating (review) == 0)
+ continue;
+
+ /* the user_hash matches, so mark this as our own review */
+ if (g_strcmp0 (as_review_get_reviewer_id (review),
+ self->user_hash) == 0) {
+ as_review_set_flags (review, AS_REVIEW_FLAG_SELF);
+ }
+ gs_app_add_review (app, review);
+ }
+ }
+
+ /* add ratings if possible */
+ if (flags & GS_ODRS_PROVIDER_REFINE_FLAGS_GET_RATINGS) {
+ if (gs_app_get_review_ratings (app) != NULL)
+ return TRUE;
+ if (!gs_odrs_provider_refine_ratings (self, app, cancellable, error))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
/**
* gs_odrs_provider_submit_review:
* @self: a #GsOdrsProvider
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]