Differential D9069 Diff 38942 native/android/app/src/main/java/app/comm/android/notifications/CommNotificationsHandler.java
Changeset View
Changeset View
Standalone View
Standalone View
native/android/app/src/main/java/app/comm/android/notifications/CommNotificationsHandler.java
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
public class CommNotificationsHandler extends FirebaseMessagingService { | public class CommNotificationsHandler extends FirebaseMessagingService { | ||||
private static final String BADGE_KEY = "badge"; | private static final String BADGE_KEY = "badge"; | ||||
private static final String BADGE_ONLY_KEY = "badgeOnly"; | private static final String BADGE_ONLY_KEY = "badgeOnly"; | ||||
private static final String SET_UNREAD_STATUS_KEY = "setUnreadStatus"; | private static final String SET_UNREAD_STATUS_KEY = "setUnreadStatus"; | ||||
private static final String NOTIF_ID_KEY = "id"; | private static final String NOTIF_ID_KEY = "id"; | ||||
private static final String ENCRYPTED_PAYLOAD_KEY = "encryptedPayload"; | private static final String ENCRYPTED_PAYLOAD_KEY = "encryptedPayload"; | ||||
private static final String ENCRYPTION_FAILED_KEY = "encryptionFailed"; | private static final String ENCRYPTION_FAILED_KEY = "encryptionFailed"; | ||||
private static final String BLOB_HASH_KEY = "blobHash"; | private static final String BLOB_HASH_KEY = "blobHash"; | ||||
private static final String BLOB_HOLDER_KEY = "blobHolder"; | |||||
private static final String AES_ENCRYPTION_KEY_LABEL = "encryptionKey"; | private static final String AES_ENCRYPTION_KEY_LABEL = "encryptionKey"; | ||||
private static final String GROUP_NOTIF_IDS_KEY = "groupNotifIDs"; | private static final String GROUP_NOTIF_IDS_KEY = "groupNotifIDs"; | ||||
private static final String COLLAPSE_ID_KEY = "collapseKey"; | private static final String COLLAPSE_ID_KEY = "collapseKey"; | ||||
private static final String KEYSERVER_ID_KEY = "keyserverID"; | private static final String KEYSERVER_ID_KEY = "keyserverID"; | ||||
private static final String CHANNEL_ID = "default"; | private static final String CHANNEL_ID = "default"; | ||||
private static final long[] VIBRATION_SPEC = {500, 500}; | private static final long[] VIBRATION_SPEC = {500, 500}; | ||||
// Those and future MMKV-related constants should match | // Those and future MMKV-related constants should match | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | if ("1".equals(badgeOnly)) { | ||||
return; | return; | ||||
} | } | ||||
if (message.getData().get(MESSAGE_INFOS_KEY) != null) { | if (message.getData().get(MESSAGE_INFOS_KEY) != null) { | ||||
handleMessageInfosPersistence(message); | handleMessageInfosPersistence(message); | ||||
} | } | ||||
if (message.getData().get(BLOB_HASH_KEY) != null && | if (message.getData().get(BLOB_HASH_KEY) != null && | ||||
message.getData().get(AES_ENCRYPTION_KEY_LABEL) != null) { | message.getData().get(AES_ENCRYPTION_KEY_LABEL) != null && | ||||
message.getData().get(BLOB_HOLDER_KEY) != null) { | |||||
handleLargeNotification(message); | handleLargeNotification(message); | ||||
} | } | ||||
Intent intent = new Intent(MESSAGE_EVENT); | Intent intent = new Intent(MESSAGE_EVENT); | ||||
intent.putExtra( | intent.putExtra( | ||||
"message", serializeMessageDataForIntentAttachment(message)); | "message", serializeMessageDataForIntentAttachment(message)); | ||||
localBroadcastManager.sendBroadcast(intent); | localBroadcastManager.sendBroadcast(intent); | ||||
▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | if (rawMessageInfosString != null && sqliteFile.exists()) { | ||||
}); | }); | ||||
} else if (rawMessageInfosString != null) { | } else if (rawMessageInfosString != null) { | ||||
Log.w("COMM", "Database not existing yet. Skipping notification"); | Log.w("COMM", "Database not existing yet. Skipping notification"); | ||||
} | } | ||||
} | } | ||||
private void handleLargeNotification(RemoteMessage message) { | private void handleLargeNotification(RemoteMessage message) { | ||||
String blobHash = message.getData().get(BLOB_HASH_KEY); | String blobHash = message.getData().get(BLOB_HASH_KEY); | ||||
String blobHolder = message.getData().get(BLOB_HOLDER_KEY); | |||||
try { | try { | ||||
byte[] largePayload = blobClient.getBlobSync(blobHash); | byte[] largePayload = blobClient.getBlobSync(blobHash); | ||||
message = aesDecryptRemoteMessage(message, largePayload); | message = aesDecryptRemoteMessage(message, largePayload); | ||||
handleMessageInfosPersistence(message); | handleMessageInfosPersistence(message); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
Log.w("COMM", "Failure when handling large notification.", e); | Log.w("COMM", "Failure when handling large notification.", e); | ||||
} | } | ||||
blobClient.scheduleDeferredBlobDeletion( | |||||
blobHash, blobHolder, this.getApplicationContext()); | |||||
} | } | ||||
private void addToThreadGroupAndDisplay( | private void addToThreadGroupAndDisplay( | ||||
String notificationID, | String notificationID, | ||||
NotificationCompat.Builder notificationBuilder, | NotificationCompat.Builder notificationBuilder, | ||||
String threadID) { | String threadID) { | ||||
notificationBuilder.setGroup(threadID).setGroupAlertBehavior( | notificationBuilder.setGroup(threadID).setGroupAlertBehavior( | ||||
▲ Show 20 Lines • Show All 303 Lines • Show Last 20 Lines |