Change List<? extends Message> to List<LocalMessage> where appropriate

This commit is contained in:
cketti 2020-04-27 17:51:26 +02:00
parent 17b9654fad
commit 46b2633bea
3 changed files with 36 additions and 43 deletions

View file

@ -9,7 +9,6 @@ import android.content.Intent;
import android.net.Uri;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mailstore.LocalMessage;
import com.fsck.k9.provider.EmailProvider;
@ -139,12 +138,11 @@ public class EmailProviderCache {
}
}
public void unhideMessages(List<? extends Message> messages) {
public void unhideMessages(List<LocalMessage> messages) {
synchronized (mHiddenMessageCache) {
for (Message message : messages) {
LocalMessage localMessage = (LocalMessage) message;
long messageId = localMessage.getDatabaseId();
long folderId = localMessage.getFolder().getDatabaseId();
for (LocalMessage message : messages) {
long messageId = message.getDatabaseId();
long folderId = message.getFolder().getDatabaseId();
Long hiddenInFolder = mHiddenMessageCache.get(messageId);
if (hiddenInFolder != null && hiddenInFolder == folderId) {

View file

@ -326,7 +326,7 @@ public class MessagingController {
cache.hideMessages(messages);
}
private void unsuppressMessages(Account account, List<? extends Message> messages) {
private void unsuppressMessages(Account account, List<LocalMessage> messages) {
EmailProviderCache cache = EmailProviderCache.getCache(account.getUuid(), context);
cache.unhideMessages(messages);
}
@ -1097,7 +1097,7 @@ public class MessagingController {
* @param newState
* {@code true}, if the flag should be set. {@code false} if it should be removed.
*/
public void setFlag(Account account, String folderServerId, List<? extends Message> messages, Flag flag,
public void setFlag(Account account, String folderServerId, List<LocalMessage> messages, Flag flag,
boolean newState) {
// TODO: Put this into the background, but right now some callers depend on the message
// objects being modified right after this method returns.
@ -1153,7 +1153,7 @@ public class MessagingController {
localFolder = localStore.getFolder(folderServerId);
localFolder.open();
Message message = localFolder.getMessage(uid);
LocalMessage message = localFolder.getMessage(uid);
if (message != null) {
setFlag(account, folderServerId, Collections.singletonList(message), flag, newState);
}
@ -1743,7 +1743,7 @@ public class MessagingController {
@Override
public void run() {
try {
List<Message> messagesInThreads = collectMessagesInThreads(account, messages);
List<LocalMessage> messagesInThreads = collectMessagesInThreads(account, messages);
moveOrCopyMessageSynchronous(account, srcFolder, messagesInThreads, destFolder,
MoveOrCopyFlavor.MOVE);
} catch (MessagingException e) {
@ -1785,7 +1785,7 @@ public class MessagingController {
@Override
public void run() {
try {
List<Message> messagesInThreads = collectMessagesInThreads(account, messages);
List<LocalMessage> messagesInThreads = collectMessagesInThreads(account, messages);
moveOrCopyMessageSynchronous(account, srcFolder, messagesInThreads, destFolder,
MoveOrCopyFlavor.COPY);
} catch (MessagingException e) {
@ -1804,7 +1804,7 @@ public class MessagingController {
}
private void moveOrCopyMessageSynchronous(final Account account, final String srcFolder,
final List<? extends Message> inMessages, final String destFolder,
final List<LocalMessage> inMessages, final String destFolder,
MoveOrCopyFlavor operation) {
try {
@ -1947,9 +1947,9 @@ public class MessagingController {
});
}
private void deleteThreadsSynchronous(Account account, String folderServerId, List<? extends Message> messages) {
private void deleteThreadsSynchronous(Account account, String folderServerId, List<LocalMessage> messages) {
try {
List<Message> messagesToDelete = collectMessagesInThreads(account, messages);
List<LocalMessage> messagesToDelete = collectMessagesInThreads(account, messages);
deleteMessagesSynchronous(account, folderServerId,
messagesToDelete, null);
@ -1958,18 +1958,17 @@ public class MessagingController {
}
}
private List<Message> collectMessagesInThreads(Account account, List<? extends Message> messages)
private List<LocalMessage> collectMessagesInThreads(Account account, List<LocalMessage> messages)
throws MessagingException {
LocalStore localStore = localStoreProvider.getInstance(account);
List<Message> messagesInThreads = new ArrayList<>();
for (Message message : messages) {
LocalMessage localMessage = (LocalMessage) message;
long rootId = localMessage.getRootId();
long threadId = (rootId == -1) ? localMessage.getThreadId() : rootId;
List<LocalMessage> messagesInThreads = new ArrayList<>();
for (LocalMessage message : messages) {
long rootId = message.getRootId();
long threadId = (rootId == -1) ? message.getThreadId() : rootId;
List<? extends Message> messagesInThread = localStore.getMessagesInThread(threadId);
List<LocalMessage> messagesInThread = localStore.getMessagesInThread(threadId);
messagesInThreads.addAll(messagesInThread);
}
@ -2030,15 +2029,15 @@ public class MessagingController {
}
private void deleteMessagesSynchronous(final Account account, final String folder,
final List<? extends Message> messages,
final List<LocalMessage> messages,
MessagingListener listener) {
LocalFolder localFolder = null;
LocalFolder localTrashFolder = null;
try {
List<Message> localOnlyMessages = new ArrayList<>();
List<Message> syncedMessages = new ArrayList<>();
List<LocalMessage> localOnlyMessages = new ArrayList<>();
List<LocalMessage> syncedMessages = new ArrayList<>();
List<String> syncedMessageUids = new ArrayList<>();
for (Message message : messages) {
for (LocalMessage message : messages) {
String uid = message.getUid();
if (uid.startsWith(K9.LOCAL_UID_PREFIX)) {
localOnlyMessages.add(message);
@ -2129,7 +2128,7 @@ public class MessagingController {
}
}
private static List<String> getUidsFromMessages(List<? extends Message> messages) {
private static List<String> getUidsFromMessages(List<LocalMessage> messages) {
List<String> uids = new ArrayList<>(messages.size());
for (int i = 0; i < messages.size(); i++) {
uids.add(messages.get(i).getUid());

View file

@ -572,10 +572,8 @@ public class LocalFolder {
try {
open();
if (fp.contains(FetchProfile.Item.BODY)) {
for (Message message : messages) {
LocalMessage localMessage = (LocalMessage) message;
loadMessageParts(db, localMessage);
for (LocalMessage message : messages) {
loadMessageParts(db, message);
}
}
} catch (MessagingException e) {
@ -865,11 +863,11 @@ public class LocalFolder {
return messages;
}
public Map<String, String> copyMessages(List<? extends Message> msgs, LocalFolder folder) throws MessagingException {
public Map<String, String> copyMessages(List<LocalMessage> msgs, LocalFolder folder) throws MessagingException {
return folder.appendMessages(msgs, true);
}
public Map<String, String> moveMessages(final List<? extends Message> msgs, final LocalFolder destFolder) throws MessagingException {
public Map<String, String> moveMessages(final List<LocalMessage> msgs, final LocalFolder destFolder) throws MessagingException {
final Map<String, String> uidMap = new HashMap<>();
try {
@ -878,16 +876,14 @@ public class LocalFolder {
public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
try {
destFolder.open();
for (Message message : msgs) {
LocalMessage lMessage = (LocalMessage)message;
for (LocalMessage message : msgs) {
String oldUID = message.getUid();
Timber.d("Updating folder_id to %s for message with UID %s, " +
"id %d currently in folder %s",
destFolder.getDatabaseId(),
message.getUid(),
lMessage.getDatabaseId(),
message.getDatabaseId(),
getServerId());
String newUid = K9.LOCAL_UID_PREFIX + UUID.randomUUID().toString();
@ -901,7 +897,7 @@ public class LocalFolder {
/*
* "Move" the message into the new folder
*/
long msgId = lMessage.getDatabaseId();
long msgId = message.getDatabaseId();
String[] idArg = new String[] { Long.toString(msgId) };
ContentValues cv = new ContentValues();
@ -972,7 +968,7 @@ public class LocalFolder {
cv.clear();
cv.put("message_id", newId);
db.update("threads", cv, "id = ?",
new String[] { Long.toString(lMessage.getThreadId()) });
new String[] { Long.toString(message.getThreadId()) });
}
} catch (MessagingException e) {
throw new WrappedException(e);
@ -1005,12 +1001,12 @@ public class LocalFolder {
return appendMessages(messages, false);
}
public void destroyMessages(final List<? extends Message> messages) {
public void destroyMessages(final List<LocalMessage> messages) {
try {
this.localStore.getDatabase().execute(true, new DbCallback<Void>() {
@Override
public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
for (Message message : messages) {
for (LocalMessage message : messages) {
try {
message.destroy();
} catch (MessagingException e) {
@ -1534,7 +1530,7 @@ public class LocalFolder {
this.localStore.notifyChange();
}
public void setFlags(final List<? extends Message> messages, final Set<Flag> flags, final boolean value)
public void setFlags(final List<LocalMessage> messages, final Set<Flag> flags, final boolean value)
throws MessagingException {
open();
@ -1545,7 +1541,7 @@ public class LocalFolder {
public Void doDbWork(final SQLiteDatabase db) throws WrappedException,
UnavailableStorageException {
for (Message message : messages) {
for (LocalMessage message : messages) {
try {
message.setFlags(flags, value);
} catch (MessagingException e) {
@ -1564,7 +1560,7 @@ public class LocalFolder {
public void setFlags(final Set<Flag> flags, boolean value)
throws MessagingException {
open();
for (Message message : getMessages(null)) {
for (LocalMessage message : getMessages(null)) {
message.setFlags(flags, value);
}
}