mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
Clean
This commit is contained in:
parent
f91b493dd3
commit
2ea009b05b
@ -41,7 +41,6 @@ import org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl;
|
|||||||
import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore;
|
import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore;
|
||||||
import org.thoughtcrime.securesms.database.Address;
|
import org.thoughtcrime.securesms.database.Address;
|
||||||
import org.thoughtcrime.securesms.database.AttachmentDatabase;
|
import org.thoughtcrime.securesms.database.AttachmentDatabase;
|
||||||
import org.thoughtcrime.securesms.database.Database;
|
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
import org.thoughtcrime.securesms.database.GroupDatabase;
|
import org.thoughtcrime.securesms.database.GroupDatabase;
|
||||||
import org.thoughtcrime.securesms.database.GroupReceiptDatabase;
|
import org.thoughtcrime.securesms.database.GroupReceiptDatabase;
|
||||||
@ -282,7 +281,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
|
|
||||||
// Loki - Ignore any friend requests that we got before restoration
|
// Loki - Ignore any friend requests that we got before restoration
|
||||||
if (envelope.isFriendRequest() && envelope.getTimestamp() < TextSecurePreferences.getRestorationTime(context)) {
|
if (envelope.isFriendRequest() && envelope.getTimestamp() < TextSecurePreferences.getRestorationTime(context)) {
|
||||||
Log.i(TAG, "Ignoring friend request that was received before restoration");
|
Log.d("Loki", "Ignoring friend request received before restoration.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,7 +338,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
MultiDeviceUtilities.checkForRevocation(context);
|
MultiDeviceUtilities.checkForRevocation(context);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Loki - We shouldn't process session restore message any further
|
// Loki - Don't process session restore message any further
|
||||||
if (message.isSessionRestore()) { return; }
|
if (message.isSessionRestore()) { return; }
|
||||||
if (message.isEndSession()) handleEndSessionMessage(content, smsMessageId);
|
if (message.isEndSession()) handleEndSessionMessage(content, smsMessageId);
|
||||||
else if (message.isGroupUpdate()) handleGroupMessage(content, message, smsMessageId);
|
else if (message.isGroupUpdate()) handleGroupMessage(content, message, smsMessageId);
|
||||||
@ -1199,18 +1198,18 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
|
ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
|
||||||
LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
||||||
|
|
||||||
// Store the latest PreKeyBundle
|
// Loki - Store the latest pre key bundle
|
||||||
if (registrationID > 0) {
|
if (registrationID > 0) {
|
||||||
Log.d("Loki", "Received a pre key bundle from: " + content.getSender() + ".");
|
Log.d("Loki", "Received a pre key bundle from: " + content.getSender() + ".");
|
||||||
PreKeyBundle preKeyBundle = lokiMessage.getPreKeyBundleMessage().getPreKeyBundle(registrationID);
|
PreKeyBundle preKeyBundle = lokiMessage.getPreKeyBundleMessage().getPreKeyBundle(registrationID);
|
||||||
lokiPreKeyBundleDatabase.setPreKeyBundle(content.getSender(), preKeyBundle);
|
lokiPreKeyBundleDatabase.setPreKeyBundle(content.getSender(), preKeyBundle);
|
||||||
|
|
||||||
// If we got a friend request and we were friends with this user then we need to reset our session
|
// Loki - If we received a friend request, but we were already friends with this user, then reset the session
|
||||||
if (envelope.isFriendRequest()) {
|
if (envelope.isFriendRequest()) {
|
||||||
long threadID = threadDatabase.getThreadIdIfExistsFor(sender);
|
long threadID = threadDatabase.getThreadIdIfExistsFor(sender);
|
||||||
if (lokiThreadDatabase.getFriendRequestStatus(threadID) == LokiThreadFriendRequestStatus.FRIENDS) {
|
if (lokiThreadDatabase.getFriendRequestStatus(threadID) == LokiThreadFriendRequestStatus.FRIENDS) {
|
||||||
resetSession(content.getSender(), threadID);
|
resetSession(content.getSender(), threadID);
|
||||||
// Let our other devices know that we have reset session
|
// Let our other devices know that we have reset the session
|
||||||
MessageSender.syncContact(context, sender.getAddress());
|
MessageSender.syncContact(context, sender.getAddress());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1388,13 +1387,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
|
SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
|
||||||
Recipient recipient = Recipient.from(context, Address.fromSerialized(sender), false);
|
Recipient recipient = Recipient.from(context, Address.fromSerialized(sender), false);
|
||||||
long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(recipient);
|
long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(recipient);
|
||||||
if (threadID < 0) {
|
if (threadID < 0) { return null; }
|
||||||
return null;
|
|
||||||
}
|
|
||||||
int messageCount = smsDatabase.getMessageCountForThread(threadID);
|
int messageCount = smsDatabase.getMessageCountForThread(threadID);
|
||||||
if (messageCount <= 0) {
|
if (messageCount <= 0) { return null; }
|
||||||
return null;
|
|
||||||
}
|
|
||||||
long lastMessageID = smsDatabase.getIDForMessageAtIndex(threadID, messageCount - 1);
|
long lastMessageID = smsDatabase.getIDForMessageAtIndex(threadID, messageCount - 1);
|
||||||
return smsDatabase.getMessage(lastMessageID);
|
return smsDatabase.getMessage(lastMessageID);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -13,30 +13,23 @@ import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage
|
|||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress
|
||||||
import org.whispersystems.signalservice.internal.util.JsonUtil
|
import org.whispersystems.signalservice.internal.util.JsonUtil
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.lang.IllegalStateException
|
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
data class BackgroundMessage private constructor(val data: Map<String, Any>) {
|
data class BackgroundMessage private constructor(val data: Map<String, Any>) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun create(recipient: String) = BackgroundMessage(mapOf("recipient" to recipient))
|
fun create(recipient: String) = BackgroundMessage(mapOf("recipient" to recipient))
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun createFriendRequest(recipient: String, messageBody: String) = BackgroundMessage(mapOf(
|
fun createFriendRequest(recipient: String, messageBody: String) = BackgroundMessage(mapOf( "recipient" to recipient, "body" to messageBody, "friendRequest" to true ))
|
||||||
"recipient" to recipient,
|
|
||||||
"body" to messageBody,
|
|
||||||
"friendRequest" to true
|
|
||||||
))
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun createUnpairingRequest(recipient: String) = BackgroundMessage(mapOf(
|
fun createUnpairingRequest(recipient: String) = BackgroundMessage(mapOf( "recipient" to recipient, "unpairingRequest" to true ))
|
||||||
"recipient" to recipient,
|
|
||||||
"unpairingRequest" to true
|
|
||||||
))
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun createSessionRestore(recipient: String) = BackgroundMessage(mapOf(
|
fun createSessionRestore(recipient: String) = BackgroundMessage(mapOf( "recipient" to recipient, "friendRequest" to true, "sessionRestore" to true ))
|
||||||
"recipient" to recipient,
|
|
||||||
"friendRequest" to true,
|
|
||||||
"sessionRestore" to true
|
|
||||||
))
|
|
||||||
|
|
||||||
internal fun parse(serialized: String): BackgroundMessage {
|
internal fun parse(serialized: String): BackgroundMessage {
|
||||||
val data = JsonUtil.fromJson(serialized, Map::class.java) as? Map<String, Any> ?: throw AssertionError("JSON parsing failed")
|
val data = JsonUtil.fromJson(serialized, Map::class.java) as? Map<String, Any> ?: throw AssertionError("JSON parsing failed")
|
||||||
|
@ -129,6 +129,7 @@ class RegisterActivity : BaseActionBarActivity() {
|
|||||||
IdentityKeyUtil.getIdentityKeyPair(this).publicKey, IdentityDatabase.VerifiedStatus.VERIFIED,
|
IdentityKeyUtil.getIdentityKeyPair(this).publicKey, IdentityDatabase.VerifiedStatus.VERIFIED,
|
||||||
true, System.currentTimeMillis(), true)
|
true, System.currentTimeMillis(), true)
|
||||||
TextSecurePreferences.setLocalNumber(this, userHexEncodedPublicKey)
|
TextSecurePreferences.setLocalNumber(this, userHexEncodedPublicKey)
|
||||||
|
TextSecurePreferences.setRestorationTime(this, 0)
|
||||||
TextSecurePreferences.setHasViewedSeed(this, false)
|
TextSecurePreferences.setHasViewedSeed(this, false)
|
||||||
val intent = Intent(this, DisplayNameActivity::class.java)
|
val intent = Intent(this, DisplayNameActivity::class.java)
|
||||||
push(intent)
|
push(intent)
|
||||||
|
@ -87,6 +87,7 @@ class RestoreActivity : BaseActionBarActivity() {
|
|||||||
IdentityKeyUtil.getIdentityKeyPair(this).publicKey, IdentityDatabase.VerifiedStatus.VERIFIED,
|
IdentityKeyUtil.getIdentityKeyPair(this).publicKey, IdentityDatabase.VerifiedStatus.VERIFIED,
|
||||||
true, System.currentTimeMillis(), true)
|
true, System.currentTimeMillis(), true)
|
||||||
TextSecurePreferences.setLocalNumber(this, userHexEncodedPublicKey)
|
TextSecurePreferences.setLocalNumber(this, userHexEncodedPublicKey)
|
||||||
|
TextSecurePreferences.setRestorationTime(this, System.currentTimeMillis())
|
||||||
TextSecurePreferences.setHasViewedSeed(this, true)
|
TextSecurePreferences.setHasViewedSeed(this, true)
|
||||||
val intent = Intent(this, DisplayNameActivity::class.java)
|
val intent = Intent(this, DisplayNameActivity::class.java)
|
||||||
push(intent)
|
push(intent)
|
||||||
|
Loading…
Reference in New Issue
Block a user