From dc26b19aac8cc013d89a9752a911309e885a4f31 Mon Sep 17 00:00:00 2001 From: Eric Gregory Date: Fri, 21 Jun 2013 18:20:56 -0700 Subject: [PATCH] Closes #7120 Store and update unseen count in database --- sql/CMakeLists.txt | 1 + sql/version-010.sql | 5 +++++ src/engine/imap-db/imap-db-account.vala | 15 +++++++++------ 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 sql/version-010.sql diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 02cc18f9..be95f314 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -9,3 +9,4 @@ install(FILES version-006.sql DESTINATION ${SQL_DEST}) install(FILES version-007.sql DESTINATION ${SQL_DEST}) install(FILES version-008.sql DESTINATION ${SQL_DEST}) install(FILES version-009.sql DESTINATION ${SQL_DEST}) +install(FILES version-010.sql DESTINATION ${SQL_DEST}) diff --git a/sql/version-010.sql b/sql/version-010.sql new file mode 100644 index 00000000..120f6b81 --- /dev/null +++ b/sql/version-010.sql @@ -0,0 +1,5 @@ +-- +-- Add unread count column to the FolderTable +-- + +ALTER TABLE FolderTable ADD COLUMN unread_count INTEGER DEFAULT 0; diff --git a/src/engine/imap-db/imap-db-account.vala b/src/engine/imap-db/imap-db-account.vala index 25f58b63..d246fd59 100644 --- a/src/engine/imap-db/imap-db-account.vala +++ b/src/engine/imap-db/imap-db-account.vala @@ -107,7 +107,7 @@ private class Geary.ImapDB.Account : BaseObject { // create the folder object Db.Statement stmt = cx.prepare( "INSERT INTO FolderTable (name, parent_id, last_seen_total, last_seen_status_total, " - + "uid_validity, uid_next, attributes) VALUES (?, ?, ?, ?, ?, ?, ?)"); + + "uid_validity, uid_next, attributes, unread_count) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); stmt.bind_string(0, path.basename); stmt.bind_rowid(1, parent_id); stmt.bind_int(2, Numeric.int_floor(properties.select_examine_messages, 0)); @@ -117,6 +117,7 @@ private class Geary.ImapDB.Account : BaseObject { stmt.bind_int64(5, (properties.uid_next != null) ? properties.uid_next.value : Imap.UID.INVALID); stmt.bind_string(6, properties.attrs.serialize()); + stmt.bind_int(7, properties.email_unread); stmt.exec(cancellable); @@ -146,15 +147,17 @@ private class Geary.ImapDB.Account : BaseObject { Db.Statement stmt; if (parent_id != Db.INVALID_ROWID) { stmt = cx.prepare( - "UPDATE FolderTable SET attributes=? WHERE parent_id=? AND name=?"); + "UPDATE FolderTable SET attributes=?, unread_count=? WHERE parent_id=? AND name=?"); stmt.bind_string(0, properties.attrs.serialize()); - stmt.bind_rowid(1, parent_id); - stmt.bind_string(2, path.basename); + stmt.bind_int(1, properties.email_unread); + stmt.bind_rowid(2, parent_id); + stmt.bind_string(3, path.basename); } else { stmt = cx.prepare( - "UPDATE FolderTable SET attributes=? WHERE parent_id IS NULL AND name=?"); + "UPDATE FolderTable SET attributes=?, unread_count=? WHERE parent_id IS NULL AND name=?"); stmt.bind_string(0, properties.attrs.serialize()); - stmt.bind_string(1, path.basename); + stmt.bind_int(1, properties.email_unread); + stmt.bind_string(2, path.basename); } stmt.exec();