mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-24 13:19:12 +00:00
Support for robust delivery.
1) If a message fails to be delivered, post a notification in the status bar if that thread is not active and visible. 2) If a message fails to be delivered because there is no service, keep retrying every time service becomes available again.
This commit is contained in:
@@ -39,6 +39,7 @@ import android.util.Log;
|
||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||
import org.thoughtcrime.securesms.ConversationListActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.contacts.ContactPhotoFactory;
|
||||
import org.thoughtcrime.securesms.crypto.MasterCipher;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.crypto.MessageDisplayHelper;
|
||||
@@ -74,6 +75,33 @@ public class MessageNotifier {
|
||||
visibleThread = threadId;
|
||||
}
|
||||
|
||||
public static void notifyMessageDeliveryFailed(Context context, Recipients recipients, long threadId) {
|
||||
if (visibleThread == threadId) {
|
||||
sendInThreadNotification(context);
|
||||
} else {
|
||||
Intent intent = new Intent(context, ConversationListActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
intent.putExtra("recipients", recipients);
|
||||
intent.putExtra("thread_id", threadId);
|
||||
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
|
||||
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
||||
builder.setSmallIcon(R.drawable.icon_notification);
|
||||
builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
|
||||
R.drawable.ic_list_alert_sms_failed));
|
||||
builder.setContentTitle(context.getString(R.string.MessageNotifier_message_delivery_failed));
|
||||
builder.setContentText(context.getString(R.string.MessageNotifier_failed_to_deliver_message));
|
||||
builder.setTicker(context.getString(R.string.MessageNotifier_error_delivering_message));
|
||||
builder.setContentIntent(PendingIntent.getActivity(context, 0, intent, 0));
|
||||
builder.setAutoCancel(true);
|
||||
setNotificationAlarms(context, builder, true);
|
||||
|
||||
((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE))
|
||||
.notify((int)threadId, builder.build());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void updateNotification(Context context, MasterSecret masterSecret) {
|
||||
updateNotification(context, masterSecret, false);
|
||||
}
|
||||
@@ -286,7 +314,9 @@ public class MessageNotifier {
|
||||
return getMmsRecipient(context, cursor);
|
||||
}
|
||||
} catch (RecipientFormattingException e) {
|
||||
return new Recipients(new Recipient("Unknown", null, null));
|
||||
Log.w("MessageNotifier", e);
|
||||
return new Recipients(new Recipient("Unknown", "Unknown", null,
|
||||
ContactPhotoFactory.getDefaultContactPhoto(context)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user