[epiphany/wip/ephy-sync: 121/126] sync-bookmarks: Don't delete the dummy BSO from the server



commit 94a550c6138538bdaf51425c37f8a9026d57ddd4
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date:   Mon Aug 15 13:29:41 2016 +0300

    sync-bookmarks: Don't delete the dummy BSO from the server

 src/ephy-sync-bookmarks.c |   48 +++++++++++++++------------------------------
 1 files changed, 16 insertions(+), 32 deletions(-)
---
diff --git a/src/ephy-sync-bookmarks.c b/src/ephy-sync-bookmarks.c
index 0730a56..cb0d275 100644
--- a/src/ephy-sync-bookmarks.c
+++ b/src/ephy-sync-bookmarks.c
@@ -22,7 +22,7 @@
 #include "ephy-debug.h"
 #include "ephy-shell.h"
 
-#define EPHY_BOOKMARKS_DUMMY_BSO   "000000000000"
+#define DUMMY_BOOKMARK_ID          "00000000000000000000000000000000"
 #define EPHY_BOOKMARKS_COLLECTION  "ephy-bookmarks"
 
 static void
@@ -61,45 +61,19 @@ get_storage_endpoint_for_bookmark (EphyBookmark *bookmark)
 }
 
 static void
-delete_dummy_bso_response_cb (SoupSession *session,
-                              SoupMessage *message,
-                              gpointer     user_data)
-{
-  EphySyncService *service;
-
-  if (message->status_code != 200)
-    warning_alert ("Failed to delete the dummy BSO", message);
-
-  service = ephy_shell_get_global_sync_service (ephy_shell_get_default ());
-  ephy_sync_service_release_next_storage_message (service);
-}
-
-static void
 create_bso_collection_response_cb (SoupSession *session,
                                    SoupMessage *message,
                                    gpointer     user_data)
 {
   EphySyncService *service;
-  gchar *endpoint;
 
-  service = ephy_shell_get_global_sync_service (ephy_shell_get_default ());
-
-  /* Status code 412 means the BSO already exists. Since we will delete it
-   * anyway, we don't treat this as an error.
-   */
+  /* Code 412 means that the BSO already exists. Don't treat this as an error. */
   if (message->status_code != 200 && message->status_code != 412) {
     warning_alert ("Failed to add dummy BSO to collection", message);
     return;
   }
 
-  /* The EPHY_BOOKMARKS_COLLECTION collection is now created. We can safely
-   * delete the dummy BSO that we've uploaded.
-   */
-  endpoint = g_strdup_printf ("storage/%s/%s", EPHY_BOOKMARKS_COLLECTION, EPHY_BOOKMARKS_DUMMY_BSO);
-  ephy_sync_service_send_storage_message (service, endpoint, SOUP_METHOD_DELETE,
-                                          NULL, -1, -1,
-                                          delete_dummy_bso_response_cb, NULL);
-  g_free (endpoint);
+  service = ephy_shell_get_global_sync_service (ephy_shell_get_default ());
   ephy_sync_service_release_next_storage_message (service);
 }
 
@@ -107,16 +81,20 @@ void
 ephy_sync_bookmarks_create_storage_collection (void)
 {
   EphySyncService *service;
+  EphyBookmark *dummy;
   gchar *endpoint;
   gchar *bso;
 
   service = ephy_shell_get_global_sync_service (ephy_shell_get_default ());
-  endpoint = g_strdup_printf ("storage/%s/%s", EPHY_BOOKMARKS_COLLECTION, EPHY_BOOKMARKS_DUMMY_BSO);
-  bso = ephy_sync_utils_create_bso_json (EPHY_BOOKMARKS_DUMMY_BSO, EPHY_BOOKMARKS_DUMMY_BSO);
+  endpoint = g_strdup_printf ("storage/%s/%s", EPHY_BOOKMARKS_COLLECTION, DUMMY_BOOKMARK_ID);
+  dummy = ephy_bookmark_new (g_strdup (DUMMY_BOOKMARK_ID),
+                             g_strdup (DUMMY_BOOKMARK_ID),
+                             g_sequence_new (g_free));
+  ephy_bookmark_set_id (dummy, DUMMY_BOOKMARK_ID);
+  bso = ephy_bookmark_to_bso (dummy);
 
   /* Send a dummy BSO to the Storage Server so it will create the
    * EPHY_BOOKMARKS_COLLECTION collection if it doesn't exist already.
-   * In the response callback we will delete the dummy BSO.
    */
   ephy_sync_service_send_storage_message (service, endpoint, SOUP_METHOD_PUT,
                                           bso, -1, 0,
@@ -206,6 +184,12 @@ merge_locals_with_remotes_response_cb (SoupSession *session,
   for (i = 0; i < json_array_get_length (array); i++) {
     JsonObject *bso = json_array_get_object_element (array, i);
     EphyBookmark *bookmark = ephy_bookmark_from_bso (bso);
+
+    if (g_strcmp0 (ephy_bookmark_get_id (bookmark), DUMMY_BOOKMARK_ID) == 0) {
+      g_object_unref (bookmark);
+      continue;
+    }
+
     remotes = g_list_append (remotes, bookmark);
   }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]