rename LocalMessage id field to databaseId

This commit is contained in:
Vincent Breitmoser 2017-08-22 16:27:09 +02:00
parent 52d76cad71
commit 2fbd6f61a8
16 changed files with 40 additions and 50 deletions

View file

@ -144,8 +144,6 @@ public abstract class Message implements Part, Body {
@Override @Override
public abstract void setBody(Body body); public abstract void setBody(Body body);
public abstract long getId();
public abstract boolean hasAttachments(); public abstract boolean hasAttachments();
public abstract long getSize(); public abstract long getSize();

View file

@ -688,11 +688,6 @@ public class MimeMessage extends Message {
return message; return message;
} }
@Override
public long getId() {
return Long.parseLong(mUid); //or maybe .mMessageId?
}
@Override @Override
public boolean hasAttachments() { public boolean hasAttachments() {
return false; return false;

View file

@ -126,7 +126,7 @@ public class EmailProviderCache {
public void hideMessages(List<LocalMessage> messages) { public void hideMessages(List<LocalMessage> messages) {
synchronized (mHiddenMessageCache) { synchronized (mHiddenMessageCache) {
for (LocalMessage message : messages) { for (LocalMessage message : messages) {
long messageId = message.getId(); long messageId = message.getDatabaseId();
mHiddenMessageCache.put(messageId, message.getFolder().getId()); mHiddenMessageCache.put(messageId, message.getFolder().getId());
} }
} }
@ -145,7 +145,7 @@ public class EmailProviderCache {
synchronized (mHiddenMessageCache) { synchronized (mHiddenMessageCache) {
for (Message message : messages) { for (Message message : messages) {
LocalMessage localMessage = (LocalMessage) message; LocalMessage localMessage = (LocalMessage) message;
long messageId = localMessage.getId(); long messageId = localMessage.getDatabaseId();
long folderId = ((LocalFolder) localMessage.getFolder()).getId(); long folderId = ((LocalFolder) localMessage.getFolder()).getId();
Long hiddenInFolder = mHiddenMessageCache.get(messageId); Long hiddenInFolder = mHiddenMessageCache.get(messageId);

View file

@ -305,7 +305,7 @@ public class MessagingController {
} }
private boolean isMessageSuppressed(LocalMessage message) { private boolean isMessageSuppressed(LocalMessage message) {
long messageId = message.getId(); long messageId = message.getDatabaseId();
long folderId = message.getFolder().getId(); long folderId = message.getFolder().getId();
EmailProviderCache cache = EmailProviderCache.getCache(message.getFolder().getAccountUuid(), context); EmailProviderCache cache = EmailProviderCache.getCache(message.getFolder().getAccountUuid(), context);
@ -2511,7 +2511,7 @@ public class MessagingController {
localFolder.open(Folder.OPEN_MODE_RW); localFolder.open(Folder.OPEN_MODE_RW);
LocalMessage message = localFolder.getMessage(uid); LocalMessage message = localFolder.getMessage(uid);
if (message == null || message.getId() == 0) { if (message == null || message.getDatabaseId() == 0) {
throw new IllegalArgumentException("Message not found: folder=" + folderName + ", uid=" + uid); throw new IllegalArgumentException("Message not found: folder=" + folderName + ", uid=" + uid);
} }
@ -2530,7 +2530,7 @@ public class MessagingController {
throws MessagingException { throws MessagingException {
if (account.isMarkMessageAsReadOnView() && !message.isSet(Flag.SEEN)) { if (account.isMarkMessageAsReadOnView() && !message.isSet(Flag.SEEN)) {
List<Long> messageIds = Collections.singletonList(message.getId()); List<Long> messageIds = Collections.singletonList(message.getDatabaseId());
setFlag(account, messageIds, Flag.SEEN, true); setFlag(account, messageIds, Flag.SEEN, true);
message.setFlagInternal(Flag.SEEN, true); message.setFlagInternal(Flag.SEEN, true);
@ -3996,7 +3996,7 @@ public class MessagingController {
public long getId(Message message) { public long getId(Message message) {
long id; long id;
if (message instanceof LocalMessage) { if (message instanceof LocalMessage) {
id = message.getId(); id = ((LocalMessage) message).getDatabaseId();
} else { } else {
Timber.w("MessagingController.getId() called without a LocalMessage"); Timber.w("MessagingController.getId() called without a LocalMessage");
id = INVALID_MESSAGE_ID; id = INVALID_MESSAGE_ID;

View file

@ -26,7 +26,7 @@ public class LocalBodyPart extends MimeBodyPart implements LocalPart {
} }
@Override @Override
public long getId() { public long getPartId() {
return messagePartId; return messagePartId;
} }

View file

@ -1046,7 +1046,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
"id %d currently in folder %s", "id %d currently in folder %s",
lDestFolder.getId(), lDestFolder.getId(),
message.getUid(), message.getUid(),
lMessage.getId(), lMessage.getDatabaseId(),
getName()); getName());
String newUid = K9.LOCAL_UID_PREFIX + UUID.randomUUID().toString(); String newUid = K9.LOCAL_UID_PREFIX + UUID.randomUUID().toString();
@ -1060,7 +1060,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
/* /*
* "Move" the message into the new folder * "Move" the message into the new folder
*/ */
long msgId = lMessage.getId(); long msgId = lMessage.getDatabaseId();
String[] idArg = new String[] { Long.toString(msgId) }; String[] idArg = new String[] { Long.toString(msgId) };
ContentValues cv = new ContentValues(); ContentValues cv = new ContentValues();
@ -1309,7 +1309,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
LocalMessage oldMessage = getMessage(uid); LocalMessage oldMessage = getMessage(uid);
if (oldMessage != null) { if (oldMessage != null) {
oldMessageId = oldMessage.getId(); oldMessageId = oldMessage.getDatabaseId();
long oldRootMessagePartId = oldMessage.getMessagePartId(); long oldRootMessagePartId = oldMessage.getMessagePartId();
deleteMessagePartsAndDataFromDisk(oldRootMessagePartId); deleteMessagePartsAndDataFromDisk(oldRootMessagePartId);
@ -1689,7 +1689,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
@Override @Override
public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
db.update("messages", cv, "id = ?", new String[] db.update("messages", cv, "id = ?", new String[]
{ Long.toString(message.getId()) }); { Long.toString(message.getDatabaseId()) });
return null; return null;
} }
}); });
@ -1844,7 +1844,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
} }
void destroyMessage(LocalMessage localMessage) throws MessagingException { void destroyMessage(LocalMessage localMessage) throws MessagingException {
destroyMessage(localMessage.getId(), localMessage.getMessagePartId(), localMessage.getMessageId()); destroyMessage(localMessage.getDatabaseId(), localMessage.getMessagePartId(), localMessage.getMessageId());
} }
private void destroyMessage(final long messageId, final long messagePartId, final String messageIdHeader) private void destroyMessage(final long messageId, final long messagePartId, final String messageIdHeader)

View file

@ -29,7 +29,7 @@ import timber.log.Timber;
public class LocalMessage extends MimeMessage { public class LocalMessage extends MimeMessage {
private final LocalStore localStore; private final LocalStore localStore;
private long id; private long databaseId;
private long rootId; private long rootId;
private long threadId; private long threadId;
private long messagePartId; private long messagePartId;
@ -79,7 +79,7 @@ public class LocalMessage extends MimeMessage {
} }
} }
} }
this.id = cursor.getLong(5); this.databaseId = cursor.getLong(5);
this.setRecipients(RecipientType.TO, Address.unpack(cursor.getString(6))); this.setRecipients(RecipientType.TO, Address.unpack(cursor.getString(6)));
this.setRecipients(RecipientType.CC, Address.unpack(cursor.getString(7))); this.setRecipients(RecipientType.CC, Address.unpack(cursor.getString(7)));
this.setRecipients(RecipientType.BCC, Address.unpack(cursor.getString(8))); this.setRecipients(RecipientType.BCC, Address.unpack(cursor.getString(8)));
@ -246,9 +246,8 @@ public class LocalMessage extends MimeMessage {
super.setFlag(flag, set); super.setFlag(flag, set);
} }
@Override public long getDatabaseId() {
public long getId() { return databaseId;
return id;
} }
@Override @Override
@ -277,7 +276,7 @@ public class LocalMessage extends MimeMessage {
cv.put("answered", isSet(Flag.ANSWERED) ? 1 : 0); cv.put("answered", isSet(Flag.ANSWERED) ? 1 : 0);
cv.put("forwarded", isSet(Flag.FORWARDED) ? 1 : 0); cv.put("forwarded", isSet(Flag.FORWARDED) ? 1 : 0);
db.update("messages", cv, "id = ?", new String[] { Long.toString(id) }); db.update("messages", cv, "id = ?", new String[] { Long.toString(databaseId) });
return null; return null;
} }
@ -311,7 +310,7 @@ public class LocalMessage extends MimeMessage {
cv.putNull("reply_to_list"); cv.putNull("reply_to_list");
cv.putNull("message_part_id"); cv.putNull("message_part_id");
db.update("messages", cv, "id = ?", new String[] { Long.toString(id) }); db.update("messages", cv, "id = ?", new String[] { Long.toString(databaseId) });
try { try {
((LocalFolder) mFolder).deleteMessagePartsAndDataFromDisk(messagePartId); ((LocalFolder) mFolder).deleteMessagePartsAndDataFromDisk(messagePartId);
@ -319,7 +318,7 @@ public class LocalMessage extends MimeMessage {
throw new WrappedException(e); throw new WrappedException(e);
} }
getFolder().deleteFulltextIndexEntry(db, id); getFolder().deleteFulltextIndexEntry(db, databaseId);
return null; return null;
} }
@ -343,7 +342,7 @@ public class LocalMessage extends MimeMessage {
ContentValues cv = new ContentValues(); ContentValues cv = new ContentValues();
cv.putNull("message_part_id"); cv.putNull("message_part_id");
db.update("messages", cv, "id = ?", new String[] { Long.toString(id) }); db.update("messages", cv, "id = ?", new String[] { Long.toString(databaseId) });
try { try {
((LocalFolder) mFolder).deleteMessagePartsAndDataFromDisk(messagePartId); ((LocalFolder) mFolder).deleteMessagePartsAndDataFromDisk(messagePartId);
@ -380,7 +379,7 @@ public class LocalMessage extends MimeMessage {
super.copy(message); super.copy(message);
message.messageReference = messageReference; message.messageReference = messageReference;
message.id = id; message.databaseId = databaseId;
message.attachmentCount = attachmentCount; message.attachmentCount = attachmentCount;
message.subject = subject; message.subject = subject;
message.preview = preview; message.preview = preview;

View file

@ -24,7 +24,7 @@ public class LocalMimeMessage extends MimeMessage implements LocalPart {
} }
@Override @Override
public long getId() { public long getPartId() {
return messagePartId; return messagePartId;
} }

View file

@ -3,7 +3,7 @@ package com.fsck.k9.mailstore;
public interface LocalPart { public interface LocalPart {
String getAccountUuid(); String getAccountUuid();
long getId(); long getPartId();
long getSize(); long getSize();
LocalMessage getMessage(); LocalMessage getMessage();
} }

View file

@ -756,7 +756,7 @@ public class LocalStore extends Store implements Serializable {
if (part instanceof LocalPart) { if (part instanceof LocalPart) {
LocalPart localBodyPart = (LocalPart) part; LocalPart localBodyPart = (LocalPart) part;
if (localBodyPart.getId() == partId) { if (localBodyPart.getPartId() == partId) {
return part; return part;
} }
} }

View file

@ -9,7 +9,6 @@ import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils; import android.text.TextUtils;
import timber.log.Timber; import timber.log.Timber;
import com.fsck.k9.K9;
import com.fsck.k9.mail.FetchProfile; import com.fsck.k9.mail.FetchProfile;
import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mailstore.LocalFolder; import com.fsck.k9.mailstore.LocalFolder;
@ -38,13 +37,13 @@ class MigrationTo55 {
String fulltext = fulltextCreator.createFulltext(localMessage); String fulltext = fulltextCreator.createFulltext(localMessage);
if (!TextUtils.isEmpty(fulltext)) { if (!TextUtils.isEmpty(fulltext)) {
Timber.d("fulltext for msg id %d is %d chars long", localMessage.getId(), fulltext.length()); Timber.d("fulltext for msg id %d is %d chars long", localMessage.getDatabaseId(), fulltext.length());
cv.clear(); cv.clear();
cv.put("docid", localMessage.getId()); cv.put("docid", localMessage.getDatabaseId());
cv.put("fulltext", fulltext); cv.put("fulltext", fulltext);
db.insert("messages_fulltext", null, cv); db.insert("messages_fulltext", null, cv);
} else { } else {
Timber.d("no fulltext for msg id %d :(", localMessage.getId()); Timber.d("no fulltext for msg id %d :(", localMessage.getDatabaseId());
} }
} }
} }

View file

@ -14,7 +14,6 @@ import timber.log.Timber;
import android.support.annotation.WorkerThread; import android.support.annotation.WorkerThread;
import com.fsck.k9.Globals; import com.fsck.k9.Globals;
import com.fsck.k9.K9;
import com.fsck.k9.mail.Body; import com.fsck.k9.mail.Body;
import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.Part; import com.fsck.k9.mail.Part;
@ -64,7 +63,7 @@ public class AttachmentInfoExtractor {
if (part instanceof LocalPart) { if (part instanceof LocalPart) {
LocalPart localPart = (LocalPart) part; LocalPart localPart = (LocalPart) part;
String accountUuid = localPart.getAccountUuid(); String accountUuid = localPart.getAccountUuid();
long messagePartId = localPart.getId(); long messagePartId = localPart.getPartId();
size = localPart.getSize(); size = localPart.getSize();
isContentAvailable = part.getBody() != null; isContentAvailable = part.getBody() != null;
uri = AttachmentProvider.getAttachmentUri(accountUuid, messagePartId); uri = AttachmentProvider.getAttachmentUri(accountUuid, messagePartId);

View file

@ -358,13 +358,13 @@ public class MessageProvider extends ContentProvider {
} }
/** /**
* Extracts the {@link LocalMessage#getId() ID} from the given {@link MessageInfoHolder}. The underlying * Extracts the {@link LocalMessage#getDatabaseId() ID} from the given {@link MessageInfoHolder}. The underlying
* {@link Message} is expected to be a {@link LocalMessage}. * {@link Message} is expected to be a {@link LocalMessage}.
*/ */
public static class IdExtractor implements FieldExtractor<MessageInfoHolder, Long> { public static class IdExtractor implements FieldExtractor<MessageInfoHolder, Long> {
@Override @Override
public Long getField(MessageInfoHolder source) { public Long getField(MessageInfoHolder source) {
return source.message.getId(); return source.message.getDatabaseId();
} }
} }

View file

@ -283,7 +283,7 @@ public class MessageHeader extends LinearLayout implements OnClickListener, OnLo
/* We hide the subject by default for each new message, and MessageTitleView might show /* We hide the subject by default for each new message, and MessageTitleView might show
* it later by calling showSubjectLine(). */ * it later by calling showSubjectLine(). */
boolean newMessageShown = mMessage == null || mMessage.getId() != message.getId(); boolean newMessageShown = mMessage == null || !mMessage.getUid().equals(message.getUid());
if (newMessageShown) { if (newMessageShown) {
mSubjectView.setVisibility(GONE); mSubjectView.setVisibility(GONE);
} }

View file

@ -40,7 +40,7 @@ public class EmailProviderCacheTest {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
cache = EmailProviderCache.getCache(UUID.randomUUID().toString(), RuntimeEnvironment.application); cache = EmailProviderCache.getCache(UUID.randomUUID().toString(), RuntimeEnvironment.application);
when(mockLocalMessage.getId()).thenReturn(localMessageId); when(mockLocalMessage.getDatabaseId()).thenReturn(localMessageId);
when(mockLocalMessage.getFolder()).thenReturn(mockLocalMessageFolder); when(mockLocalMessage.getFolder()).thenReturn(mockLocalMessageFolder);
when(mockLocalMessageFolder.getId()).thenReturn(localMessageFolderId); when(mockLocalMessageFolder.getId()).thenReturn(localMessageFolderId);
} }

View file

@ -163,7 +163,7 @@ public class MigrationTest {
localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null); localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);
Assert.assertEquals("text/plain", msg.getMimeType()); Assert.assertEquals("text/plain", msg.getMimeType());
Assert.assertEquals(2, msg.getId()); Assert.assertEquals(2, msg.getDatabaseId());
Assert.assertEquals(13, msg.getHeaderNames().size()); Assert.assertEquals(13, msg.getHeaderNames().size());
Assert.assertEquals(0, msg.getAttachmentCount()); Assert.assertEquals(0, msg.getAttachmentCount());
@ -229,7 +229,7 @@ public class MigrationTest {
fp.add(FetchProfile.Item.BODY); fp.add(FetchProfile.Item.BODY);
localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null); localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);
Assert.assertEquals(3, msg.getId()); Assert.assertEquals(3, msg.getDatabaseId());
Assert.assertEquals(8, msg.getHeaderNames().size()); Assert.assertEquals(8, msg.getHeaderNames().size());
Assert.assertEquals("multipart/mixed", msg.getMimeType()); Assert.assertEquals("multipart/mixed", msg.getMimeType());
Assert.assertEquals(1, msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE).length); Assert.assertEquals(1, msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE).length);
@ -301,7 +301,7 @@ public class MigrationTest {
fp.add(FetchProfile.Item.BODY); fp.add(FetchProfile.Item.BODY);
localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null); localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);
Assert.assertEquals(4, msg.getId()); Assert.assertEquals(4, msg.getDatabaseId());
Assert.assertEquals(8, msg.getHeaderNames().size()); Assert.assertEquals(8, msg.getHeaderNames().size());
Assert.assertEquals("multipart/mixed", msg.getMimeType()); Assert.assertEquals("multipart/mixed", msg.getMimeType());
Assert.assertEquals(2, msg.getAttachmentCount()); Assert.assertEquals(2, msg.getAttachmentCount());
@ -360,7 +360,7 @@ public class MigrationTest {
fp.add(FetchProfile.Item.BODY); fp.add(FetchProfile.Item.BODY);
localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null); localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);
Assert.assertEquals(5, msg.getId()); Assert.assertEquals(5, msg.getDatabaseId());
Assert.assertEquals(13, msg.getHeaderNames().size()); Assert.assertEquals(13, msg.getHeaderNames().size());
Assert.assertEquals("multipart/encrypted", msg.getMimeType()); Assert.assertEquals("multipart/encrypted", msg.getMimeType());
Assert.assertEquals(2, msg.getAttachmentCount()); Assert.assertEquals(2, msg.getAttachmentCount());
@ -478,7 +478,7 @@ public class MigrationTest {
fp.add(FetchProfile.Item.BODY); fp.add(FetchProfile.Item.BODY);
localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null); localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);
Assert.assertEquals(6, msg.getId()); Assert.assertEquals(6, msg.getDatabaseId());
Assert.assertEquals(12, msg.getHeaderNames().size()); Assert.assertEquals(12, msg.getHeaderNames().size());
Assert.assertEquals("text/plain", msg.getMimeType()); Assert.assertEquals("text/plain", msg.getMimeType());
Assert.assertEquals(0, msg.getAttachmentCount()); Assert.assertEquals(0, msg.getAttachmentCount());
@ -565,7 +565,7 @@ public class MigrationTest {
fp.add(FetchProfile.Item.BODY); fp.add(FetchProfile.Item.BODY);
localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null); localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);
Assert.assertEquals(7, msg.getId()); Assert.assertEquals(7, msg.getDatabaseId());
Assert.assertEquals(12, msg.getHeaderNames().size()); Assert.assertEquals(12, msg.getHeaderNames().size());
Assert.assertEquals("text/plain", msg.getMimeType()); Assert.assertEquals("text/plain", msg.getMimeType());
Assert.assertEquals(0, msg.getAttachmentCount()); Assert.assertEquals(0, msg.getAttachmentCount());
@ -623,7 +623,7 @@ public class MigrationTest {
fp.add(FetchProfile.Item.BODY); fp.add(FetchProfile.Item.BODY);
localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null); localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);
Assert.assertEquals(8, msg.getId()); Assert.assertEquals(8, msg.getDatabaseId());
Assert.assertEquals(9, msg.getHeaderNames().size()); Assert.assertEquals(9, msg.getHeaderNames().size());
Assert.assertEquals("multipart/alternative", msg.getMimeType()); Assert.assertEquals("multipart/alternative", msg.getMimeType());
Assert.assertEquals(0, msg.getAttachmentCount()); Assert.assertEquals(0, msg.getAttachmentCount());
@ -688,7 +688,7 @@ public class MigrationTest {
fp.add(FetchProfile.Item.BODY); fp.add(FetchProfile.Item.BODY);
localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null); localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);
Assert.assertEquals(9, msg.getId()); Assert.assertEquals(9, msg.getDatabaseId());
Assert.assertEquals(11, msg.getHeaderNames().size()); Assert.assertEquals(11, msg.getHeaderNames().size());
Assert.assertEquals("multipart/mixed", msg.getMimeType()); Assert.assertEquals("multipart/mixed", msg.getMimeType());
Assert.assertEquals(1, msg.getAttachmentCount()); Assert.assertEquals(1, msg.getAttachmentCount());