Fixes Issue 963

MessagingController was calling the MessagingListener twice for
deleted messages.  By the time the second call was made, some
Activities already had removed the message holder, so a null holder
was being put on the list.

This change should prevent the double calls, and adds protection
against have the MessageList MessagingListener called with a message
that is no longer in the MessageList.

Also, some logical cleanups.
This commit is contained in:
Daniel Applebaum 2010-01-06 04:54:24 +00:00
parent 2b37fe6864
commit a5166e3c2d
2 changed files with 35 additions and 28 deletions

View file

@ -1508,20 +1508,21 @@ public class MessagingController implements Runnable
boolean messageChanged = syncFlags(localMessage, remoteMessage);
if (messageChanged)
{
if (isMessageSuppressed(account, folder, localMessage) == false)
{
for (MessagingListener l : getListeners())
{
l.synchronizeMailboxAddOrUpdateMessage(account, folder, localMessage);
}
}
if (localMessage.isSet(Flag.DELETED))
if (localMessage.isSet(Flag.DELETED) || isMessageSuppressed(account, folder, localMessage))
{
for (MessagingListener l : getListeners())
{
l.synchronizeMailboxRemovedMessage(account, folder, localMessage);
}
}
else
{
for (MessagingListener l : getListeners())
{
l.synchronizeMailboxAddOrUpdateMessage(account, folder, localMessage);
}
}
}
progress.incrementAndGet();
for (MessagingListener l : getListeners())

View file

@ -143,22 +143,24 @@ public class MessageList
public void removeMessage(final List<MessageInfoHolder> messages)
{
runOnUiThread(new Runnable()
{
public void run()
{
for (MessageInfoHolder message : messages)
{
if (message != null)
{
if (mFolderName == null || (message.folder != null && message.folder.name.equals(mFolderName)))
{
if (message != null && message.selected && mSelectedCount > 0)
if (message.selected && mSelectedCount > 0)
{
mSelectedCount--;
}
mAdapter.messages.remove(message);
}
}
}
mAdapter.notifyDataSetChanged();
configureBatchButtons();
}
@ -1627,7 +1629,15 @@ public class MessageList
@Override
public void synchronizeMailboxRemovedMessage(Account account, String folder,Message message)
{
removeMessage(getMessage(message.getUid()));
MessageInfoHolder holder = getMessage(message.getUid());
if (holder == null)
{
Log.w(K9.LOG_TAG, "Got callback to remove non-existent message with UID " + message.getUid());
}
else
{
removeMessage(holder);
}
}
@Override
@ -1791,32 +1801,28 @@ public class MessageList
boolean needsSort = false;
List<MessageInfoHolder> messagesToAdd = new ArrayList<MessageInfoHolder>();
List<MessageInfoHolder> messagesToRemove = new ArrayList<MessageInfoHolder>();
FolderInfoHolder f = mCurrentFolder; // This is wrong, but what the old code did.
for (Message message : messages)
{
if (updateForMe(account, folder))
{
MessageInfoHolder m = getMessage(message.getUid());
if (m == null)
if (message.isSet(Flag.DELETED))
{
if (m != null)
{
messagesToRemove.add(m);
}
}
else if (m == null)
{
m = new MessageInfoHolder(message, account);
messagesToAdd.add(m);
}
else
{
if (message.isSet(Flag.DELETED))
{
messagesToRemove.add(m);
}
else
{
m.populate(message, new FolderInfoHolder(message.getFolder(), account), account);
needsSort = true;
}
}
}
}