Don't show non-incoming message in notification.
Filter out non-incoming messages using a subquery. (because the message table doen't have the mailbox type.) I was initially thinking of adding a new content URL for the message table joined with the mailbox table, but it turned out to be a bit of pain, so ended up using a subquery. (one of the problems was that both tables had the "_id" field.) Bug 3177220 Change-Id: I276efb70db1589835f3ddb8c7da4773e72d8691b
This commit is contained in:
parent
d12e56d321
commit
6f3d167cfa
@ -158,7 +158,7 @@ public class NotificationController {
|
||||
return null;
|
||||
}
|
||||
// Get the latest message
|
||||
final Message message = Message.getLatestMessage(mContext, accountId);
|
||||
final Message message = Message.getLatestIncomingMessage(mContext, accountId);
|
||||
if (message == null) {
|
||||
return null; // no message found???
|
||||
}
|
||||
|
@ -91,8 +91,7 @@ import java.security.InvalidParameterException;
|
||||
private static final int COLUMN_ROW_TYPE = 6;
|
||||
|
||||
private static final String MAILBOX_SELECTION = MailboxColumns.ACCOUNT_KEY + "=?" +
|
||||
" AND " + MailboxColumns.TYPE + "<" + Mailbox.TYPE_NOT_EMAIL +
|
||||
" AND " + MailboxColumns.FLAG_VISIBLE + "=1";
|
||||
" AND " + Mailbox.USER_VISIBLE_MAILBOX_SELECTION;
|
||||
|
||||
private static final String MAILBOX_SELECTION_MOVE_TO_FOLDER =
|
||||
MAILBOX_SELECTION + " AND " + Mailbox.MOVE_TO_TARGET_MAILBOX_SELECTION;
|
||||
|
@ -543,6 +543,21 @@ public abstract class EmailContent {
|
||||
private static final String ACCOUNT_KEY_SELECTION =
|
||||
MessageColumns.ACCOUNT_KEY + "=?";
|
||||
|
||||
/**
|
||||
* Selection for latest incoming messages. In order to tell whether incoming or not,
|
||||
* we need the mailbox type, which is in the mailbox table, not the message table, so
|
||||
* use a subquery.
|
||||
*/
|
||||
private static final String LATEST_INCOMING_MESSAGE_SELECTION =
|
||||
MessageColumns.MAILBOX_KEY + " IN (SELECT " + RECORD_ID + " FROM " + Mailbox.TABLE_NAME
|
||||
+ " WHERE " + MailboxColumns.ACCOUNT_KEY + "=? AND "
|
||||
+ Mailbox.USER_VISIBLE_MAILBOX_SELECTION + " AND "
|
||||
+ MailboxColumns.TYPE + " NOT IN ("
|
||||
+ Mailbox.TYPE_DRAFTS + ","
|
||||
+ Mailbox.TYPE_OUTBOX + ","
|
||||
+ Mailbox.TYPE_SENT
|
||||
+ "))";
|
||||
|
||||
// _id field is in AbstractContent
|
||||
public String mDisplayName;
|
||||
public long mTimeStamp;
|
||||
@ -851,10 +866,10 @@ public abstract class EmailContent {
|
||||
/**
|
||||
* @return the latest messages on an account.
|
||||
*/
|
||||
public static Message getLatestMessage(Context context, Long accountId) {
|
||||
public static Message getLatestIncomingMessage(Context context, Long accountId) {
|
||||
Cursor c = context.getContentResolver().query(Message.CONTENT_URI_LIMIT_1,
|
||||
Message.CONTENT_PROJECTION,
|
||||
ACCOUNT_KEY_SELECTION, new String[] {Long.toString(accountId)},
|
||||
LATEST_INCOMING_MESSAGE_SELECTION, new String[] {Long.toString(accountId)},
|
||||
EmailContent.MessageColumns.TIMESTAMP + " DESC");
|
||||
try {
|
||||
if (c.moveToFirst()) {
|
||||
@ -2210,6 +2225,9 @@ public abstract class EmailContent {
|
||||
public static final Integer[] INVALID_DROP_TARGETS = new Integer[] {Mailbox.TYPE_DRAFTS,
|
||||
Mailbox.TYPE_OUTBOX, Mailbox.TYPE_SENT};
|
||||
|
||||
public static final String USER_VISIBLE_MAILBOX_SELECTION =
|
||||
MailboxColumns.TYPE + "<" + Mailbox.TYPE_NOT_EMAIL +
|
||||
" AND " + MailboxColumns.FLAG_VISIBLE + "=1";
|
||||
|
||||
// Types of mailboxes. The list is ordered to match a typical UI presentation, e.g.
|
||||
// placing the inbox at the top.
|
||||
|
@ -2231,7 +2231,7 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
|
||||
return m;
|
||||
}
|
||||
|
||||
public void testMessageGetLatestMessage() {
|
||||
public void testMessageGetLatestIncomingMessage() {
|
||||
final Context c = mMockContext;
|
||||
|
||||
// Create 2 accounts with a inbox.
|
||||
@ -2239,22 +2239,28 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
|
||||
Account a2 = ProviderTestUtils.setupAccount("a2", true, c);
|
||||
|
||||
Mailbox b1 = ProviderTestUtils.setupMailbox("box1", a1.mId, true, c, Mailbox.TYPE_INBOX);
|
||||
Mailbox b2 = ProviderTestUtils.setupMailbox("box3", a2.mId, true, c, Mailbox.TYPE_INBOX);
|
||||
Mailbox b1d = ProviderTestUtils.setupMailbox("box1d", a1.mId, true, c, Mailbox.TYPE_DRAFTS);
|
||||
Mailbox b1o = ProviderTestUtils.setupMailbox("box1o", a1.mId, true, c, Mailbox.TYPE_OUTBOX);
|
||||
Mailbox b1s = ProviderTestUtils.setupMailbox("box1s", a1.mId, true, c, Mailbox.TYPE_SENT);
|
||||
Mailbox b2 = ProviderTestUtils.setupMailbox("box2", a2.mId, true, c, Mailbox.TYPE_MAIL);
|
||||
|
||||
// Create some messages
|
||||
Message m11 = createMessageWithTimestamp(c, b1, 33);
|
||||
Message m12 = createMessageWithTimestamp(c, b1, 10);
|
||||
Message m13 = createMessageWithTimestamp(c, b1, 1000);
|
||||
Message m13 = createMessageWithTimestamp(c, b1, 1000); // latest incoming
|
||||
Message m1d = createMessageWithTimestamp(c, b1d, 2000);
|
||||
Message m1o = createMessageWithTimestamp(c, b1o, 2000);
|
||||
Message m1s = createMessageWithTimestamp(c, b1s, 2000);
|
||||
|
||||
Message m21 = createMessageWithTimestamp(c, b2, 99);
|
||||
Message m21 = createMessageWithTimestamp(c, b2, 99); // latest incoming
|
||||
Message m22 = createMessageWithTimestamp(c, b2, 1);
|
||||
Message m23 = createMessageWithTimestamp(c, b2, 2);
|
||||
|
||||
// Check!
|
||||
assertEquals(m13.mId, Message.getLatestMessage(c, a1.mId).mId);
|
||||
assertEquals(m21.mId, Message.getLatestMessage(c, a2.mId).mId);
|
||||
assertEquals(m13.mId, Message.getLatestIncomingMessage(c, a1.mId).mId);
|
||||
assertEquals(m21.mId, Message.getLatestIncomingMessage(c, a2.mId).mId);
|
||||
|
||||
// No such account
|
||||
assertEquals(null, Message.getLatestMessage(c, 9999999L));
|
||||
assertEquals(null, Message.getLatestIncomingMessage(c, 9999999L));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user