X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/5ee375c74d13fa18ed353221c403772511abcbb1..adbc08b2f76c80c8613ade367159af9f40f03099:/src/main/java/org/asamk/signal/Manager.java?ds=sidebyside diff --git a/src/main/java/org/asamk/signal/Manager.java b/src/main/java/org/asamk/signal/Manager.java index 315eac13..6ed8b045 100644 --- a/src/main/java/org/asamk/signal/Manager.java +++ b/src/main/java/org/asamk/signal/Manager.java @@ -864,7 +864,49 @@ class Manager implements Signal { } } + public void retryFailedReceivedMessages(ReceiveMessageHandler handler) { + final File cachePath = new File(getMessageCachePath()); + if (!cachePath.exists()) { + return; + } + for (final File dir : cachePath.listFiles()) { + if (!dir.isDirectory()) { + continue; + } + + String sender = dir.getName(); + 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); + } + save(); + handler.handleMessage(envelope, content, null); + fileEntry.delete(); + } + } + } + public void receiveMessages(int timeoutSeconds, boolean returnOnTimeout, ReceiveMessageHandler handler) throws IOException { + retryFailedReceivedMessages(handler); final SignalServiceMessageReceiver messageReceiver = new SignalServiceMessageReceiver(URL, TRUST_STORE, username, password, deviceId, signalingKey, USER_AGENT); SignalServiceMessagePipe messagePipe = null; @@ -975,6 +1017,9 @@ class Manager implements Signal { } catch (Exception e) { e.printStackTrace(); } + if (syncMessage.getBlockedList().isPresent()) { + // TODO store list of blocked numbers + } } if (syncMessage.getContacts().isPresent()) { try { @@ -986,6 +1031,9 @@ class Manager implements Signal { if (c.getName().isPresent()) { contact.name = c.getName().get(); } + if (c.getColor().isPresent()) { + contact.color = c.getColor().get(); + } contactStore.updateContact(contact); if (c.getAvatar().isPresent()) { @@ -1000,6 +1048,34 @@ class Manager implements Signal { } } + private SignalServiceEnvelope loadEnvelope(File file) throws IOException { + try (FileInputStream f = new FileInputStream(file)) { + DataInputStream in = new DataInputStream(f); + int version = in.readInt(); + if (version != 1) { + return null; + } + int type = in.readInt(); + String source = in.readUTF(); + int sourceDevice = in.readInt(); + String relay = in.readUTF(); + long timestamp = in.readLong(); + byte[] content = null; + int contentLen = in.readInt(); + if (contentLen > 0) { + content = new byte[contentLen]; + in.readFully(content); + } + byte[] legacyMessage = null; + int legacyMessageLen = in.readInt(); + if (legacyMessageLen > 0) { + legacyMessage = new byte[legacyMessageLen]; + in.readFully(legacyMessage); + } + return new SignalServiceEnvelope(type, source, sourceDevice, relay, timestamp, legacyMessage, content); + } + } + private void storeEnvelope(SignalServiceEnvelope envelope, File file) throws IOException { try (FileOutputStream f = new FileOutputStream(file)) { DataOutputStream out = new DataOutputStream(f); @@ -1194,7 +1270,7 @@ class Manager implements Signal { try { for (ContactInfo record : contactStore.getContacts()) { out.write(new DeviceContact(record.number, Optional.fromNullable(record.name), - createContactAvatarAttachment(record.number))); + createContactAvatarAttachment(record.number), Optional.fromNullable(record.color))); } } finally { out.close();