Geary.RFC822.MessageIDList: Support merging message id lists
Add support for merging a list with a single id or a another list, only appending the new id(s) if not already present. Add unit tests.
This commit is contained in:
parent
c41515a2c7
commit
c73888b2c4
2 changed files with 42 additions and 0 deletions
|
|
@ -210,6 +210,34 @@ public class Geary.RFC822.MessageIDList :
|
|||
return this.list.read_only_view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list with the given id appended if not already present.
|
||||
*
|
||||
* This list is returned if the given id is already present,
|
||||
* otherwise the result of a call to {@link concatenate_id} is
|
||||
* returned.
|
||||
*/
|
||||
public MessageIDList merge_id(MessageID other) {
|
||||
return this.list.contains(other) ? this : this.concatenate_id(other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list with the given ids appended if not already present.
|
||||
*
|
||||
* This list is returned if all given ids are already present,
|
||||
* otherwise the result of a call to {@link concatenate_id} for
|
||||
* each not present is returned.
|
||||
*/
|
||||
public MessageIDList merge_list(MessageIDList other) {
|
||||
var list = this;
|
||||
foreach (var id in other) {
|
||||
if (!this.list.contains(id)) {
|
||||
list = list.concatenate_id(id);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new list with the given list appended to this.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ class Geary.RFC822.MessageDataTest : TestCase {
|
|||
add_test("header_names_from_rfc822", header_names_from_rfc822);
|
||||
add_test("PreviewText.with_header", preview_text_with_header);
|
||||
add_test("MessageIDList.from_rfc822_string", message_id_list_from_rfc822_string);
|
||||
add_test("MessageIdList.merge", message_id_list_merge);
|
||||
}
|
||||
|
||||
public void preview_text_with_header() throws GLib.Error {
|
||||
|
|
@ -213,6 +214,19 @@ class Geary.RFC822.MessageDataTest : TestCase {
|
|||
.contains(new MessageID("id2@example.com"));
|
||||
}
|
||||
|
||||
public void message_id_list_merge() throws GLib.Error {
|
||||
var a1 = new MessageID("a");
|
||||
var b = new MessageID("b");
|
||||
var a2 = new MessageID("a");
|
||||
var list = new MessageIDList.single(a1);
|
||||
|
||||
assert_equal<int?>(list.merge_id(b).size, 2);
|
||||
assert_equal<int?>(list.merge_id(a2).size, 1);
|
||||
|
||||
assert_equal<int?>(list.merge_list(new MessageIDList.single(b)).size, 2);
|
||||
assert_equal<int?>(list.merge_list(new MessageIDList.single(a2)).size, 1);
|
||||
}
|
||||
|
||||
|
||||
private const string HEADER_FIXTURE = """From: Test <test@example.com>
|
||||
Subject: test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue