mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +00:00
Trigger session reset if we got a new friend request from one of our friends.
This commit is contained in:
parent
3bdae214c1
commit
5e5309d07e
@ -42,6 +42,7 @@ 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;
|
||||||
@ -532,21 +533,24 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (threadId != null) {
|
if (threadId != null) {
|
||||||
|
resetSession(content.getSender(), threadId);
|
||||||
|
MessageNotifier.updateNotification(context, threadId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetSession(String hexEncodedPublicKey, long threadId) {
|
||||||
TextSecureSessionStore sessionStore = new TextSecureSessionStore(context);
|
TextSecureSessionStore sessionStore = new TextSecureSessionStore(context);
|
||||||
LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
||||||
|
|
||||||
Log.d("Loki", "Received a session reset request from: " + content.getSender() + "; archiving the session.");
|
Log.d("Loki", "Received a session reset request from: " + hexEncodedPublicKey + "; archiving the session.");
|
||||||
|
|
||||||
sessionStore.archiveAllSessions(content.getSender());
|
sessionStore.archiveAllSessions(hexEncodedPublicKey);
|
||||||
lokiThreadDatabase.setSessionResetStatus(threadId, LokiThreadSessionResetStatus.REQUEST_RECEIVED);
|
lokiThreadDatabase.setSessionResetStatus(threadId, LokiThreadSessionResetStatus.REQUEST_RECEIVED);
|
||||||
|
|
||||||
Log.d("Loki", "Sending a ping back to " + content.getSender() + ".");
|
Log.d("Loki", "Sending a ping back to " + hexEncodedPublicKey + ".");
|
||||||
String contactID = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadId).getAddress().toString();
|
MessageSender.sendBackgroundMessage(context, hexEncodedPublicKey);
|
||||||
MessageSender.sendBackgroundMessage(context, contactID);
|
|
||||||
|
|
||||||
SecurityEvent.broadcastSecurityUpdateEvent(context);
|
SecurityEvent.broadcastSecurityUpdateEvent(context);
|
||||||
MessageNotifier.updateNotification(context, threadId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private long handleSynchronizeSentEndSessionMessage(@NonNull SentTranscriptMessage message)
|
private long handleSynchronizeSentEndSessionMessage(@NonNull SentTranscriptMessage message)
|
||||||
@ -1185,12 +1189,23 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
if (lokiMessage.getPreKeyBundleMessage() != null) {
|
if (lokiMessage.getPreKeyBundleMessage() != null) {
|
||||||
int registrationID = TextSecurePreferences.getLocalRegistrationId(context);
|
int registrationID = TextSecurePreferences.getLocalRegistrationId(context);
|
||||||
LokiPreKeyBundleDatabase lokiPreKeyBundleDatabase = DatabaseFactory.getLokiPreKeyBundleDatabase(context);
|
LokiPreKeyBundleDatabase lokiPreKeyBundleDatabase = DatabaseFactory.getLokiPreKeyBundleDatabase(context);
|
||||||
|
ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
|
||||||
|
LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
||||||
|
|
||||||
// Store the latest PreKeyBundle
|
// Store the latest PreKeyBundle
|
||||||
if (registrationID > 0) {
|
if (registrationID > 0) {
|
||||||
Log.d("Loki", "Received a pre key bundle from: " + envelope.getSource() + ".");
|
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(envelope.getSource(), 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
|
||||||
|
if (envelope.isFriendRequest()) {
|
||||||
|
Recipient sender = Recipient.from(context, Address.fromSerialized(content.getSender()), false);
|
||||||
|
long threadID = threadDatabase.getThreadIdIfExistsFor(sender);
|
||||||
|
if (lokiThreadDatabase.getFriendRequestStatus(threadID) == LokiThreadFriendRequestStatus.FRIENDS) {
|
||||||
|
resetSession(content.getSender(), threadID);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user