mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-18 23:18:26 +00:00
Display a notification when unable retrieve messages for push
Fixes #6684 // FREEBIE
This commit is contained in:
parent
cd55feb2b9
commit
73410f64b5
@ -670,6 +670,8 @@
|
|||||||
<string name="MessageNotifier_mark_read">Mark read</string>
|
<string name="MessageNotifier_mark_read">Mark read</string>
|
||||||
<string name="MessageNotifier_media_message">Media message</string>
|
<string name="MessageNotifier_media_message">Media message</string>
|
||||||
<string name="MessageNotifier_reply">Reply</string>
|
<string name="MessageNotifier_reply">Reply</string>
|
||||||
|
<string name="MessageNotifier_pending_signal_messages">Pending Signal messages</string>
|
||||||
|
<string name="MessageNotifier_you_have_pending_signal_messages">You have pending Signal messages, tap to open and retrieve</string>
|
||||||
|
|
||||||
<!-- MmsPreferencesFragment -->
|
<!-- MmsPreferencesFragment -->
|
||||||
<string name="MmsPreferencesFragment__manual_mms_settings_are_required">Manual MMS settings are required for your phone.</string>
|
<string name="MmsPreferencesFragment__manual_mms_settings_are_required">Manual MMS settings are required for your phone.</string>
|
||||||
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
||||||
|
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||||
import org.whispersystems.jobqueue.JobParameters;
|
import org.whispersystems.jobqueue.JobParameters;
|
||||||
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
|
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
|
||||||
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
|
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
|
||||||
@ -50,5 +51,6 @@ public class PushNotificationReceiveJob extends PushReceivedJob implements Injec
|
|||||||
@Override
|
@Override
|
||||||
public void onCanceled() {
|
public void onCanceled() {
|
||||||
Log.w(TAG, "***** Failed to download pending message!");
|
Log.w(TAG, "***** Failed to download pending message!");
|
||||||
|
MessageNotifier.notifyMessagesPending(getContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,7 @@ public class MessageNotifier {
|
|||||||
public static final String EXTRA_REMOTE_REPLY = "extra_remote_reply";
|
public static final String EXTRA_REMOTE_REPLY = "extra_remote_reply";
|
||||||
|
|
||||||
private static final int SUMMARY_NOTIFICATION_ID = 1338;
|
private static final int SUMMARY_NOTIFICATION_ID = 1338;
|
||||||
|
private static final int PENDING_MESSAGES_ID = 1111;
|
||||||
private static final String NOTIFICATION_GROUP = "messages";
|
private static final String NOTIFICATION_GROUP = "messages";
|
||||||
private static final long MIN_AUDIBLE_PERIOD_MILLIS = TimeUnit.SECONDS.toMillis(2);
|
private static final long MIN_AUDIBLE_PERIOD_MILLIS = TimeUnit.SECONDS.toMillis(2);
|
||||||
private static final long DESKTOP_ACTIVITY_PERIOD = TimeUnit.MINUTES.toMillis(1);
|
private static final long DESKTOP_ACTIVITY_PERIOD = TimeUnit.MINUTES.toMillis(1);
|
||||||
@ -116,6 +117,15 @@ public class MessageNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void notifyMessagesPending(Context context) {
|
||||||
|
if (!TextSecurePreferences.isNotificationsEnabled(context)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PendingMessageNotificationBuilder builder = new PendingMessageNotificationBuilder(context, TextSecurePreferences.getNotificationPrivacy(context));
|
||||||
|
ServiceUtil.getNotificationManager(context).notify(PENDING_MESSAGES_ID, builder.build());
|
||||||
|
}
|
||||||
|
|
||||||
public static void cancelDelayedNotifications() {
|
public static void cancelDelayedNotifications() {
|
||||||
executor.cancel();
|
executor.cancel();
|
||||||
}
|
}
|
||||||
@ -153,7 +163,8 @@ public class MessageNotifier {
|
|||||||
if (notification.getId() != SUMMARY_NOTIFICATION_ID &&
|
if (notification.getId() != SUMMARY_NOTIFICATION_ID &&
|
||||||
notification.getId() != CallNotificationBuilder.WEBRTC_NOTIFICATION &&
|
notification.getId() != CallNotificationBuilder.WEBRTC_NOTIFICATION &&
|
||||||
notification.getId() != KeyCachingService.SERVICE_RUNNING_ID &&
|
notification.getId() != KeyCachingService.SERVICE_RUNNING_ID &&
|
||||||
notification.getId() != MessageRetrievalService.FOREGROUND_ID)
|
notification.getId() != MessageRetrievalService.FOREGROUND_ID &&
|
||||||
|
notification.getId() != PENDING_MESSAGES_ID)
|
||||||
{
|
{
|
||||||
for (NotificationItem item : notificationState.getNotifications()) {
|
for (NotificationItem item : notificationState.getNotifications()) {
|
||||||
if (notification.getId() == (SUMMARY_NOTIFICATION_ID + item.getThreadId())) {
|
if (notification.getId() == (SUMMARY_NOTIFICATION_ID + item.getThreadId())) {
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
package org.thoughtcrime.securesms.notifications;
|
||||||
|
|
||||||
|
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.ConversationListActivity;
|
||||||
|
import org.thoughtcrime.securesms.R;
|
||||||
|
import org.thoughtcrime.securesms.database.RecipientPreferenceDatabase;
|
||||||
|
import org.thoughtcrime.securesms.preferences.NotificationPrivacyPreference;
|
||||||
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
|
||||||
|
public class PendingMessageNotificationBuilder extends AbstractNotificationBuilder {
|
||||||
|
|
||||||
|
public PendingMessageNotificationBuilder(Context context, NotificationPrivacyPreference privacy) {
|
||||||
|
super(context, privacy);
|
||||||
|
|
||||||
|
Intent intent = new Intent(context, ConversationListActivity.class);
|
||||||
|
|
||||||
|
setSmallIcon(R.drawable.icon_notification);
|
||||||
|
setColor(context.getResources().getColor(R.color.textsecure_primary));
|
||||||
|
setPriority(TextSecurePreferences.getNotificationPriority(context));
|
||||||
|
setCategory(NotificationCompat.CATEGORY_MESSAGE);
|
||||||
|
|
||||||
|
setContentTitle(context.getString(R.string.MessageNotifier_pending_signal_messages));
|
||||||
|
setContentText(context.getString(R.string.MessageNotifier_you_have_pending_signal_messages));
|
||||||
|
setTicker(context.getString(R.string.MessageNotifier_you_have_pending_signal_messages));
|
||||||
|
|
||||||
|
setContentIntent(PendingIntent.getActivity(context, 0, intent, 0));
|
||||||
|
setAutoCancel(true);
|
||||||
|
setAlarms(null, RecipientPreferenceDatabase.VibrateState.DEFAULT);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user