mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-24 06:02:22 +00:00
Support for retrieving stored messages via websocket.
1) When registering with server, indicate that the server should store messages and send notifications. 2) Process notification GCM messages, and connect to the server to retrieve actual message content.
This commit is contained in:
@@ -23,6 +23,7 @@ import org.whispersystems.libaxolotl.InvalidMessageException;
|
||||
import org.whispersystems.textsecure.api.crypto.AttachmentCipherInputStream;
|
||||
import org.whispersystems.textsecure.internal.push.PushServiceSocket;
|
||||
import org.whispersystems.textsecure.api.push.exceptions.NonSuccessfulResponseCodeException;
|
||||
import org.whispersystems.textsecure.internal.util.StaticCredentialsProvider;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -99,8 +100,9 @@ public class AvatarDownloadJob extends MasterSecretJob {
|
||||
private File downloadAttachment(String relay, long contentLocation) throws IOException {
|
||||
PushServiceSocket socket = new PushServiceSocket(Release.PUSH_URL,
|
||||
new TextSecurePushTrustStore(context),
|
||||
TextSecurePreferences.getLocalNumber(context),
|
||||
TextSecurePreferences.getPushServerPassword(context));
|
||||
new StaticCredentialsProvider(TextSecurePreferences.getLocalNumber(context),
|
||||
TextSecurePreferences.getPushServerPassword(context),
|
||||
null));
|
||||
|
||||
File destination = File.createTempFile("avatar", "tmp");
|
||||
|
||||
|
||||
@@ -221,10 +221,12 @@ public class PushDecryptJob extends MasterSecretJob {
|
||||
}
|
||||
|
||||
private void handleDuplicateMessage(MasterSecret masterSecret, TextSecureEnvelope envelope) {
|
||||
Pair<Long, Long> messageAndThreadId = insertPlaceholder(masterSecret, envelope);
|
||||
DatabaseFactory.getEncryptingSmsDatabase(context).markAsDecryptDuplicate(messageAndThreadId.first);
|
||||
// Let's start ignoring these now.
|
||||
|
||||
MessageNotifier.updateNotification(context, masterSecret, messageAndThreadId.second);
|
||||
// Pair<Long, Long> messageAndThreadId = insertPlaceholder(masterSecret, envelope);
|
||||
// DatabaseFactory.getEncryptingSmsDatabase(context).markAsDecryptDuplicate(messageAndThreadId.first);
|
||||
//
|
||||
// MessageNotifier.updateNotification(context, masterSecret, messageAndThreadId.second);
|
||||
}
|
||||
|
||||
private void handleUntrustedIdentityMessage(MasterSecret masterSecret, TextSecureEnvelope envelope) {
|
||||
|
||||
@@ -22,6 +22,11 @@ public class PushReceiveJob extends ContextJob {
|
||||
|
||||
private final String data;
|
||||
|
||||
public PushReceiveJob(Context context) {
|
||||
super(context, JobParameters.newBuilder().create());
|
||||
this.data = null;
|
||||
}
|
||||
|
||||
public PushReceiveJob(Context context, String data) {
|
||||
super(context, JobParameters.newBuilder()
|
||||
.withPersistence()
|
||||
@@ -39,16 +44,7 @@ public class PushReceiveJob extends ContextJob {
|
||||
String sessionKey = TextSecurePreferences.getSignalingKey(context);
|
||||
TextSecureEnvelope envelope = new TextSecureEnvelope(data, sessionKey);
|
||||
|
||||
if (!isActiveNumber(context, envelope.getSource())) {
|
||||
TextSecureDirectory directory = TextSecureDirectory.getInstance(context);
|
||||
ContactTokenDetails contactTokenDetails = new ContactTokenDetails();
|
||||
contactTokenDetails.setNumber(envelope.getSource());
|
||||
|
||||
directory.setNumber(contactTokenDetails, true);
|
||||
}
|
||||
|
||||
if (envelope.isReceipt()) handleReceipt(envelope);
|
||||
else handleMessage(envelope);
|
||||
handle(envelope, true);
|
||||
} catch (IOException | InvalidVersionException e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
@@ -64,13 +60,28 @@ public class PushReceiveJob extends ContextJob {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void handleMessage(TextSecureEnvelope envelope) {
|
||||
public void handle(TextSecureEnvelope envelope, boolean sendExplicitReceipt) {
|
||||
if (!isActiveNumber(context, envelope.getSource())) {
|
||||
TextSecureDirectory directory = TextSecureDirectory.getInstance(context);
|
||||
ContactTokenDetails contactTokenDetails = new ContactTokenDetails();
|
||||
contactTokenDetails.setNumber(envelope.getSource());
|
||||
|
||||
directory.setNumber(contactTokenDetails, true);
|
||||
}
|
||||
|
||||
if (envelope.isReceipt()) handleReceipt(envelope);
|
||||
else handleMessage(envelope, sendExplicitReceipt);
|
||||
}
|
||||
|
||||
private void handleMessage(TextSecureEnvelope envelope, boolean sendExplicitReceipt) {
|
||||
JobManager jobManager = ApplicationContext.getInstance(context).getJobManager();
|
||||
long messageId = DatabaseFactory.getPushDatabase(context).insert(envelope);
|
||||
|
||||
jobManager.add(new DeliveryReceiptJob(context, envelope.getSource(),
|
||||
envelope.getTimestamp(),
|
||||
envelope.getRelay()));
|
||||
if (sendExplicitReceipt) {
|
||||
jobManager.add(new DeliveryReceiptJob(context, envelope.getSource(),
|
||||
envelope.getTimestamp(),
|
||||
envelope.getRelay()));
|
||||
}
|
||||
|
||||
jobManager.add(new PushDecryptJob(context, messageId));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user