diff --git a/.travis.yml b/.travis.yml index 4af69e484..239637ba4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ android: - '.+' before_script: - mkdir libs - - wget -O libs/libwebrtc-m85.aar http://gultsch.de/files/libwebrtc-m85.aar + - wget -O libs/libwebrtc-m85.aar https://gultsch.de/files/libwebrtc-m85.aar script: - ./gradlew assembleConversationsFreeSystemRelease - ./gradlew assembleQuicksyFreeCompatRelease diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index 1a28ba20e..cdd891966 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -186,6 +186,18 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl return null; } + public int countFailedDeliveries() { + int count = 0; + synchronized (this.messages) { + for(final Message message : this.messages) { + if (message.getStatus() == Message.STATUS_SEND_FAILED) { + ++count; + } + } + } + return count; + } + public Message getLastEditableMessage() { synchronized (this.messages) { for (final Message message : Lists.reverse(this.messages)) { diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index a77b923f2..500f95a54 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -83,6 +83,7 @@ public class NotificationService { private static final int ERROR_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 6; private static final int INCOMING_CALL_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 8; public static final int ONGOING_CALL_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 10; + private static final int DELIVERY_FAILED_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 12; private final XmppConnectionService mXmppConnectionService; private final LinkedHashMap> notifications = new LinkedHashMap<>(); private final HashMap mBacklogMessageCounter = new HashMap<>(); @@ -221,9 +222,20 @@ public class NotificationService { quietHoursChannel.setSound(null, null); notificationManager.createNotificationChannel(quietHoursChannel); + + final NotificationChannel deliveryFailedChannel = new NotificationChannel("delivery_failed", + c.getString(R.string.delivery_failed_channel_name), + NotificationManager.IMPORTANCE_DEFAULT); + deliveryFailedChannel.setShowBadge(false); + deliveryFailedChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), new AudioAttributes.Builder() + .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) + .setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT) + .build()); + deliveryFailedChannel.setGroup("chats"); + notificationManager.createNotificationChannel(deliveryFailedChannel); } - public boolean notify(final Message message) { + private boolean notify(final Message message) { final Conversation conversation = (Conversation) message.getConversation(); return message.getStatus() == Message.STATUS_RECEIVED && !conversation.isMuted() @@ -343,6 +355,37 @@ public class NotificationService { } } + public void pushFailedDelivery(final Message message) { + final Conversation conversation = (Conversation) message.getConversation(); + final boolean isScreenOn = mXmppConnectionService.isInteractive(); + if (this.mIsInForeground && isScreenOn && this.mOpenConversation == message.getConversation()) { + Log.d(Config.LOGTAG, message.getConversation().getAccount().getJid().asBareJid() + ": suppressing failed delivery notification because conversation is open"); + return; + } + final PendingIntent pendingIntent = createContentIntent(conversation); + final int notificationId = generateRequestCode(conversation, 0) + DELIVERY_FAILED_NOTIFICATION_ID; + final int failedDeliveries = conversation.countFailedDeliveries(); + final Notification notification = + new Builder(mXmppConnectionService, "delivery_failed") + .setContentTitle(conversation.getName()) + .setAutoCancel(true) + .setSmallIcon(R.drawable.ic_error_white_24dp) + .setContentText(mXmppConnectionService.getResources().getQuantityText(R.plurals.some_messages_could_not_be_delivered, failedDeliveries)) + .setGroup("delivery_failed") + .setContentIntent(pendingIntent).build(); + final Notification summaryNotification = + new Builder(mXmppConnectionService, "delivery_failed") + .setContentTitle(mXmppConnectionService.getString(R.string.failed_deliveries)) + .setContentText(mXmppConnectionService.getResources().getQuantityText(R.plurals.some_messages_could_not_be_delivered, 1024)) + .setSmallIcon(R.drawable.ic_error_white_24dp) + .setGroup("delivery_failed") + .setGroupSummary(true) + .setAutoCancel(true) + .build(); + notify(notificationId, notification); + notify(DELIVERY_FAILED_NOTIFICATION_ID, summaryNotification); + } + public void showIncomingCallNotification(final AbstractJingleConnection.Id id, final Set media) { final Intent fullScreenIntent = new Intent(mXmppConnectionService, RtpSessionActivity.class); fullScreenIntent.putExtra(RtpSessionActivity.EXTRA_ACCOUNT, id.account.getJid().asBareJid().toEscapedString()); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index d539ff30f..3225be67d 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -3922,7 +3922,7 @@ public class XmppConnectionService extends Service { } - public void markMessage(Message message, int status, String errorMessage) { + public void markMessage(final Message message, final int status, final String errorMessage) { final int oldStatus = message.getStatus(); if (status == Message.STATUS_SEND_FAILED && (oldStatus == Message.STATUS_SEND_RECEIVED || oldStatus == Message.STATUS_SEND_DISPLAYED)) { return; @@ -3934,6 +3934,9 @@ public class XmppConnectionService extends Service { message.setStatus(status); databaseBackend.updateMessage(message, false); updateConversationUi(); + if (oldStatus != status && status == Message.STATUS_SEND_FAILED) { + mNotificationService.pushFailedDelivery(message); + } } private SharedPreferences getPreferences() { diff --git a/src/main/res/drawable-hdpi/ic_error_white_24dp.png b/src/main/res/drawable-hdpi/ic_error_white_24dp.png new file mode 100644 index 000000000..69cbb1e0b Binary files /dev/null and b/src/main/res/drawable-hdpi/ic_error_white_24dp.png differ diff --git a/src/main/res/drawable-mdpi/ic_error_white_24dp.png b/src/main/res/drawable-mdpi/ic_error_white_24dp.png new file mode 100644 index 000000000..ca148fc7c Binary files /dev/null and b/src/main/res/drawable-mdpi/ic_error_white_24dp.png differ diff --git a/src/main/res/drawable-xhdpi/ic_error_white_24dp.png b/src/main/res/drawable-xhdpi/ic_error_white_24dp.png new file mode 100644 index 000000000..9829698dd Binary files /dev/null and b/src/main/res/drawable-xhdpi/ic_error_white_24dp.png differ diff --git a/src/main/res/drawable-xxhdpi/ic_error_white_24dp.png b/src/main/res/drawable-xxhdpi/ic_error_white_24dp.png new file mode 100644 index 000000000..abe2573b1 Binary files /dev/null and b/src/main/res/drawable-xxhdpi/ic_error_white_24dp.png differ diff --git a/src/main/res/drawable-xxxhdpi/ic_error_white_24dp.png b/src/main/res/drawable-xxxhdpi/ic_error_white_24dp.png new file mode 100644 index 000000000..830fb7e1e Binary files /dev/null and b/src/main/res/drawable-xxxhdpi/ic_error_white_24dp.png differ diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 9668be52e..81c9083ec 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -755,6 +755,7 @@ Ongoing calls Silent messages This notification group is used to display notifications that should not trigger any sound. For example when being active on another device (Grace Period). + Failed deliveries Message notification settings Incoming calls notification settings Importance, Sound, Vibrate @@ -942,4 +943,9 @@ View %1$d Participant View %1$d Participants + + A message could not be delivered + Some messages could not be delivered + + Failed deliveries