mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +00:00
parent
ee5062a2cc
commit
1efdf04394
4 changed files with 46 additions and 13 deletions
|
@ -5,7 +5,6 @@ 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;
|
||||||
|
|
|
@ -310,6 +310,9 @@ public class Main {
|
||||||
} catch (GroupNotFoundException e) {
|
} catch (GroupNotFoundException e) {
|
||||||
handleGroupNotFoundException(e);
|
handleGroupNotFoundException(e);
|
||||||
return 1;
|
return 1;
|
||||||
|
} catch (NotAGroupMemberException e) {
|
||||||
|
handleNotAGroupMemberException(e);
|
||||||
|
return 1;
|
||||||
} catch (AttachmentInvalidException e) {
|
} catch (AttachmentInvalidException e) {
|
||||||
System.err.println("Failed to add attachment: " + e.getMessage());
|
System.err.println("Failed to add attachment: " + e.getMessage());
|
||||||
System.err.println("Aborting sending.");
|
System.err.println("Aborting sending.");
|
||||||
|
@ -401,6 +404,9 @@ public class Main {
|
||||||
} catch (GroupNotFoundException e) {
|
} catch (GroupNotFoundException e) {
|
||||||
handleGroupNotFoundException(e);
|
handleGroupNotFoundException(e);
|
||||||
return 1;
|
return 1;
|
||||||
|
} catch (NotAGroupMemberException e) {
|
||||||
|
handleNotAGroupMemberException(e);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -433,6 +439,9 @@ public class Main {
|
||||||
} catch (GroupNotFoundException e) {
|
} catch (GroupNotFoundException e) {
|
||||||
handleGroupNotFoundException(e);
|
handleGroupNotFoundException(e);
|
||||||
return 1;
|
return 1;
|
||||||
|
} catch (NotAGroupMemberException e) {
|
||||||
|
handleNotAGroupMemberException(e);
|
||||||
|
return 1;
|
||||||
} catch (EncapsulatedExceptions e) {
|
} catch (EncapsulatedExceptions e) {
|
||||||
handleEncapsulatedExceptions(e);
|
handleEncapsulatedExceptions(e);
|
||||||
return 3;
|
return 3;
|
||||||
|
@ -553,6 +562,13 @@ public class Main {
|
||||||
System.err.println("Aborting sending.");
|
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) {
|
private static void handleDBusExecutionException(DBusExecutionException e) {
|
||||||
System.err.println("Cannot connect to dbus: " + e.getMessage());
|
System.err.println("Cannot connect to dbus: " + e.getMessage());
|
||||||
System.err.println("Aborting.");
|
System.err.println("Aborting.");
|
||||||
|
|
|
@ -515,6 +515,19 @@ class Manager implements Signal {
|
||||||
return Optional.of(createAttachment(file));
|
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
|
@Override
|
||||||
public void sendGroupMessage(String messageText, List<String> attachments,
|
public void sendGroupMessage(String messageText, List<String> attachments,
|
||||||
byte[] groupId)
|
byte[] groupId)
|
||||||
|
@ -531,10 +544,7 @@ class Manager implements Signal {
|
||||||
}
|
}
|
||||||
SignalServiceDataMessage message = messageBuilder.build();
|
SignalServiceDataMessage message = messageBuilder.build();
|
||||||
|
|
||||||
GroupInfo g = groupStore.getGroup(groupId);
|
final GroupInfo g = getGroupForSending(groupId);
|
||||||
if (g == null) {
|
|
||||||
throw new GroupNotFoundException(groupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't send group message to ourself
|
// Don't send group message to ourself
|
||||||
final List<String> membersSend = new ArrayList<>(g.members);
|
final List<String> membersSend = new ArrayList<>(g.members);
|
||||||
|
@ -551,10 +561,7 @@ class Manager implements Signal {
|
||||||
.asGroupMessage(group)
|
.asGroupMessage(group)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
final GroupInfo g = groupStore.getGroup(groupId);
|
final GroupInfo g = getGroupForSending(groupId);
|
||||||
if (g == null) {
|
|
||||||
throw new GroupNotFoundException(groupId);
|
|
||||||
}
|
|
||||||
g.members.remove(this.username);
|
g.members.remove(this.username);
|
||||||
groupStore.updateGroup(g);
|
groupStore.updateGroup(g);
|
||||||
|
|
||||||
|
@ -568,10 +575,7 @@ class Manager implements Signal {
|
||||||
g = new GroupInfo(Util.getSecretBytes(16));
|
g = new GroupInfo(Util.getSecretBytes(16));
|
||||||
g.members.add(username);
|
g.members.add(username);
|
||||||
} else {
|
} else {
|
||||||
g = groupStore.getGroup(groupId);
|
g = getGroupForSending(groupId);
|
||||||
if (g == null) {
|
|
||||||
throw new GroupNotFoundException(groupId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
|
|
14
src/main/java/org/asamk/signal/NotAGroupMemberException.java
Normal file
14
src/main/java/org/asamk/signal/NotAGroupMemberException.java
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
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) + ")");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue