import org.freedesktop.dbus.DBusInterface;
import org.freedesktop.dbus.DBusSignal;
import org.freedesktop.dbus.exceptions.DBusException;
-import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
import java.io.IOException;
} catch (GroupNotFoundException e) {
handleGroupNotFoundException(e);
return 1;
+ } catch (NotAGroupMemberException e) {
+ handleNotAGroupMemberException(e);
+ return 1;
} catch (AttachmentInvalidException e) {
System.err.println("Failed to add attachment: " + e.getMessage());
System.err.println("Aborting sending.");
} catch (GroupNotFoundException e) {
handleGroupNotFoundException(e);
return 1;
+ } catch (NotAGroupMemberException e) {
+ handleNotAGroupMemberException(e);
+ return 1;
}
break;
} catch (GroupNotFoundException e) {
handleGroupNotFoundException(e);
return 1;
+ } catch (NotAGroupMemberException e) {
+ handleNotAGroupMemberException(e);
+ return 1;
} catch (EncapsulatedExceptions e) {
handleEncapsulatedExceptions(e);
return 3;
System.err.println("Aborting sending.");
}
+ private static void handleNotAGroupMemberException(NotAGroupMemberException e) {
+ System.err.println("Failed to send to group: " + e.getMessage());
+ System.err.println("Update the group on another device to readd the user to this group.");
+ System.err.println("Aborting sending.");
+ }
+
+
private static void handleDBusExecutionException(DBusExecutionException e) {
System.err.println("Cannot connect to dbus: " + e.getMessage());
System.err.println("Aborting.");
return Optional.of(createAttachment(file));
}
+ private GroupInfo getGroupForSending(byte[] groupId) throws GroupNotFoundException, NotAGroupMemberException {
+ GroupInfo g = groupStore.getGroup(groupId);
+ if (g == null) {
+ throw new GroupNotFoundException(groupId);
+ }
+ for (String member : g.members) {
+ if (member.equals(this.username)) {
+ return g;
+ }
+ }
+ throw new NotAGroupMemberException(groupId, g.name);
+ }
+
@Override
public void sendGroupMessage(String messageText, List<String> attachments,
byte[] groupId)
}
SignalServiceDataMessage message = messageBuilder.build();
- GroupInfo g = groupStore.getGroup(groupId);
- if (g == null) {
- throw new GroupNotFoundException(groupId);
- }
+ final GroupInfo g = getGroupForSending(groupId);
// Don't send group message to ourself
final List<String> membersSend = new ArrayList<>(g.members);
.asGroupMessage(group)
.build();
- final GroupInfo g = groupStore.getGroup(groupId);
- if (g == null) {
- throw new GroupNotFoundException(groupId);
- }
+ final GroupInfo g = getGroupForSending(groupId);
g.members.remove(this.username);
groupStore.updateGroup(g);
g = new GroupInfo(Util.getSecretBytes(16));
g.members.add(username);
} else {
- g = groupStore.getGroup(groupId);
- if (g == null) {
- throw new GroupNotFoundException(groupId);
- }
+ g = getGroupForSending(groupId);
}
if (name != null) {
--- /dev/null
+package org.asamk.signal;
+
+import org.freedesktop.dbus.exceptions.DBusExecutionException;
+
+public class NotAGroupMemberException extends DBusExecutionException {
+
+ public NotAGroupMemberException(String message) {
+ super(message);
+ }
+
+ public NotAGroupMemberException(byte[] groupId, String groupName) {
+ super("User is not a member in group: " + groupName + " (" + Base64.encodeBytes(groupId) + ")");
+ }
+}