Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/ConversationList/ConversationItemModel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,10 @@ public class Mail.ConversationItemModel : GLib.Object {

return has_flag;
}

public static int compare_func (Object a, Object b) {
var item1 = (ConversationItemModel) a;
var item2 = (ConversationItemModel) b;
return (int)(item2.timestamp - item1.timestamp);
}
}
7 changes: 1 addition & 6 deletions src/ConversationList/ConversationList.vala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class Mail.ConversationList : Gtk.Box {
folder_info_flags = new Gee.HashMap<string, Camel.FolderInfoFlags> ();
threads = new Gee.HashMap<string, Camel.FolderThread> ();
list_store = new ConversationListStore ();
list_store.set_sort_func (thread_sort_function);
list_store.set_filter_func (filter_function);

list_box = new VirtualizingListBox () {
Expand Down Expand Up @@ -414,7 +413,7 @@ public class Mail.ConversationList : Gtk.Box {
private void add_conversation_item (Camel.FolderInfoFlags folder_info_flags, Camel.FolderThreadNode child, Camel.FolderThread thread, string service_uid) {
var item = new ConversationItemModel (folder_info_flags, child, thread, service_uid);
conversations[child.message.uid] = item;
list_store.add (item);
list_store.insert_sorted (item, ConversationItemModel.compare_func);
}

private static bool filter_function (GLib.Object obj) {
Expand All @@ -426,10 +425,6 @@ public class Mail.ConversationList : Gtk.Box {
}
}

private static int thread_sort_function (ConversationItemModel item1, ConversationItemModel item2) {
return (int)(item2.timestamp - item1.timestamp);
}

public void mark_read_selected_messages () {
var selected_rows = list_box.get_selected_rows ();
foreach (var row in selected_rows) {
Expand Down
25 changes: 6 additions & 19 deletions src/ConversationList/ConversationListStore.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,20 @@ public class Mail.ConversationListStore : ListModel, Object {
private GLib.Sequence<ConversationItemModel> data = new GLib.Sequence<ConversationItemModel> ();
private uint last_position = uint.MAX;
private GLib.SequenceIter<ConversationItemModel>? last_iter;
private unowned GLib.CompareDataFunc<ConversationItemModel> compare_func;
private unowned RowVisibilityFunc filter_func;

public GLib.Type get_item_type () {
private GLib.Type get_item_type () {
return typeof (GLib.Object);
}

public uint get_n_items () {
return data.get_length ();
}

public GLib.Object? get_item (uint index) {
private GLib.Object? get_item (uint index) {
return get_item_internal (index);
}

public GLib.Object? get_item_unfiltered (uint index) {
return get_item_internal (index, true);
}

private GLib.Object? get_item_internal (uint index, bool unfiltered = false) {
GLib.SequenceIter<ConversationItemModel>? iter = null;

Expand Down Expand Up @@ -81,12 +76,8 @@ public class Mail.ConversationListStore : ListModel, Object {
}
}

public void add (ConversationItemModel data) {
if (compare_func != null) {
this.data.insert_sorted (data, compare_func);
} else {
this.data.append (data);
}
public void insert_sorted (ConversationItemModel item, CompareDataFunc<Object> compare_func) {
data.insert_sorted (item, compare_func);

last_iter = null;
last_position = uint.MAX;
Expand All @@ -108,10 +99,6 @@ public class Mail.ConversationListStore : ListModel, Object {
last_position = uint.MAX;
}

public void set_sort_func (GLib.CompareDataFunc<ConversationItemModel> function) {
this.compare_func = function;
}

public void set_filter_func (RowVisibilityFunc? function) {
filter_func = function;
}
Expand Down Expand Up @@ -175,14 +162,14 @@ public class Mail.ConversationListStore : ListModel, Object {
return -1;
}

public int get_index_of_unfiltered (GLib.Object? item) {
private int get_index_of_unfiltered (GLib.Object? item) {
if (item == null) {
return -1;
}

var length = get_n_items ();
for (int i = 0; i < length; i++) {
if (item == get_item_unfiltered (i)) {
if (item == get_item_internal (i, true)) {
return i;
}
}
Expand Down