From 8cd50d1e82a608513afca1abae9f6d95b260a2cb Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Wed, 22 Feb 2017 15:05:35 -0800 Subject: [PATCH] Update last seen state on desktop sync send // FREEBIE --- src/org/thoughtcrime/securesms/ConversationActivity.java | 2 +- .../thoughtcrime/securesms/ConversationListFragment.java | 2 +- src/org/thoughtcrime/securesms/database/ThreadDatabase.java | 6 +++++- src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java | 2 +- .../securesms/notifications/AndroidAutoHeardReceiver.java | 3 +-- .../securesms/notifications/AndroidAutoReplyReceiver.java | 3 +-- .../securesms/notifications/MarkReadReceiver.java | 4 +--- .../securesms/notifications/MessageNotifier.java | 2 +- .../securesms/notifications/RemoteReplyReceiver.java | 3 +-- 9 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index 85a4f64d19..5fb05fbef2 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -1443,7 +1443,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity @Override protected Void doInBackground(Long... params) { Context context = ConversationActivity.this; - List messageIds = DatabaseFactory.getThreadDatabase(context).setRead(params[0]); + List messageIds = DatabaseFactory.getThreadDatabase(context).setRead(params[0], false); MessageNotifier.updateNotification(context, masterSecret); MarkReadReceiver.process(context, messageIds); diff --git a/src/org/thoughtcrime/securesms/ConversationListFragment.java b/src/org/thoughtcrime/securesms/ConversationListFragment.java index d91a2d8301..c3d728b03c 100644 --- a/src/org/thoughtcrime/securesms/ConversationListFragment.java +++ b/src/org/thoughtcrime/securesms/ConversationListFragment.java @@ -476,7 +476,7 @@ public class ConversationListFragment extends Fragment DatabaseFactory.getThreadDatabase(getActivity()).archiveConversation(threadId); if (!read) { - List messageIds = DatabaseFactory.getThreadDatabase(getActivity()).setRead(threadId); + List messageIds = DatabaseFactory.getThreadDatabase(getActivity()).setRead(threadId, false); MessageNotifier.updateNotification(getActivity(), masterSecret); MarkReadReceiver.process(getActivity(), messageIds); } diff --git a/src/org/thoughtcrime/securesms/database/ThreadDatabase.java b/src/org/thoughtcrime/securesms/database/ThreadDatabase.java index 0f16866b0f..73d23c638e 100644 --- a/src/org/thoughtcrime/securesms/database/ThreadDatabase.java +++ b/src/org/thoughtcrime/securesms/database/ThreadDatabase.java @@ -264,10 +264,14 @@ public class ThreadDatabase extends Database { notifyConversationListListeners(); } - public List setRead(long threadId) { + public List setRead(long threadId, boolean lastSeen) { ContentValues contentValues = new ContentValues(1); contentValues.put(READ, 1); + if (lastSeen) { + contentValues.put(LAST_SEEN, System.currentTimeMillis()); + } + SQLiteDatabase db = databaseHelper.getWritableDatabase(); db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {threadId+""}); diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 0335616404..defc6f3db6 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -373,7 +373,7 @@ public class PushDecryptJob extends ContextJob { } if (threadId != null) { - DatabaseFactory.getThreadDatabase(getContext()).setRead(threadId); + DatabaseFactory.getThreadDatabase(getContext()).setRead(threadId, true); MessageNotifier.updateNotification(getContext(), masterSecret.getMasterSecret().orNull()); } diff --git a/src/org/thoughtcrime/securesms/notifications/AndroidAutoHeardReceiver.java b/src/org/thoughtcrime/securesms/notifications/AndroidAutoHeardReceiver.java index d1691e6b54..ba0b235435 100644 --- a/src/org/thoughtcrime/securesms/notifications/AndroidAutoHeardReceiver.java +++ b/src/org/thoughtcrime/securesms/notifications/AndroidAutoHeardReceiver.java @@ -61,8 +61,7 @@ public class AndroidAutoHeardReceiver extends MasterSecretBroadcastReceiver { for (long threadId : threadIds) { Log.i(TAG, "Marking meassage as read: " + threadId); - List messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId); - DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId); + List messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, true); messageIdsCollection.addAll(messageIds); } diff --git a/src/org/thoughtcrime/securesms/notifications/AndroidAutoReplyReceiver.java b/src/org/thoughtcrime/securesms/notifications/AndroidAutoReplyReceiver.java index 81d3c46b00..dd29837f4f 100644 --- a/src/org/thoughtcrime/securesms/notifications/AndroidAutoReplyReceiver.java +++ b/src/org/thoughtcrime/securesms/notifications/AndroidAutoReplyReceiver.java @@ -90,8 +90,7 @@ public class AndroidAutoReplyReceiver extends MasterSecretBroadcastReceiver { replyThreadId = MessageSender.send(context, masterSecret, reply, threadId, false); } - List messageIds = DatabaseFactory.getThreadDatabase(context).setRead(replyThreadId); - DatabaseFactory.getThreadDatabase(context).setLastSeen(replyThreadId); + List messageIds = DatabaseFactory.getThreadDatabase(context).setRead(replyThreadId, true); MessageNotifier.updateNotification(context, masterSecret); MarkReadReceiver.process(context, messageIds); diff --git a/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java b/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java index 1314cc4b22..1d7d8cdede 100644 --- a/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java +++ b/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java @@ -45,10 +45,8 @@ public class MarkReadReceiver extends MasterSecretBroadcastReceiver { for (long threadId : threadIds) { Log.w(TAG, "Marking as read: " + threadId); - List messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId); + List messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, true); messageIdsCollection.addAll(messageIds); - - DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId); } process(context, messageIdsCollection); diff --git a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java index 555565fa2e..340cb61371 100644 --- a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java +++ b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java @@ -223,7 +223,7 @@ public class MessageNotifier { .getRecipientsForThreadId(threadId); if (isVisible) { - List messageIds = threads.setRead(threadId); + List messageIds = threads.setRead(threadId, false); MarkReadReceiver.process(context, messageIds); } diff --git a/src/org/thoughtcrime/securesms/notifications/RemoteReplyReceiver.java b/src/org/thoughtcrime/securesms/notifications/RemoteReplyReceiver.java index 74402483dc..b846c00056 100644 --- a/src/org/thoughtcrime/securesms/notifications/RemoteReplyReceiver.java +++ b/src/org/thoughtcrime/securesms/notifications/RemoteReplyReceiver.java @@ -80,8 +80,7 @@ public class RemoteReplyReceiver extends MasterSecretBroadcastReceiver { threadId = MessageSender.send(context, masterSecret, reply, -1, false); } - List messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId); - DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId); + List messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, true); MessageNotifier.updateNotification(context, masterSecret); MarkReadReceiver.process(context, messageIds);