Don't let outgoing messages trigger last seen divider

Closes #6306
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2017-02-26 10:49:48 -08:00
parent 1d3f1cc79e
commit 8f96cff104
4 changed files with 14 additions and 8 deletions

View File

@ -289,7 +289,7 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
Cursor cursor = getCursorAtPositionOrThrow(i); Cursor cursor = getCursorAtPositionOrThrow(i);
MessageRecord messageRecord = getMessageRecord(cursor); MessageRecord messageRecord = getMessageRecord(cursor);
if (messageRecord.getDateReceived() <= lastSeen) { if (messageRecord.isOutgoing() || messageRecord.getDateReceived() <= lastSeen) {
return i; return i;
} }
} }
@ -345,7 +345,8 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
Cursor cursor = getCursorAtPositionOrThrow(position); Cursor cursor = getCursorAtPositionOrThrow(position);
MessageRecord messageRecord = getMessageRecord(cursor); MessageRecord messageRecord = getMessageRecord(cursor);
return messageRecord.getDateReceived(); if (messageRecord.isOutgoing()) return 0;
else return messageRecord.getDateReceived();
} }
@Override @Override

View File

@ -412,6 +412,7 @@ public class ConversationFragment extends Fragment
@Override @Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
Log.w(TAG, "onLoadFinished");
ConversationLoader loader = (ConversationLoader)cursorLoader; ConversationLoader loader = (ConversationLoader)cursorLoader;
if (list.getAdapter() != null) { if (list.getAdapter() != null) {
@ -427,10 +428,16 @@ public class ConversationFragment extends Fragment
getListAdapter().changeCursor(cursor); getListAdapter().changeCursor(cursor);
int lastSeenPosition = getListAdapter().findLastSeenPosition(lastSeen);
if (firstLoad) { if (firstLoad) {
scrollToLastSeenPosition(lastSeen); scrollToLastSeenPosition(lastSeenPosition);
firstLoad = false; firstLoad = false;
} }
if (lastSeenPosition <= 0) {
setLastSeen(0);
}
} }
} }
@ -441,9 +448,7 @@ public class ConversationFragment extends Fragment
} }
} }
private void scrollToLastSeenPosition(long lastSeen) { private void scrollToLastSeenPosition(final int lastSeenPosition) {
final int lastSeenPosition = getListAdapter().findLastSeenPosition(lastSeen);
if (lastSeenPosition > 0) { if (lastSeenPosition > 0) {
list.post(new Runnable() { list.post(new Runnable() {
@Override @Override
@ -451,8 +456,6 @@ public class ConversationFragment extends Fragment
((LinearLayoutManager)list.getLayoutManager()).scrollToPositionWithOffset(lastSeenPosition, list.getHeight()); ((LinearLayoutManager)list.getLayoutManager()).scrollToPositionWithOffset(lastSeenPosition, list.getHeight());
} }
}); });
} else {
setLastSeen(0);
} }
} }

View File

@ -911,6 +911,7 @@ public class MmsDatabase extends MessagingDatabase {
long messageId = insertMediaMessage(masterSecret, addresses, message.getBody(), long messageId = insertMediaMessage(masterSecret, addresses, message.getBody(),
message.getAttachments(), contentValues); message.getAttachments(), contentValues);
DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId);
jobManager.add(new TrimThreadJob(context, threadId)); jobManager.add(new TrimThreadJob(context, threadId));
return messageId; return messageId;

View File

@ -614,6 +614,7 @@ public class SmsDatabase extends MessagingDatabase {
long messageId = db.insert(TABLE_NAME, ADDRESS, contentValues); long messageId = db.insert(TABLE_NAME, ADDRESS, contentValues);
DatabaseFactory.getThreadDatabase(context).update(threadId, true); DatabaseFactory.getThreadDatabase(context).update(threadId, true);
DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId);
notifyConversationListeners(threadId); notifyConversationListeners(threadId);
jobManager.add(new TrimThreadJob(context, threadId)); jobManager.add(new TrimThreadJob(context, threadId));