Slight optimization for message status updates

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2015-12-03 11:47:28 -08:00
parent 7c95adc7e6
commit 8fb73a092d

View File

@ -333,43 +333,50 @@ public class MmsDatabase extends MessagingDatabase {
return readerFor(masterSecret, rawQuery(where, null));
}
private void updateMailboxBitmask(long id, long maskOff, long maskOn) {
private void updateMailboxBitmask(long id, long maskOff, long maskOn, Optional<Long> threadId) {
SQLiteDatabase db = databaseHelper.getWritableDatabase();
db.execSQL("UPDATE " + TABLE_NAME +
" SET " + MESSAGE_BOX + " = (" + MESSAGE_BOX + " & " + (Types.TOTAL_MASK - maskOff) + " | " + maskOn + " )" +
" WHERE " + ID + " = ?", new String[] {id + ""});
DatabaseFactory.getThreadDatabase(context).update(getThreadIdForMessage(id), false);
if (threadId.isPresent()) {
DatabaseFactory.getThreadDatabase(context).update(threadId.get(), false);
}
}
public void markAsOutbox(long messageId) {
updateMailboxBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_OUTBOX_TYPE);
notifyConversationListeners(getThreadIdForMessage(messageId));
long threadId = getThreadIdForMessage(messageId);
updateMailboxBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_OUTBOX_TYPE, Optional.of(threadId));
}
public void markAsForcedSms(long messageId) {
updateMailboxBitmask(messageId, Types.PUSH_MESSAGE_BIT, Types.MESSAGE_FORCE_SMS_BIT);
notifyConversationListeners(getThreadIdForMessage(messageId));
long threadId = getThreadIdForMessage(messageId);
updateMailboxBitmask(messageId, Types.PUSH_MESSAGE_BIT, Types.MESSAGE_FORCE_SMS_BIT, Optional.of(threadId));
notifyConversationListeners(threadId);
}
public void markAsPendingInsecureSmsFallback(long messageId) {
updateMailboxBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_PENDING_INSECURE_SMS_FALLBACK);
notifyConversationListeners(getThreadIdForMessage(messageId));
long threadId = getThreadIdForMessage(messageId);
updateMailboxBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_PENDING_INSECURE_SMS_FALLBACK, Optional.of(threadId));
notifyConversationListeners(threadId);
}
public void markAsSending(long messageId) {
updateMailboxBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_SENDING_TYPE);
notifyConversationListeners(getThreadIdForMessage(messageId));
long threadId = getThreadIdForMessage(messageId);
updateMailboxBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_SENDING_TYPE, Optional.of(threadId));
notifyConversationListeners(threadId);
}
public void markAsSentFailed(long messageId) {
updateMailboxBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_SENT_FAILED_TYPE);
notifyConversationListeners(getThreadIdForMessage(messageId));
long threadId = getThreadIdForMessage(messageId);
updateMailboxBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_SENT_FAILED_TYPE, Optional.of(threadId));
notifyConversationListeners(threadId);
}
public void markAsSent(long messageId) {
updateMailboxBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_SENT_TYPE);
notifyConversationListeners(getThreadIdForMessage(messageId));
long threadId = getThreadIdForMessage(messageId);
updateMailboxBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_SENT_TYPE, Optional.of(threadId));
notifyConversationListeners(threadId);
}
public void markDownloadState(long messageId, long state) {
@ -382,34 +389,34 @@ public class MmsDatabase extends MessagingDatabase {
}
public void markAsNoSession(long messageId, long threadId) {
updateMailboxBitmask(messageId, Types.ENCRYPTION_MASK, Types.ENCRYPTION_REMOTE_NO_SESSION_BIT);
updateMailboxBitmask(messageId, Types.ENCRYPTION_MASK, Types.ENCRYPTION_REMOTE_NO_SESSION_BIT, Optional.of(threadId));
notifyConversationListeners(threadId);
}
public void markAsSecure(long messageId) {
updateMailboxBitmask(messageId, 0, Types.SECURE_MESSAGE_BIT);
updateMailboxBitmask(messageId, 0, Types.SECURE_MESSAGE_BIT, Optional.<Long>absent());
}
public void markAsInsecure(long messageId) {
updateMailboxBitmask(messageId, Types.SECURE_MESSAGE_BIT, 0);
updateMailboxBitmask(messageId, Types.SECURE_MESSAGE_BIT, 0, Optional.<Long>absent());
}
public void markAsPush(long messageId) {
updateMailboxBitmask(messageId, 0, Types.PUSH_MESSAGE_BIT);
updateMailboxBitmask(messageId, 0, Types.PUSH_MESSAGE_BIT, Optional.<Long>absent());
}
public void markAsDecryptFailed(long messageId, long threadId) {
updateMailboxBitmask(messageId, Types.ENCRYPTION_MASK, Types.ENCRYPTION_REMOTE_FAILED_BIT);
updateMailboxBitmask(messageId, Types.ENCRYPTION_MASK, Types.ENCRYPTION_REMOTE_FAILED_BIT, Optional.of(threadId));
notifyConversationListeners(threadId);
}
public void markAsDecryptDuplicate(long messageId, long threadId) {
updateMailboxBitmask(messageId, Types.ENCRYPTION_MASK, Types.ENCRYPTION_REMOTE_DUPLICATE_BIT);
updateMailboxBitmask(messageId, Types.ENCRYPTION_MASK, Types.ENCRYPTION_REMOTE_DUPLICATE_BIT, Optional.of(threadId));
notifyConversationListeners(threadId);
}
public void markAsLegacyVersion(long messageId, long threadId) {
updateMailboxBitmask(messageId, Types.ENCRYPTION_MASK, Types.ENCRYPTION_REMOTE_LEGACY_BIT);
updateMailboxBitmask(messageId, Types.ENCRYPTION_MASK, Types.ENCRYPTION_REMOTE_LEGACY_BIT, Optional.of(threadId));
notifyConversationListeners(threadId);
}