diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt index a0e42a3660..f1176470cf 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt @@ -15,6 +15,7 @@ import kotlinx.coroutines.launch import org.session.libsession.messaging.messages.ExpirationConfiguration import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate import org.session.libsession.messaging.sending_receiving.MessageSender +import org.session.libsession.snode.SnodeAPI import org.session.libsession.utilities.SSKEnvironment.MessageExpirationManagerProtocol import org.session.libsession.utilities.TextSecurePreferences import org.session.libsession.utilities.recipients.Recipient @@ -108,7 +109,7 @@ class ExpirationSettingsViewModel( return@launch } - val expiryChangeTimestampMs = System.currentTimeMillis() + val expiryChangeTimestampMs = System.currentTimeMillis() + SnodeAPI.clockOffset storage.setExpirationConfiguration(ExpirationConfiguration(threadId, expirationTimer, expiryType, expiryChangeTimestampMs)) val message = ExpirationTimerUpdate(expirationTimer) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index 4e990d13c2..42aa3df770 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -3,13 +3,21 @@ package org.thoughtcrime.securesms.conversation.v2 import android.Manifest import android.animation.FloatEvaluator import android.animation.ValueAnimator -import android.content.* +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.content.DialogInterface +import android.content.Intent import android.content.res.Resources import android.database.Cursor import android.graphics.Rect import android.graphics.Typeface import android.net.Uri -import android.os.* +import android.os.AsyncTask +import android.os.Build +import android.os.Bundle +import android.os.Handler +import android.os.Looper import android.provider.MediaStore import android.text.TextUtils import android.util.Pair @@ -58,8 +66,13 @@ import org.session.libsession.messaging.sending_receiving.attachments.Attachment import org.session.libsession.messaging.sending_receiving.link_preview.LinkPreview import org.session.libsession.messaging.sending_receiving.quotes.QuoteModel import org.session.libsession.messaging.utilities.SessionId -import org.session.libsession.utilities.* +import org.session.libsession.snode.SnodeAPI +import org.session.libsession.utilities.Address import org.session.libsession.utilities.Address.Companion.fromSerialized +import org.session.libsession.utilities.GroupUtil +import org.session.libsession.utilities.MediaTypes +import org.session.libsession.utilities.Stub +import org.session.libsession.utilities.TextSecurePreferences import org.session.libsession.utilities.concurrent.SimpleTask import org.session.libsession.utilities.recipients.Recipient import org.session.libsession.utilities.recipients.Recipient.DisappearingState @@ -123,7 +136,14 @@ import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel.LinkPreviewState import org.thoughtcrime.securesms.mediasend.Media import org.thoughtcrime.securesms.mediasend.MediaSendActivity -import org.thoughtcrime.securesms.mms.* +import org.thoughtcrime.securesms.mms.AudioSlide +import org.thoughtcrime.securesms.mms.GifSlide +import org.thoughtcrime.securesms.mms.GlideApp +import org.thoughtcrime.securesms.mms.ImageSlide +import org.thoughtcrime.securesms.mms.MediaConstraints +import org.thoughtcrime.securesms.mms.Slide +import org.thoughtcrime.securesms.mms.SlideDeck +import org.thoughtcrime.securesms.mms.VideoSlide import org.thoughtcrime.securesms.permissions.Permissions import org.thoughtcrime.securesms.reactions.ReactionsDialogFragment import org.thoughtcrime.securesms.reactions.any.ReactWithAnyEmojiDialogFragment @@ -1070,7 +1090,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe // Create the message val recipient = viewModel.recipient ?: return val reactionMessage = VisibleMessage() - val emojiTimestamp = System.currentTimeMillis() + val emojiTimestamp = System.currentTimeMillis() + SnodeAPI.clockOffset reactionMessage.sentTimestamp = emojiTimestamp val author = textSecurePreferences.getLocalNumber()!! // Put the message in the database @@ -1103,7 +1123,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe private fun sendEmojiRemoval(emoji: String, originalMessage: MessageRecord) { val recipient = viewModel.recipient ?: return val message = VisibleMessage() - val emojiTimestamp = System.currentTimeMillis() + val emojiTimestamp = System.currentTimeMillis() + SnodeAPI.clockOffset message.sentTimestamp = emojiTimestamp val author = textSecurePreferences.getLocalNumber()!! reactionDb.deleteReaction(emoji, MessageId(originalMessage.id, originalMessage.isMms), author, false) @@ -1332,7 +1352,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe } // Create the message val message = VisibleMessage() - message.sentTimestamp = System.currentTimeMillis() + message.sentTimestamp = System.currentTimeMillis() + SnodeAPI.clockOffset message.text = text val expiresInMillis = (viewModel.expirationConfiguration?.durationSeconds ?: 0) * 1000L val outgoingTextMessage = OutgoingTextMessage.from(message, recipient, expiresInMillis) @@ -1356,7 +1376,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe val recipient = viewModel.recipient ?: return processMessageRequestApproval() // Create the message - val sentTimestampMs = System.currentTimeMillis() + val sentTimestampMs = System.currentTimeMillis() + SnodeAPI.clockOffset val message = VisibleMessage() message.sentTimestamp = sentTimestampMs message.text = body @@ -1375,7 +1395,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe } val expiresInMs = (viewModel.expirationConfiguration?.durationSeconds ?: 0) * 1000L val expireStartedAtMs = if (viewModel.expirationConfiguration?.expirationType == ExpirationType.DELETE_AFTER_SEND) { - sentTimestampMs + expiresInMs + sentTimestampMs } else 0 val outgoingTextMessage = OutgoingMediaMessage.from(message, recipient, attachments, localQuote, linkPreview, expiresInMs, expireStartedAtMs) // Clear the input bar diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index ddce0a44fb..a64a7e887b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -161,7 +161,7 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, val expirationConfig = getExpirationConfiguration(message.threadID ?: -1) val expiresIn = expirationConfig?.durationSeconds ?: 0 val expireStartedAt = if (expirationConfig?.expirationType == ExpirationType.DELETE_AFTER_SEND) { - message.sentTimestamp!! + (expiresIn * 1000L) + message.sentTimestamp!! } else 0 if (message.isMediaMessage() || attachments.isNotEmpty()) { val quote: Optional = if (quotes != null) Optional.of(quotes) else Optional.absent() diff --git a/app/src/main/java/org/thoughtcrime/securesms/repository/ConversationRepository.kt b/app/src/main/java/org/thoughtcrime/securesms/repository/ConversationRepository.kt index 00f5d72c7b..2e5fceedc3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/repository/ConversationRepository.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/repository/ConversationRepository.kt @@ -106,7 +106,7 @@ class DefaultConversationRepository @Inject constructor( val openGroup = lokiThreadDb.getOpenGroupChat(threadId) ?: return for (contact in contacts) { val message = VisibleMessage() - message.sentTimestamp = System.currentTimeMillis() + message.sentTimestamp = System.currentTimeMillis() + SnodeAPI.clockOffset val openGroupInvitation = OpenGroupInvitation() openGroupInvitation.name = openGroup.name openGroupInvitation.url = openGroup.joinURL diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java b/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java index 6ee3ecfda2..5e52d164ff 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java @@ -72,7 +72,7 @@ public class ExpiringMessageManager implements SSKEnvironment.MessageExpirationM String userPublicKey = TextSecurePreferences.getLocalNumber(context); String senderPublicKey = message.getSender(); long expireStartedAt = ExpirationType.DELETE_AFTER_SEND_VALUE != expiryType - ? 0 : message.getSentTimestamp() + (message.getDuration() * 1000L); + ? 0 : message.getSentTimestamp(); // Notify the user if (senderPublicKey == null || userPublicKey.equals(senderPublicKey)) { @@ -161,7 +161,7 @@ public class ExpiringMessageManager implements SSKEnvironment.MessageExpirationM } else { smsDatabase.markExpireStarted(messageRecord.getId(), expireStartedAt); } - scheduleDeletion(messageRecord.getId(), mms, config.getDurationSeconds() * 1000L); + scheduleDeletion(messageRecord.getId(), mms, expireStartedAt, config.getDurationSeconds() * 1000L); } } diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt index 3cb62c4bef..b07a15f1fb 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt @@ -79,7 +79,7 @@ object MessageSender { val userPublicKey = storage.getUserPublicKey() // Set the timestamp, sender and recipient if (message.sentTimestamp == null) { - message.sentTimestamp = System.currentTimeMillis() // Visible messages will already have their sent timestamp set + message.sentTimestamp = System.currentTimeMillis() + SnodeAPI.clockOffset // Visible messages will already have their sent timestamp set } val messageSendTime = System.currentTimeMillis() @@ -238,7 +238,7 @@ object MessageSender { val deferred = deferred() val storage = MessagingModuleConfiguration.shared.storage if (message.sentTimestamp == null) { - message.sentTimestamp = System.currentTimeMillis() + message.sentTimestamp = System.currentTimeMillis() + SnodeAPI.clockOffset } val userEdKeyPair = MessagingModuleConfiguration.shared.getUserED25519KeyPair()!! var serverCapabilities = listOf() diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt index 3e013d88a6..debe7ab029 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt @@ -10,6 +10,7 @@ import org.session.libsession.messaging.messages.control.ClosedGroupControlMessa import org.session.libsession.messaging.sending_receiving.MessageSender.Error import org.session.libsession.messaging.sending_receiving.notifications.PushNotificationAPI import org.session.libsession.messaging.sending_receiving.pollers.ClosedGroupPollerV2 +import org.session.libsession.snode.SnodeAPI import org.session.libsession.utilities.Address import org.session.libsession.utilities.Address.Companion.fromSerialized import org.session.libsession.utilities.GroupUtil @@ -53,7 +54,7 @@ fun MessageSender.create(name: String, members: Collection): Promise) val name = group.title // Send the update to the group val memberUpdateKind = ClosedGroupControlMessage.Kind.MembersAdded(newMembersAsData) - val sentTime = System.currentTimeMillis() + val sentTime = System.currentTimeMillis() + SnodeAPI.clockOffset val closedGroupControlMessage = ClosedGroupControlMessage(memberUpdateKind) closedGroupControlMessage.sentTimestamp = sentTime send(closedGroupControlMessage, Address.fromSerialized(groupID)) @@ -167,7 +168,7 @@ fun MessageSender.addMembers(groupPublicKey: String, membersToAdd: List) // updates from before that timestamp. By setting the timestamp of the message below to a value // greater than that of the `MembersAdded` message, we ensure that newly added members ignore // the `MembersAdded` message. - closedGroupControlMessage.sentTimestamp = System.currentTimeMillis() + closedGroupControlMessage.sentTimestamp = System.currentTimeMillis() + SnodeAPI.clockOffset send(closedGroupControlMessage, Address.fromSerialized(member)) } // Notify the user @@ -208,7 +209,7 @@ fun MessageSender.removeMembers(groupPublicKey: String, membersToRemove: List if (newValue > oldValue) { Log.d("Loki", "Setting new fork info new: $newValue, old: $oldValue")