diff --git a/man/signal-cli-dbus.5.adoc b/man/signal-cli-dbus.5.adoc index 26f66aba..f967830f 100755 --- a/man/signal-cli-dbus.5.adoc +++ b/man/signal-cli-dbus.5.adoc @@ -108,14 +108,6 @@ Note that quitting a group will not remove the group from the getGroupIds comman Exceptions: GroupNotFound, Failure -isMember(groupId) -> active:: -isMember(base64GroupId) -> active:: -* groupId : Byte array representing the internal group identifier -* base64GroupId : String representing the internal group identifier in Base64 format -* active : Boolean representing whether you are a member of the group - -Exceptions: GroupNotFound - sendEndSessionMessage(recipients) -> <>:: * recipients : String array of phone numbers @@ -266,6 +258,32 @@ base64GroupId : String representing the internal group identifier in Base64 form Exception: Failure if base64GroupId or groupId is malformed; GroupNotFound +isMember(groupId) -> active:: +isMember(base64GroupId) -> active:: +isMember(groupId, members, setMemberStatus) -> memberList:: +isMember(base64GroupId, members, setMemberStatus) -> memberList:: +* groupId : Byte array representing the internal group identifier +* base64GroupId : String representing the internal group identifier in Base64 format +* members : Phone numbers of users to add to or remove from group +* setMemberStatus : true for add to group members; false for remove from group members +* active : Boolean representing whether you are a member of the group +* memberList : List of members after command execution + +Exceptions: GroupNotFound, Failure + +isAdmin(groupId) -> admin:: +isAdmin(base64GroupId) -> admin:: +isAdmin(groupId, admins, setAdminStatus) -> adminList:: +isAdmin(base64GroupId, admins, setAdminStatus) -> adminList:: +* groupId : Byte array representing the internal group identifier +* base64GroupId : String representing the internal group identifier in Base64 format +* admins : Phone numbers of users to grant or deny admin status +* setAdminStatus : true for add to group admins; false for remove from group admins +* admin : Boolean representing whether you are an admin of the group +* adminList : List of admins after command execution + +Exceptions: GroupNotFound, Failure + getGroupMembers(groupId) -> members:: getGroupMembers(base64GroupId) -> members:: * members : String array with the phone numbers of all active members of a group diff --git a/src/main/java/org/asamk/Signal.java b/src/main/java/org/asamk/Signal.java index b025066e..8a35f533 100644 --- a/src/main/java/org/asamk/Signal.java +++ b/src/main/java/org/asamk/Signal.java @@ -233,8 +233,15 @@ public interface Signal extends DBusInterface { boolean isGroupBlocked(final byte[] groupId) throws Error.GroupNotFound, Error.Failure; boolean isGroupBlocked(final String base64GroupId) throws Error.GroupNotFound, Error.Failure; - boolean isMember(final byte[] groupId) throws Error.GroupNotFound, Error.Failure; - boolean isMember(final String base64GroupId) throws Error.GroupNotFound, Error.Failure; + boolean isMember(final byte[] groupId) throws Error.GroupNotFound, Error.Failure; + boolean isMember(final String base64GroupId) throws Error.GroupNotFound, Error.Failure; + List isMember(final byte[] groupId, Listmembers, boolean setMemberStatus) throws Error.GroupNotFound, Error.Failure; + List isMember(final String base64GroupId, Listmembers, boolean setMemberStatus) throws Error.GroupNotFound, Error.Failure; + + boolean isAdmin(final byte[] groupId) throws Error.GroupNotFound, Error.Failure; + boolean isAdmin(final String base64GroupId) throws Error.GroupNotFound, Error.Failure; + List isAdmin(final byte[] groupId, Listadmins, boolean setAdminStatus) throws Error.GroupNotFound, Error.Failure; + List isAdmin(final String base64GroupId, Listadmins, boolean setAdminStatus) throws Error.GroupNotFound, Error.Failure; void joinGroup(final String groupLink) throws Error.Failure; diff --git a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java index 1e68159e..1400af73 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java @@ -1083,8 +1083,6 @@ public class DbusSignalImpl implements Signal { } } - - @Override public boolean isRegistered(String number) { if (number.isEmpty()) { @@ -1260,7 +1258,6 @@ public class DbusSignalImpl implements Signal { DbusSignalControlImpl.verifyWithPin(number, verificationCode, pin); } - // Create a unique list of Numbers from Identities and Contacts to really get // all numbers the system knows @Override @@ -1447,6 +1444,156 @@ public class DbusSignalImpl implements Signal { } } + @Override + public List isMember(final byte[] groupId, Listmembers, boolean setMemberStatus) { + GroupInfo group = null; + try { + group = m.getGroup(GroupId.unknownVersion(groupId)); + if (group == null) { + throw new Error.GroupNotFound("Error finding group"); + } + if (setMemberStatus) { + var results = m.updateGroup(group.getGroupId(), + null, + null, + members, + null, + null, + null, + false, + null, + null, + null, + null, + null); + } else { + var results = m.updateGroup(group.getGroupId(), + null, + null, + null, + members, + null, + null, + false, + null, + null, + null, + null, + null); + } + return getGroupMembers(groupId); + } catch (NotAGroupMemberException | InvalidNumberException | AssertionError | IOException | AttachmentInvalidException e) { + throw new Error.Failure(e.getMessage()); + } catch (GroupNotFoundException e) { + throw new Error.GroupNotFound("Group not found."); + } + } + + @Override + public List isMember(final String base64GroupId, List members, boolean setMemberStatus) { + GroupInfo group = null; + byte[] groupId = null; + try { + groupId = GroupId.fromBase64(base64GroupId).serialize(); + return isMember(groupId, members, setMemberStatus); + } catch (GroupIdFormatException e) { + throw new Error.Failure("Incorrect format: " + e.getMessage()); + } + } + + @Override + public boolean isAdmin(final byte[] groupId) { + GroupInfo group = null; + try { + group = m.getGroup(GroupId.unknownVersion(groupId)); + } catch (AssertionError e) { + throw new Error.Failure(e.getMessage()); + } + if (group == null) { + throw new Error.GroupNotFound("Error finding group"); + } else { + return group.getAdminMembers().contains(m.getSelfRecipientId()); + } + } + + @Override + public boolean isAdmin(final String base64GroupId) { + GroupInfo group = null; + byte[] groupId = null; + try { + groupId = GroupId.fromBase64(base64GroupId).serialize(); + } catch (GroupIdFormatException e) { + throw new Error.Failure("Incorrect format: " + e.getMessage()); + } + try { + group = m.getGroup(GroupId.unknownVersion(groupId)); + } catch (AssertionError e) { + throw new Error.Failure(e.getMessage()); + } + if (group == null) { + throw new Error.GroupNotFound("Error finding group"); + } else { + return group.getAdminMembers().contains(m.getSelfRecipientId()); + } + } + + @Override + public List isAdmin(final byte[] groupId, Listadmins, boolean setAdminStatus) { + GroupInfo group = null; + try { + group = m.getGroup(GroupId.unknownVersion(groupId)); + if (group == null) { + throw new Error.GroupNotFound("Error finding group"); + } + if (setAdminStatus) { + var results = m.updateGroup(group.getGroupId(), + null, + null, + null, + null, + admins, + null, + false, + null, + null, + null, + null, + null); + } else { + var results = m.updateGroup(group.getGroupId(), + null, + null, + null, + null, + null, + admins, + false, + null, + null, + null, + null, + null); + } + return getGroupAdminMembers(groupId); + } catch (NotAGroupMemberException | InvalidNumberException | AssertionError | IOException | AttachmentInvalidException e) { + throw new Error.Failure(e.getMessage()); + } catch (GroupNotFoundException e) { + throw new Error.GroupNotFound("Group not found."); + } + } + + @Override + public List isAdmin(final String base64GroupId, List admins, boolean setAdminStatus) { + GroupInfo group = null; + byte[] groupId = null; + try { + groupId = GroupId.fromBase64(base64GroupId).serialize(); + return isAdmin(groupId, admins, setAdminStatus); + } catch (GroupIdFormatException e) { + throw new Error.Failure("Incorrect format: " + e.getMessage()); + } + } + @Override public void uploadStickerPack(String stickerPackPath) { File path = new File(stickerPackPath);