+ if (message.getProfileKey().isPresent() && message.getProfileKey().get().length == 32) {
+ ContactInfo contact = contactStore.getContact(source);
+ if (contact == null) {
+ contact = new ContactInfo();
+ contact.number = source;
+ }
+ contact.profileKey = Base64.encodeBytes(message.getProfileKey().get());
+ }
+ }
+
+ public void retryFailedReceivedMessages(ReceiveMessageHandler handler, boolean ignoreAttachments) {
+ final File cachePath = new File(getMessageCachePath());
+ if (!cachePath.exists()) {
+ return;
+ }
+ for (final File dir : cachePath.listFiles()) {
+ if (!dir.isDirectory()) {
+ continue;
+ }
+
+ for (final File fileEntry : dir.listFiles()) {
+ if (!fileEntry.isFile()) {
+ continue;
+ }
+ SignalServiceEnvelope envelope;
+ try {
+ envelope = loadEnvelope(fileEntry);
+ if (envelope == null) {
+ continue;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ continue;
+ }
+ SignalServiceContent content = null;
+ if (!envelope.isReceipt()) {
+ try {
+ content = decryptMessage(envelope);
+ } catch (Exception e) {
+ continue;
+ }
+ handleMessage(envelope, content, ignoreAttachments);
+ }
+ save();
+ handler.handleMessage(envelope, content, null);
+ try {
+ Files.delete(fileEntry.toPath());
+ } catch (IOException e) {
+ System.err.println("Failed to delete cached message file “" + fileEntry + "”: " + e.getMessage());
+ }
+ }
+ // Try to delete directory if empty
+ dir.delete();
+ }