[geary/mjog/search-refinement: 2/14] Make Geary.EmailIdentifier serialisation a bit less ad-hoc



commit 981ea845f4ec1ac2f69aadbce4056f65368ec0e6
Author: Michael Gratton <mike vee net>
Date:   Tue Dec 10 13:15:32 2019 +1100

    Make Geary.EmailIdentifier serialisation a bit less ad-hoc
    
    Require EmailIdentifier implementations to use an outer GVariant of the
    form `(yr)` (that is, a byte and an arbitrary length tuple), so that
    inner representations are independent of the outer format.

 src/engine/api/geary-email-identifier.vala                |  2 +-
 src/engine/imap-db/imap-db-email-identifier.vala          | 13 ++++++++-----
 src/engine/outbox/outbox-email-identifier.vala            | 15 +++++++++------
 .../imap-engine/imap-engine-generic-account-test.vala     | 12 ++++++++++--
 4 files changed, 28 insertions(+), 14 deletions(-)
---
diff --git a/src/engine/api/geary-email-identifier.vala b/src/engine/api/geary-email-identifier.vala
index e1df28ed..cdea6a7b 100644
--- a/src/engine/api/geary-email-identifier.vala
+++ b/src/engine/api/geary-email-identifier.vala
@@ -21,7 +21,7 @@
 public abstract class Geary.EmailIdentifier : BaseObject, Gee.Hashable<Geary.EmailIdentifier> {
 
     /** Base variant type returned by {@link to_variant}. */
-    public const string BASE_VARIANT_TYPE = "(y??)";
+    public const string BASE_VARIANT_TYPE = "(yr)";
 
     // Warning: only change this if you know what you are doing.
     protected string unique;
diff --git a/src/engine/imap-db/imap-db-email-identifier.vala 
b/src/engine/imap-db/imap-db-email-identifier.vala
index 9829d52d..cb2c5dc1 100644
--- a/src/engine/imap-db/imap-db-email-identifier.vala
+++ b/src/engine/imap-db/imap-db-email-identifier.vala
@@ -9,7 +9,7 @@
 private class Geary.ImapDB.EmailIdentifier : Geary.EmailIdentifier {
 
 
-    private const string VARIANT_TYPE = "(yxx)";
+    private const string VARIANT_TYPE = "(y(xx))";
 
 
     public int64 message_id { get; private set; }
@@ -41,12 +41,13 @@ private class Geary.ImapDB.EmailIdentifier : Geary.EmailIdentifier {
                 "Invalid serialised id type: %s", serialised.get_type_string()
             );
         }
+        GLib.Variant inner = serialised.get_child_value(1);
         Imap.UID? uid = null;
-        int64 uid_value = serialised.get_child_value(2).get_int64();
+        int64 uid_value = inner.get_child_value(1).get_int64();
         if (uid_value >= 0) {
             uid = new Imap.UID(uid_value);
         }
-        this(serialised.get_child_value(1).get_int64(), uid);
+        this(inner.get_child_value(0).get_int64(), uid);
     }
 
     // Used to promote an id created with no_message_id to one that has a
@@ -84,8 +85,10 @@ private class Geary.ImapDB.EmailIdentifier : Geary.EmailIdentifier {
         int64 uid_value = this.uid != null ? this.uid.value : -1;
         return new GLib.Variant.tuple(new Variant[] {
                 new GLib.Variant.byte('i'),
-                new GLib.Variant.int64(this.message_id),
-                new GLib.Variant.int64(uid_value)
+                new GLib.Variant.tuple(new Variant[] {
+                        new GLib.Variant.int64(this.message_id),
+                        new GLib.Variant.int64(uid_value)
+                    })
             });
     }
 
diff --git a/src/engine/outbox/outbox-email-identifier.vala b/src/engine/outbox/outbox-email-identifier.vala
index cf12b751..63b6f67c 100644
--- a/src/engine/outbox/outbox-email-identifier.vala
+++ b/src/engine/outbox/outbox-email-identifier.vala
@@ -9,7 +9,7 @@
 private class Geary.Outbox.EmailIdentifier : Geary.EmailIdentifier {
 
 
-    private const string VARIANT_TYPE = "(yxx)";
+    private const string VARIANT_TYPE = "(y(xx))";
 
     public int64 message_id { get; private set; }
     public int64 ordering { get; private set; }
@@ -28,9 +28,10 @@ private class Geary.Outbox.EmailIdentifier : Geary.EmailIdentifier {
                 "Invalid serialised id type: %s", serialised.get_type_string()
             );
         }
-        GLib.Variant mid = serialised.get_child_value(1);
-        GLib.Variant uid = serialised.get_child_value(2);
-        this(mid.get_int64(), uid.get_int64());
+        GLib.Variant inner = serialised.get_child_value(1);
+        GLib.Variant mid = inner.get_child_value(0);
+        GLib.Variant ord = inner.get_child_value(1);
+        this(mid.get_int64(), ord.get_int64());
     }
 
     public override int natural_sort_comparator(Geary.EmailIdentifier o) {
@@ -46,8 +47,10 @@ private class Geary.Outbox.EmailIdentifier : Geary.EmailIdentifier {
         // inform GenericAccount that it's an SMTP id.
         return new GLib.Variant.tuple(new Variant[] {
                 new GLib.Variant.byte('o'),
-                new GLib.Variant.int64(this.message_id),
-                new GLib.Variant.int64(this.ordering)
+                new GLib.Variant.tuple(new Variant[] {
+                        new GLib.Variant.int64(this.message_id),
+                        new GLib.Variant.int64(this.ordering)
+                    })
             });
     }
 
diff --git a/test/engine/imap-engine/imap-engine-generic-account-test.vala 
b/test/engine/imap-engine/imap-engine-generic-account-test.vala
index 54829e15..b22af954 100644
--- a/test/engine/imap-engine/imap-engine-generic-account-test.vala
+++ b/test/engine/imap-engine/imap-engine-generic-account-test.vala
@@ -86,10 +86,18 @@ public class Geary.ImapEngine.GenericAccountTest : TestCase {
         );
 
         assert_non_null(
-            test_article.to_email_identifier(new GLib.Variant("(yxx)", 'i', 1, 2))
+            test_article.to_email_identifier(
+                new GLib.Variant(
+                    "(yr)", 'i', new GLib.Variant("(xx)", 1, 2)
+                )
+            )
         );
         assert_non_null(
-            test_article.to_email_identifier(new GLib.Variant("(yxx)", 'o', 1, 2))
+            test_article.to_email_identifier(
+                new GLib.Variant(
+                    "(yr)", 'o', new GLib.Variant("(xx)", 1, 2)
+                )
+            )
         );
     }
 


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