Dbus methods isMember and isAdmin

create isAdmin method in parallel with isMember
extend both to have the ability to add or remove members or admins

update documentation
This commit is contained in:
John Freed 2021-08-19 11:19:08 +02:00
parent 217afd74c4
commit 0691a91dad
3 changed files with 185 additions and 13 deletions

View file

@ -108,14 +108,6 @@ Note that quitting a group will not remove the group from the getGroupIds comman
Exceptions: GroupNotFound, Failure
isMember(groupId<ay>) -> active<b>::
isMember(base64GroupId<s>) -> active<b>::
* 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<as>) -> <>::
* 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<ay>) -> active<b>::
isMember(base64GroupId<s>) -> active<b>::
isMember(groupId<ay>, members<as>, setMemberStatus<b>) -> memberList<as>::
isMember(base64GroupId<s>, members<as>, setMemberStatus<b>) -> memberList<as>::
* 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<ay>) -> admin<b>::
isAdmin(base64GroupId<s>) -> admin<b>::
isAdmin(groupId<ay>, admins<as>, setAdminStatus<b>) -> adminList<as>::
isAdmin(base64GroupId<s>, admins<as>, setAdminStatus<b>) -> adminList<as>::
* 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<ay>) -> members<as>::
getGroupMembers(base64GroupId<s>) -> members<as>::
* members : String array with the phone numbers of all active members of a group

View file

@ -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<String> isMember(final byte[] groupId, List<String>members, boolean setMemberStatus) throws Error.GroupNotFound, Error.Failure;
List<String> isMember(final String base64GroupId, List<String>members, 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<String> isAdmin(final byte[] groupId, List<String>admins, boolean setAdminStatus) throws Error.GroupNotFound, Error.Failure;
List<String> isAdmin(final String base64GroupId, List<String>admins, boolean setAdminStatus) throws Error.GroupNotFound, Error.Failure;
void joinGroup(final String groupLink) throws Error.Failure;

View file

@ -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<String> isMember(final byte[] groupId, List<String>members, 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<String> isMember(final String base64GroupId, List<String> 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<String> isAdmin(final byte[] groupId, List<String>admins, 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<String> isAdmin(final String base64GroupId, List<String> 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);