Fix IMAP/POP notifications

* Make sure the default Inbox is always notified
* Use correct "new" count for mailbox

Change-Id: Id66c76e415589f6eb6fdad0649ae039fd45c1205
This commit is contained in:
Marc Blank 2012-03-03 10:31:16 -08:00
parent 54c26f9d32
commit bc7f451442
2 changed files with 12 additions and 18 deletions

View File

@ -316,8 +316,7 @@ public class NotificationController {
}
/**
* Registers an observer for changes to the INBOX for the given account. Since accounts
* may only have a single INBOX, we will never have more than one observer for an account.
* Registers an observer for changes to mailboxes in the given account.
* NOTE: This must be called on the notification handler thread.
* @param accountId The ID of the account to register the observer for. May be
* {@link Account#ACCOUNT_ID_COMBINED_VIEW} to register observers for all
@ -340,12 +339,6 @@ public class NotificationController {
} else {
ContentObserver obs = mNotificationMap.get(accountId);
if (obs != null) return; // we're already observing; nothing to do
Mailbox mailbox = Mailbox.restoreMailboxOfType(mContext, accountId, Mailbox.TYPE_INBOX);
if (mailbox == null) {
Log.w(Logging.LOG_TAG, "Could not load INBOX for account id: " + accountId);
return;
}
if (Email.DEBUG) {
Log.i(Logging.LOG_TAG, "Registering for notifications for account " + accountId);
}
@ -717,6 +710,7 @@ public class NotificationController {
try {
while (c.moveToNext()) {
long mailboxId = c.getLong(EmailContent.NOTIFICATION_MAILBOX_ID_COLUMN);
if (mailboxId == 0) continue;
int messageCount =
c.getInt(EmailContent.NOTIFICATION_MAILBOX_MESSAGE_COUNT_COLUMN);
int unreadCount =

View File

@ -1829,29 +1829,29 @@ outer:
mAttachmentService = (as == null) ? DEFAULT_ATTACHMENT_SERVICE : as;
}
// SELECT DISTINCT Boxes._id, Boxes.unreadCount from Message, (SELECT _id, unreadCount,
// messageCount, lastNotifiedMessageCount, lastNotifiedMessageKey
// FROM Mailbox WHERE accountKey=6 AND syncInterval!=0 AND syncInterval!=-1) AS Boxes
// SELECT DISTINCT Boxes._id, Boxes.unreadCount count(Message._id) from Message,
// (SELECT _id, unreadCount, messageCount, lastNotifiedMessageCount, lastNotifiedMessageKey
// FROM Mailbox WHERE accountKey=6 AND ((type = 0) OR (syncInterval!=0 AND syncInterval!=-1)))
// AS Boxes
// WHERE Boxes.messageCount!=Boxes.lastNotifiedMessageCount
// OR (Boxes._id=Message.mailboxKey AND Message._id>Boxes.lastNotifiedMessageKey)
// TODO: This query can be simplified a bit
private static final String NOTIFICATION_QUERY =
"SELECT DISTINCT Boxes." + MailboxColumns.ID + ", Boxes." + MailboxColumns.UNREAD_COUNT +
", Boxes." + MailboxColumns.MESSAGE_COUNT +
", count(" + Message.TABLE_NAME + "." + MessageColumns.ID + ")" +
" FROM " +
Message.TABLE_NAME + "," +
"(SELECT " + MailboxColumns.ID + "," + MailboxColumns.UNREAD_COUNT + "," +
MailboxColumns.MESSAGE_COUNT + "," + MailboxColumns.LAST_NOTIFIED_MESSAGE_COUNT +
"," + MailboxColumns.LAST_NOTIFIED_MESSAGE_KEY + " FROM " + Mailbox.TABLE_NAME +
" WHERE " + MailboxColumns.ACCOUNT_KEY + "=?" +
" AND " + MailboxColumns.SYNC_INTERVAL + "!=0 AND " +
MailboxColumns.SYNC_INTERVAL + "!=-1) AS Boxes " +
"WHERE Boxes." + MailboxColumns.MESSAGE_COUNT + "!=Boxes." +
MailboxColumns.LAST_NOTIFIED_MESSAGE_COUNT +
" OR (Boxes." + MailboxColumns.ID + '=' + Message.TABLE_NAME + "." +
" AND (" + MailboxColumns.TYPE + "=" + Mailbox.TYPE_INBOX + " OR ("
+ MailboxColumns.SYNC_INTERVAL + "!=0 AND " +
MailboxColumns.SYNC_INTERVAL + "!=-1))) AS Boxes " +
"WHERE Boxes." + MailboxColumns.ID + '=' + Message.TABLE_NAME + "." +
MessageColumns.MAILBOX_KEY + " AND " + Message.TABLE_NAME + "." +
MessageColumns.ID + ">Boxes." + MailboxColumns.LAST_NOTIFIED_MESSAGE_KEY +
" AND " + MessageColumns.FLAG_READ + "=0)";
" AND " + MessageColumns.FLAG_READ + "=0";
public Cursor notificationQuery(Uri uri) {
SQLiteDatabase db = getDatabase(getContext());