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.
This commit is contained in:
Michael Gratton 2019-12-10 13:15:32 +11:00 committed by Michael James Gratton
parent c93cfc38b1
commit 981ea845f4
4 changed files with 28 additions and 14 deletions

View file

@ -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;

View file

@ -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)
})
});
}

View file

@ -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)
})
});
}

View file

@ -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)
)
)
);
}