mirror of
https://github.com/oxen-io/session-android.git
synced 2023-12-14 02:53:01 +01:00
a0e23612d4
This could be a sync message, delivery receipt, or some other message that isn't user-visible. The push notification content would need to indicate whether that's the case in order to be able to accurately display a notification // FREEBIE
56 lines
1.8 KiB
Java
56 lines
1.8 KiB
Java
package org.thoughtcrime.securesms.jobs;
|
|
|
|
import android.content.Context;
|
|
import android.util.Log;
|
|
|
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
|
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
|
import org.whispersystems.jobqueue.JobParameters;
|
|
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
|
|
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
|
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
|
|
|
|
import java.io.IOException;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import javax.inject.Inject;
|
|
|
|
public class PushNotificationReceiveJob extends PushReceivedJob implements InjectableType {
|
|
|
|
private static final String TAG = PushNotificationReceiveJob.class.getSimpleName();
|
|
|
|
@Inject transient SignalServiceMessageReceiver receiver;
|
|
|
|
public PushNotificationReceiveJob(Context context) {
|
|
super(context, JobParameters.newBuilder()
|
|
.withRequirement(new NetworkRequirement(context))
|
|
.withGroupId("__notification_received")
|
|
.withWakeLock(true, 30, TimeUnit.SECONDS).create());
|
|
}
|
|
|
|
@Override
|
|
public void onAdded() {}
|
|
|
|
@Override
|
|
public void onRun() throws IOException {
|
|
receiver.retrieveMessages(new SignalServiceMessageReceiver.MessageReceivedCallback() {
|
|
@Override
|
|
public void onMessage(SignalServiceEnvelope envelope) {
|
|
handle(envelope, false);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public boolean onShouldRetry(Exception e) {
|
|
Log.w(TAG, e);
|
|
return e instanceof PushNetworkException;
|
|
}
|
|
|
|
@Override
|
|
public void onCanceled() {
|
|
Log.w(TAG, "***** Failed to download pending message!");
|
|
// MessageNotifier.notifyMessagesPending(getContext());
|
|
}
|
|
}
|