Correctly use API for sending non group messages

is necessary so the correct sync messages are generated
for linked accounts
This commit is contained in:
AsamK 2016-04-08 23:34:34 +02:00
parent aa8a23aceb
commit 5c117bd863
3 changed files with 28 additions and 12 deletions

View file

@ -5,19 +5,20 @@ import org.asamk.signal.GroupNotFoundException;
import org.freedesktop.dbus.DBusInterface; import org.freedesktop.dbus.DBusInterface;
import org.freedesktop.dbus.DBusSignal; import org.freedesktop.dbus.DBusSignal;
import org.freedesktop.dbus.exceptions.DBusException; import org.freedesktop.dbus.exceptions.DBusException;
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions; import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
import java.io.IOException; import java.io.IOException;
import java.util.List; 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; void sendMessage(String message, List<String> attachments, String recipient) throws EncapsulatedExceptions, AttachmentInvalidException, IOException, UntrustedIdentityException;
void sendMessage(String message, List<String> attachments, List<String> recipients) throws EncapsulatedExceptions, AttachmentInvalidException, IOException; void sendMessage(String message, List<String> attachments, List<String> recipients) throws EncapsulatedExceptions, AttachmentInvalidException, IOException, UntrustedIdentityException;
void sendEndSessionMessage(List<String> recipients) throws IOException, EncapsulatedExceptions; void sendEndSessionMessage(List<String> recipients) throws IOException, EncapsulatedExceptions, UntrustedIdentityException;
void sendGroupMessage(String message, List<String> attachments, byte[] groupId) throws EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, IOException; void sendGroupMessage(String message, List<String> attachments, byte[] groupId) throws EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, IOException, UntrustedIdentityException;
class MessageReceived extends DBusSignal { class MessageReceived extends DBusSignal {
private long timestamp; private long timestamp;

View file

@ -166,6 +166,8 @@ public class Main {
handleAssertionError(e); handleAssertionError(e);
} catch (DBusExecutionException e) { } catch (DBusExecutionException e) {
handleDBusExecutionException(e); handleDBusExecutionException(e);
} catch (UntrustedIdentityException e) {
e.printStackTrace();
} }
} else { } else {
String messageText = ns.getString("message"); String messageText = ns.getString("message");
@ -204,6 +206,8 @@ public class Main {
System.exit(1); System.exit(1);
} catch (DBusExecutionException e) { } catch (DBusExecutionException e) {
handleDBusExecutionException(e); handleDBusExecutionException(e);
} catch (UntrustedIdentityException e) {
e.printStackTrace();
} }
} }
@ -282,6 +286,8 @@ public class Main {
handleAssertionError(e); handleAssertionError(e);
} catch (GroupNotFoundException e) { } catch (GroupNotFoundException e) {
handleGroupNotFoundException(e); handleGroupNotFoundException(e);
} catch (UntrustedIdentityException e) {
e.printStackTrace();
} }
break; break;
@ -314,6 +320,8 @@ public class Main {
handleGroupNotFoundException(e); handleGroupNotFoundException(e);
} catch (EncapsulatedExceptions e) { } catch (EncapsulatedExceptions e) {
handleEncapsulatedExceptions(e); handleEncapsulatedExceptions(e);
} catch (UntrustedIdentityException e) {
e.printStackTrace();
} }
break; break;

View file

@ -300,7 +300,7 @@ class Manager implements Signal {
@Override @Override
public void sendGroupMessage(String messageText, List<String> attachments, public void sendGroupMessage(String messageText, List<String> attachments,
byte[] groupId) byte[] groupId)
throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException { throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, UntrustedIdentityException {
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText); final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText);
if (attachments != null) { if (attachments != null) {
messageBuilder.withAttachments(getSignalServiceAttachments(attachments)); messageBuilder.withAttachments(getSignalServiceAttachments(attachments));
@ -316,7 +316,7 @@ class Manager implements Signal {
sendMessage(message, groupStore.getGroup(groupId).members); sendMessage(message, groupStore.getGroup(groupId).members);
} }
public void sendQuitGroupMessage(byte[] groupId) throws GroupNotFoundException, IOException, EncapsulatedExceptions { public void sendQuitGroupMessage(byte[] groupId) throws GroupNotFoundException, IOException, EncapsulatedExceptions, UntrustedIdentityException {
SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.QUIT) SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.QUIT)
.withId(groupId) .withId(groupId)
.build(); .build();
@ -328,7 +328,7 @@ class Manager implements Signal {
sendMessage(message, groupStore.getGroup(groupId).members); sendMessage(message, groupStore.getGroup(groupId).members);
} }
public byte[] sendUpdateGroupMessage(byte[] groupId, String name, Collection<String> members, String avatarFile) throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException { public byte[] sendUpdateGroupMessage(byte[] groupId, String name, Collection<String> members, String avatarFile) throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, UntrustedIdentityException {
GroupInfo g; GroupInfo g;
if (groupId == null) { if (groupId == null) {
// Create new group // Create new group
@ -381,7 +381,7 @@ class Manager implements Signal {
@Override @Override
public void sendMessage(String message, List<String> attachments, String recipient) public void sendMessage(String message, List<String> attachments, String recipient)
throws EncapsulatedExceptions, AttachmentInvalidException, IOException { throws EncapsulatedExceptions, AttachmentInvalidException, IOException, UntrustedIdentityException {
List<String> recipients = new ArrayList<>(1); List<String> recipients = new ArrayList<>(1);
recipients.add(recipient); recipients.add(recipient);
sendMessage(message, attachments, recipients); sendMessage(message, attachments, recipients);
@ -390,7 +390,7 @@ class Manager implements Signal {
@Override @Override
public void sendMessage(String messageText, List<String> attachments, public void sendMessage(String messageText, List<String> attachments,
List<String> recipients) List<String> recipients)
throws IOException, EncapsulatedExceptions, AttachmentInvalidException { throws IOException, EncapsulatedExceptions, AttachmentInvalidException, UntrustedIdentityException {
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText); final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText);
if (attachments != null) { if (attachments != null) {
messageBuilder.withAttachments(getSignalServiceAttachments(attachments)); messageBuilder.withAttachments(getSignalServiceAttachments(attachments));
@ -401,7 +401,7 @@ class Manager implements Signal {
} }
@Override @Override
public void sendEndSessionMessage(List<String> recipients) throws IOException, EncapsulatedExceptions { public void sendEndSessionMessage(List<String> recipients) throws IOException, EncapsulatedExceptions, UntrustedIdentityException {
SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder() SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder()
.asEndSessionMessage() .asEndSessionMessage()
.build(); .build();
@ -410,7 +410,7 @@ class Manager implements Signal {
} }
private void sendMessage(SignalServiceDataMessage message, Collection<String> recipients) private void sendMessage(SignalServiceDataMessage message, Collection<String> recipients)
throws IOException, EncapsulatedExceptions { throws IOException, EncapsulatedExceptions, UntrustedIdentityException {
SignalServiceMessageSender messageSender = new SignalServiceMessageSender(URL, TRUST_STORE, username, password, SignalServiceMessageSender messageSender = new SignalServiceMessageSender(URL, TRUST_STORE, username, password,
signalProtocolStore, USER_AGENT, Optional.<SignalServiceMessageSender.EventListener>absent()); signalProtocolStore, USER_AGENT, Optional.<SignalServiceMessageSender.EventListener>absent());
@ -426,7 +426,14 @@ class Manager implements Signal {
} }
} }
messageSender.sendMessage(new ArrayList<>(recipientsTS), message); if (message.getGroupInfo().isPresent()) {
messageSender.sendMessage(new ArrayList<>(recipientsTS), message);
} else {
// Send to all individually, so sync messages are sent correctly
for (SignalServiceAddress address : recipientsTS) {
messageSender.sendMessage(address, message);
}
}
if (message.isEndSession()) { if (message.isEndSession()) {
for (SignalServiceAddress recipient : recipientsTS) { for (SignalServiceAddress recipient : recipientsTS) {