Return message timestamp after sucessfully sending a message

Fixes #104
This commit is contained in:
AsamK 2020-04-03 14:02:18 +02:00
parent 320e126eeb
commit f51f0cbbcf
3 changed files with 17 additions and 12 deletions

View file

@ -13,13 +13,13 @@ import java.util.List;
public interface Signal extends DBusInterface { public interface Signal extends DBusInterface {
void sendMessage(String message, List<String> attachments, String recipient) throws EncapsulatedExceptions, AttachmentInvalidException, IOException, InvalidNumberException; long sendMessage(String message, List<String> attachments, String recipient) throws EncapsulatedExceptions, AttachmentInvalidException, IOException, InvalidNumberException;
void sendMessage(String message, List<String> attachments, List<String> recipients) throws EncapsulatedExceptions, AttachmentInvalidException, IOException, InvalidNumberException; long sendMessage(String message, List<String> attachments, List<String> recipients) throws EncapsulatedExceptions, AttachmentInvalidException, IOException, InvalidNumberException;
void sendEndSessionMessage(List<String> recipients) throws IOException, EncapsulatedExceptions, InvalidNumberException; void sendEndSessionMessage(List<String> recipients) throws IOException, EncapsulatedExceptions, InvalidNumberException;
void sendGroupMessage(String message, List<String> attachments, byte[] groupId) throws EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, IOException; long sendGroupMessage(String message, List<String> attachments, byte[] groupId) throws EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, IOException;
String getContactName(String number) throws InvalidNumberException; String getContactName(String number) throws InvalidNumberException;

View file

@ -99,12 +99,14 @@ public class SendCommand implements DbusCommand {
if (attachments == null) { if (attachments == null) {
attachments = new ArrayList<>(); attachments = new ArrayList<>();
} }
long timestamp;
if (ns.getString("group") != null) { if (ns.getString("group") != null) {
byte[] groupId = Util.decodeGroupId(ns.getString("group")); byte[] groupId = Util.decodeGroupId(ns.getString("group"));
signal.sendGroupMessage(messageText, attachments, groupId); timestamp = signal.sendGroupMessage(messageText, attachments, groupId);
} else { } else {
signal.sendMessage(messageText, attachments, ns.getList("recipient")); timestamp = signal.sendMessage(messageText, attachments, ns.getList("recipient"));
} }
System.out.println(timestamp);
return 0; return 0;
} catch (IOException e) { } catch (IOException e) {
handleIOException(e); handleIOException(e);

View file

@ -525,7 +525,7 @@ public class Manager implements Signal {
} }
@Override @Override
public void sendGroupMessage(String messageText, List<String> attachments, public long sendGroupMessage(String messageText, List<String> attachments,
byte[] groupId) byte[] groupId)
throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException { throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException {
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText); final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText);
@ -543,7 +543,7 @@ public class Manager implements Signal {
messageBuilder.withExpiration(g.messageExpirationTime); messageBuilder.withExpiration(g.messageExpirationTime);
sendMessageLegacy(messageBuilder, g.getMembersWithout(account.getSelfAddress())); return sendMessageLegacy(messageBuilder, g.getMembersWithout(account.getSelfAddress()));
} }
public void sendGroupMessageReaction(String emoji, boolean remove, String targetAuthor, public void sendGroupMessageReaction(String emoji, boolean remove, String targetAuthor,
@ -688,15 +688,15 @@ public class Manager implements Signal {
} }
@Override @Override
public void sendMessage(String message, List<String> attachments, String recipient) public long sendMessage(String message, List<String> attachments, String recipient)
throws EncapsulatedExceptions, AttachmentInvalidException, IOException, InvalidNumberException { throws EncapsulatedExceptions, AttachmentInvalidException, IOException, InvalidNumberException {
List<String> recipients = new ArrayList<>(1); List<String> recipients = new ArrayList<>(1);
recipients.add(recipient); recipients.add(recipient);
sendMessage(message, attachments, recipients); return sendMessage(message, attachments, recipients);
} }
@Override @Override
public void sendMessage(String messageText, List<String> attachments, public long sendMessage(String messageText, List<String> attachments,
List<String> recipients) List<String> recipients)
throws IOException, EncapsulatedExceptions, AttachmentInvalidException, InvalidNumberException { throws IOException, EncapsulatedExceptions, AttachmentInvalidException, InvalidNumberException {
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText); final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText);
@ -716,7 +716,7 @@ public class Manager implements Signal {
messageBuilder.withAttachments(attachmentPointers); messageBuilder.withAttachments(attachmentPointers);
} }
sendMessageLegacy(messageBuilder, getSignalServiceAddresses(recipients)); return sendMessageLegacy(messageBuilder, getSignalServiceAddresses(recipients));
} }
public void sendMessageReaction(String emoji, boolean remove, String targetAuthor, public void sendMessageReaction(String emoji, boolean remove, String targetAuthor,
@ -1134,8 +1134,10 @@ public class Manager implements Signal {
/** /**
* This method throws an EncapsulatedExceptions exception instead of returning a list of SendMessageResult. * This method throws an EncapsulatedExceptions exception instead of returning a list of SendMessageResult.
*/ */
private void sendMessageLegacy(SignalServiceDataMessage.Builder messageBuilder, Collection<SignalServiceAddress> recipients) private long sendMessageLegacy(SignalServiceDataMessage.Builder messageBuilder, Collection<SignalServiceAddress> recipients)
throws EncapsulatedExceptions, IOException { throws EncapsulatedExceptions, IOException {
final long timestamp = System.currentTimeMillis();
messageBuilder.withTimestamp(timestamp);
List<SendMessageResult> results = sendMessage(messageBuilder, recipients); List<SendMessageResult> results = sendMessage(messageBuilder, recipients);
List<UntrustedIdentityException> untrustedIdentities = new LinkedList<>(); List<UntrustedIdentityException> untrustedIdentities = new LinkedList<>();
@ -1154,6 +1156,7 @@ public class Manager implements Signal {
if (!untrustedIdentities.isEmpty() || !unregisteredUsers.isEmpty() || !networkExceptions.isEmpty()) { if (!untrustedIdentities.isEmpty() || !unregisteredUsers.isEmpty() || !networkExceptions.isEmpty()) {
throw new EncapsulatedExceptions(untrustedIdentities, unregisteredUsers, networkExceptions); throw new EncapsulatedExceptions(untrustedIdentities, unregisteredUsers, networkExceptions);
} }
return timestamp;
} }
private Collection<SignalServiceAddress> getSignalServiceAddresses(Collection<String> numbers) throws InvalidNumberException { private Collection<SignalServiceAddress> getSignalServiceAddresses(Collection<String> numbers) throws InvalidNumberException {