[Xfce4-commits] <postler:master> Introduce GetThread to build conversations
Christian Dywan
noreply at xfce.org
Thu Jun 23 21:00:05 CEST 2011
Updating branch refs/heads/master
to 48059b241111109411e3bcc2085974a310322df3 (commit)
from d85170b4da8ff33fb87dec413e46199b267bec13 (commit)
commit 48059b241111109411e3bcc2085974a310322df3
Author: Christian Dywan <christian at twotoasts.de>
Date: Sun Jun 19 21:34:40 2011 +0200
Introduce GetThread to build conversations
postler/postler-client.vala | 21 +++++++++++++++++++++
postler/postler-index.vala | 26 ++++++++++++++++++++++++++
postler/postler-message.vala | 8 +++++---
postler/postler-service.vala | 4 ++++
4 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/postler/postler-client.vala b/postler/postler-client.vala
index 0ec9c75..2fb27bb 100644
--- a/postler/postler-client.vala
+++ b/postler/postler-client.vala
@@ -16,6 +16,7 @@ namespace Postler {
public async abstract int64 unread_messages (string uri) throws IOError;
public async abstract GLib.HashTable<string,Variant> get_message (string id,
char flag) throws IOError;
+ public async abstract string[] get_thread (string thread) throws IOError;
public signal void got_message (GLib.HashTable<string,Variant> message, int64 position);
public async abstract string[] get_messages (string uri) throws IOError;
public signal void progress (string account, string text, double fraction);
@@ -77,6 +78,26 @@ namespace Postler {
row.get_model ().row_changed (row.get_path (), iter);
}
+ public async GLib.List<Message> get_thread (Message parent) throws GLib.Error {
+ var messages = new GLib.List<Message> ();
+ try {
+ string[] ids = yield client.get_thread (parent.id);
+ foreach (string message_id in ids) {
+ var child = new Message.from_id (message_id);
+ child.from_hash_table (yield client.get_message (child.id, MessageFlags.NONE));
+ stdout.printf ("A %s %s\n", child.id, child.subject);
+ messages.append (child);
+ }
+ }
+ catch (GLib.Error error) {
+ var message = new Message.from_id ("error:");
+ message.from_error (error.message.replace (
+ "org.gtk.GDBus.UnmappedGError.Quark._g_2dfile_2derror_2dquark.Code24", "GLib.FileError"));
+ messages.append (message);
+ }
+ return messages;
+ }
+
public signal void got_message (Message message, int64 position);
public async GLib.List<Message> get_messages (string uri) throws GLib.Error {
diff --git a/postler/postler-index.vala b/postler/postler-index.vala
index 524b8fc..2178618 100644
--- a/postler/postler-index.vala
+++ b/postler/postler-index.vala
@@ -14,6 +14,7 @@ namespace Postler {
static Sqlite.Database? database = null;
static Sqlite.Statement? statement_insert = null;
static Sqlite.Statement? statement_get = null;
+ static Sqlite.Statement? statement_thread = null;
static Sqlite.Statement? statement_list = null;
static Sqlite.Statement? statement_position = null;
static Sqlite.Statement? statement_count = null;
@@ -189,6 +190,31 @@ namespace Postler {
return message;
}
+ public string[] get_thread (string thread) throws GLib.Error {
+ if (statement_thread == null) {
+ if (database.prepare_v2 ("""
+ SELECT id FROM messages WHERE threads = ?1 ORDER BY date ASC
+ """,
+ -1, out statement_thread) != Sqlite.OK)
+ throw new GLib.FileError.FAILED (_("Failed to thread messages: %s"), database.errmsg ());
+ }
+ int result = Sqlite.ERROR;
+ bool success =
+ statement_thread.bind_text (1, thread, -1) == Sqlite.OK
+ && row_or_done (((result = statement_thread.step ())));
+ if (!success) {
+ statement_thread.reset ();
+ throw new GLib.FileError.FAILED (_("Failed to thread messages: %s"), database.errmsg ());
+ }
+ string[] ids = {};
+ while (result == Sqlite.ROW) {
+ ids += statement_thread.column_text (0);
+ result = statement_thread.step ();
+ }
+ statement_thread.reset ();
+ return ids;
+ }
+
public string[] get_messages (string folder) throws GLib.Error {
if (statement_list == null) {
if (database.prepare_v2 ("""
diff --git a/postler/postler-message.vala b/postler/postler-message.vala
index 7857dbc..2b5e86f 100644
--- a/postler/postler-message.vala
+++ b/postler/postler-message.vala
@@ -184,7 +184,7 @@ namespace Postler {
threads = message_id.slice (1, -1);
}
}
- else if (field == "references") {
+ /* else if (field == "references") {
string[] message_ids = parts[1].split_set (", \t");
string[] parsed_ids = {};
foreach (string message_id in message_ids) {
@@ -195,8 +195,7 @@ namespace Postler {
threads = string.joinv (",", parsed_ids) + "," + threads;
else
threads = string.joinv (",", parsed_ids);
- }
- else if (field == "subject")
+ } */
subject = parse_encoded (parts[1], out charset);
else if (field == "from") {
string sender_charset = null;
@@ -251,6 +250,9 @@ namespace Postler {
if (id == null)
throw new GLib.FileError.FAILED (_("Failed to find valid message ID"));
+ /* Treat top-levels like replies to themselves */
+ if (threads == null)
+ threads = id;
recipients = parse_encoded (recipients, out charset);
diff --git a/postler/postler-service.vala b/postler/postler-service.vala
index 6e5f0f2..ca578a9 100644
--- a/postler/postler-service.vala
+++ b/postler/postler-service.vala
@@ -398,6 +398,10 @@ namespace Postler {
return message.to_hash_table ();
}
+ public string[] get_thread (string thread) throws GLib.Error {
+ return index.get_thread (thread);
+ }
+
public signal void got_message (GLib.HashTable<string,Variant> message, int64 position);
public string[] get_messages (string uri) throws GLib.Error {
More information about the Xfce4-commits
mailing list