DBus methods

implement expanded updateGroup

allow group commands to use Base64 strings as group identifiers
* setGroupBlocked
* getGroupName
* getGroupMembers
* sendGroupMessage
* sendGroupMessageReaction
* updateGroup

update AvatarStore to make some methods public or static

reuse UpdateGroupCommand code

update DBus documentation
This commit is contained in:
John Freed 2021-08-15 09:41:29 +02:00
parent 908deb43c5
commit 76406367ea
5 changed files with 466 additions and 59 deletions

View file

@ -14,7 +14,7 @@ import java.nio.file.Files;
public class AvatarStore {
private final File avatarsPath;
private static File avatarsPath = null;
public AvatarStore(final File avatarsPath) {
this.avatarsPath = avatarsPath;
@ -49,7 +49,7 @@ public class AvatarStore {
deleteAvatar(getProfileAvatarFile(address));
}
public void deleteGroupAvatar(GroupId groupId) throws IOException {
public static void deleteGroupAvatar(GroupId groupId) throws IOException {
deleteAvatar(getGroupAvatarFile(groupId));
}
@ -67,13 +67,13 @@ public class AvatarStore {
}
}
private void deleteAvatar(final File avatarFile) throws IOException {
private static void deleteAvatar(final File avatarFile) throws IOException {
if (avatarFile.exists()) {
Files.delete(avatarFile.toPath());
}
}
private File getGroupAvatarFile(GroupId groupId) {
private static File getGroupAvatarFile(GroupId groupId) {
return new File(avatarsPath, "group-" + groupId.toBase64().replace("/", "_"));
}

View file

@ -29,25 +29,37 @@ method(arg1<type>, arg2<type>, ...) -> return<type>
Where <type> is according to DBus specification:
* <a> : Array of ...
* <s> : String
* <ay> : Byte Array
* <aay> : Array of Byte Arrays
* <as> : String Array
* <y> : Byte
* <b> : Boolean (0|1)
* <x> : Signed 64 bit integer
* <x> : Signed 64-bit integer (long)
* <i> : Signed 32-bit integer (int)
* <> : no return value
Exceptions are the names of the Java Exceptions returned in the body field. They typically contain an additional message with details. All Exceptions begin with "org.asamk.Signal.Error." which is omitted here for better readability.
Phone numbers always have the format +<countrycode><regional number>
== Methods
== Methods for org.asamk.Signal
updateGroup(groupId<ay>, newName<s>, members<as>, avatar<s>) -> groupId<ay>::
* groupId : Byte array representing the internal group identifier
* newName : New name of group (empty if unchanged)
* members : String array of new members to be invited to group
* avatar : Filename of avatar picture to be set for group (empty if none)
updateGroup(groupId<ay>, name<s>, addMembers<as>, avatar<s>) -> groupId<ay>::
updateGroup(base64GroupId<s>, name<s>, addMembers<as>, avatar<s>) -> base64GroupId<s>::
updateGroup(base64GroupId<s>, name<s>, description<s>, addMembers<s>, removeMembers<s>, addAdmins<s>, removeAdmins<s>, resetGroupLink<b>, groupLinkState<s>, addMemberPermission<s>, editDetailsPermission<s>, avatar<s> expiration<i>) -> base64GroupId<s>::
* groupId : Byte array representing the internal group identifier
* base64GroupId : String representing the internal group identifier in Base64 format
* name : Name of group (empty if unchanged)
* description : Description (empty if unchanged)
* addMembers : String array of new members to be invited to group (empty if unchanged)
* removeMembers : String array of members to be removed from group (empty if unchanged)
* addAdmins : String array of members granted admin privileges (empty if unchanged)
* removeAdmins : String array of members denied admin privileges (empty if unchanged)
* resetGroupLink : Boolean (true = change the group link, false or empty = don't change)
* groupLinkState : String ("enabled", "enabled-with-approval", "disabled") (empty if unchanged)
* addMemberPermission : String of who may add members ("every-member", "only-admins") (empty if unchanged)
* editDetailsPermission : String of who may edit group details ("every-member", "only-admins") (empty if unchanged)
* avatar : Filename of avatar picture to be set for group (send the name of an empty file to delete avatar; leave field empty if avatar is unchanged)
* expiration : Expiration time for messages sent to this number (in seconds). Set to 0 to disable. (empty if unchanged)
Exceptions: AttachmentInvalid, Failure, InvalidNumber, GroupNotFound
@ -69,8 +81,10 @@ Messages from blocked numbers will no longer be forwarded via DBus.
Exceptions: InvalidNumber
setGroupBlocked(groupId<ay>, block<b>) -> <>::
* groupId : Byte array representing the internal group identifier
* block : 0=remove block , 1=blocked
setGroupBlocked(base64GroupId<s>, block<b>) -> <>::
* groupId : Byte array representing the internal group identifier
* base64GroupId : String representing the internal group identifier in Base64 format
* block : 0=remove block , 1=blocked
Messages from blocked groups will no longer be forwarded via DBus.
@ -82,33 +96,40 @@ joinGroup(inviteURI<s>) -> <>::
Exceptions: Failure
quitGroup(groupId<ay>) -> <>::
* groupId : Byte array representing the internal group identifier
quitGroup(base64GroupId<s>) -> <>::
* groupId : Byte array representing the internal group identifier
* base64GroupId : String representing the internal group identifier in Base64 format
Note that quitting a group will not remove the group from the getGroupIds command, but set it inactive which can be tested with isMember()
Exceptions: GroupNotFound, Failure
isMember(groupId<ay>) -> active<b>::
* groupId : Byte array representing the internal group identifier
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
Note that this method does not raise an Exception for a non-existing/unknown group but will simply return 0 (false)
sendEndSessionMessage(recipients<as>) -> <>::
* recipients : Array of phone numbers
* recipients : String array of phone numbers
Exceptions: Failure, InvalidNumber, UntrustedIdentity
sendGroupMessage(message<s>, attachments<as>, groupId<ay>) -> timestamp<x>::
* message : Text to send (can be UTF8)
* attachments : String array of filenames to send as attachments (passed as filename, so need to be readable by the user signal-cli is running under)
* groupId : Byte array representing the internal group identifier
* timestamp : Can be used to identify the corresponding signal reply
sendGroupMessage(message<s>, attachments<as>, base64GroupId<s>) -> timestamp<x>::
* message : Text to send (can be UTF8)
* attachments : String array of filenames or URLs to send as attachments
* groupId : Byte array representing the internal group identifier
* base64GroupId : String representing the internal group identifier in Base64 format
* timestamp : Can be used to identify the corresponding signal reply
Exceptions: GroupNotFound, Failure, AttachmentInvalid
sendNoteToSelfMessage(message<s>, attachments<as>) -> timestamp<x>::
* message : Text to send (can be UTF8)
* attachments : String array of filenames to send as attachments (passed as filename, so need to be readable by the user signal-cli is running under)
* attachments : String array of filenames or URLs to send as attachments
* timestamp : Can be used to identify the corresponding signal reply
Exceptions: Failure, AttachmentInvalid
@ -116,9 +137,9 @@ Exceptions: Failure, AttachmentInvalid
sendMessage(message<s>, attachments<as>, recipient<s>) -> timestamp<x>::
sendMessage(message<s>, attachments<as>, recipients<as>) -> timestamp<x>::
* message : Text to send (can be UTF8)
* attachments : String array of filenames to send as attachments (passed as filename, so need to be readable by the user signal-cli is running under)
* recipient : Phone number of a single recipient
* recipients : Array of phone numbers
* attachments : String array of filenames or URLs to send as attachments
* recipient : Phone number of a single recipient represented as string
* recipients : String array of phone numbers
* timestamp : Can be used to identify the corresponding signal reply
Depending on the type of the recipient field this sends a message to one or multiple recipients.
@ -126,11 +147,13 @@ Depending on the type of the recipient field this sends a message to one or mult
Exceptions: AttachmentInvalid, Failure, InvalidNumber, UntrustedIdentity
sendGroupMessageReaction(emoji<s>, remove<b>, targetAuthor<s>, targetSentTimestamp<x>, groupId<ay>) -> timestamp<x>::
sendGroupMessageReaction(emoji<s>, remove<b>, targetAuthor<s>, targetSentTimestamp<x>, base64GroupId<s>) -> timestamp<x>::
* emoji : Unicode grapheme cluster of the emoji
* remove : Boolean, whether a previously sent reaction (emoji) should be removed
* targetAuthor : String with the phone number of the author of the message to which to react
* targetSentTimestamp : Long representing timestamp of the message to which to react
* groupId : Byte array with base64 encoded group identifier
* base64GroupId : String representing the internal group identifier in Base64 format
* timestamp : Long, can be used to identify the corresponding signal reply
Exceptions: Failure, InvalidNumber, GroupNotFound
@ -150,8 +173,10 @@ Depending on the type of the recipient(s) field this sends a reaction to one or
Exceptions: Failure, InvalidNumber
sendGroupRemoteDeleteMessage(targetSentTimestamp<x>, groupId<ay>) -> timestamp<x>::
sendGroupRemoteDeleteMessage(targetSentTimestamp<x>, base64GroupId<s>) -> timestamp<x>::
* targetSentTimestamp : Long representing timestamp of the message to delete
* groupId : Byte array with base64 encoded group identifier
* groupId : Byte array representing the internal group identifier
* base64GroupId : String representing the internal group identifier in Base64 format
* timestamp : Long, can be used to identify the corresponding signal reply
Exceptions: Failure, GroupNotFound
@ -175,20 +200,36 @@ setContactName(number<s>,name<>) -> <>::
* number : Phone number
* name : Name to be set in contacts (in local storage with signal-cli)
setExpirationTimer(number<s>,expiration<i>) -> <>::
* number : Phone number
* expiration : Expiration time for messages sent to this number (in seconds). Set to 0 to disable.
getGroupIds() -> groupList<aay>::
groupList : Array of Byte arrays representing the internal group identifiers
getGroupIds(dummy<s>) -> groupList<as>::
dummy : any string (ignored by method)
groupList : Array of Byte arrays representing the internal group identifiers
base64GroupList : Array of strings representing the internal group identifiers in Base64 format
All groups known are returned, regardless of their active or blocked status. To query that use isMember() and isGroupBlocked()
getBase64GroupIds() -> groupList<as>::
groupList : Array of strings representing the internal group identifiers in Base64 format
All groups known are returned, regardless of their active or blocked status. To query that use isMember() and isGroupBlocked()
getGroupName(groupId<ay>) -> groupName<s>::
groupName : The display name of the group
groupId : Byte array representing the internal group identifier
getGroupName(base64GroupId<s>) -> groupName<s>::
groupName : The display name of the group
groupId : Byte array representing the internal group identifier
base64GroupId : String representing the internal group identifier in Base64 format
Exceptions: None, if the group name is not found an empty string is returned
getGroupMembers(groupId<ay>) -> members<as>::
members : String array with the phone numbers of all active members of a group
groupId : Byte array representing the internal group identifier
getGroupMembers(base64GroupId<s>) -> members<as>::
members : String array with the phone numbers of all active members of a group
groupId : Byte array representing the internal group identifier
base64GroupId : String representing the internal group identifier in Base64 format
Exceptions: None, if the group name is not found an empty array is returned
@ -198,7 +239,7 @@ numbers : String array of all known numbers
This is a concatenated list of all defined contacts as well of profiles known (e.g. peer group members or sender of received messages)
getContactNumber(name<s>) -> numbers<as>::
* numbers : Array of phone number
* numbers : Array of phone numbers
* name : Contact or profile name ("firstname lastname")
Searches contacts and known profiles for a given name and returns the list of all known numbers. May result in e.g. two entries if a contact and profile name is set.
@ -210,27 +251,70 @@ isContactBlocked(number<s>) -> state<b>::
Exceptions: None, for unknown numbers 0 (false) is returned
isGroupBlocked(groupId<ay>) -> state<b>::
* groupId : Byte array representing the internal group identifier
* state : 1=blocked, 0=not blocked
isGroupBlocked(base64GroupId<s>) -> state<b>::
* groupId : Byte array representing the internal group identifier
* base64GroupId : String representing the internal group identifier in Base64 format
* state : 1=blocked, 0=not blocked
Exceptions: None, for unknown groups 0 (false) is returned
version() -> version<s>::
* version : Version string of signal-cli
isRegistred -> result<b>::
* result : Currently always returns 1=true
isRegistered(number<s>) -> result<b>::
isRegistered(numbers<as>) -> results<ab>::
* number : Phone number
* numbers : String array of phone numbers
* result : 1=number is registered, 0=number is not registered
* results : Boolean array of results
listDevices() -> devices<as>::
* devices : String array of linked devices
listIdentity(number<s>) -> results<a(ssss)>::
* number : Phone number
* results : Array of elements, each consisting of four strings: trust_level, date_added, fingerprint, safety_number
** trust_level : String representation of trust level
** date_added : String representation of date added
** fingerprint : String representation of hexidecimal fingerprint
** safety_number : String representation of safety number (10 or 11 space-separated six-digit numbers)
getObjectPath() -> objectPath<s>::
* objectPath : The DBus object path associated with this connection
updateAccount() -> <>
This command reverses an `unregister` command.
== Methods for org.asamk.SignalControl
getObjectPath() -> objectPath<s>::
* objectPath : The DBus object path associated with this connection
version() -> version<s>::
* version : Version string of signal-cli
link
register
registerWithCaptcha
verify
verifyWithPin
== Signals
SyncMessageReceived (timestamp<x>, sender<s>, destination<s>, groupId<ay>,message<s>, attachments<as>)::
SyncMessageReceived (timestamp<x>, sender<s>, destination<s>, groupId<ay>, message<s>, attachments<as>)::
The sync message is received when the user sends a message from a linked device.
ReceiptReceived (timestamp<x>, sender<s>)::
* timestamp : Integer value that can be used to associate this e.g. with a sendMessage()
* sender : Phone number of the sender
This signal is sent by each recipient (e.g. each group member) after the message was successfully delivered to the device
* timestamp : Integer value that is used by the system to send a ReceiptReceived reply
* sender : Phone number of the sender
* destination : UUID (legacy identifier) of the destination
* groupId : Byte array representing the internal group identifier (empty when private message)
* message : Message text
* attachments : String array of filenames for the attachments. These files are located in the signal-cli storage and the current user needs to have read access there
MessageReceived(timestamp<x>, sender<s>, groupId<ay>, message<s>, attachments<as>)::
* timestamp : Integer value that is used by the system to send a ReceiptReceived reply
@ -241,6 +325,59 @@ MessageReceived(timestamp<x>, sender<s>, groupId<ay>, message<s>, attachments<as
This signal is received whenever we get a private message or a message is posted in a group we are an active member
SyncMessageReceivedV2 (timestamp<x>, sender<s>, destination<s>, groupId<ay>, message<s>, mentions<a(sii)>, attachments<a(sssxibiiss)>)::
* timestamp : Integer value that is used by the system to send a ReceiptReceived reply
* sender : Phone number of the sender
* destination : UUID (legacy identifier) of the destination
* groupId : Byte array representing the internal group identifier (empty when private message)
* message : Message text
* mentions : Struct array of mentions: number, position, length
** number : String phone number
** position : Integer starting position of mention within message
** length : Integer length of mention within message
* attachments : Struct array of attachment metadata.
** contentType : String representing the MIME type of the attachment
** fileName : String representing file name if given by the Signal servers
** id : String representing remote identifier of attachment. This the name used by signal-cli to store the attachment, and the current user needs to have read access
** size : Long representing size of attachment in bytes
** keyLength : Integer representing key length
** voiceNote : boolean representing whether this attachment is a voice note
** width : Integer representation of width in pixels (0 if not image)
** height : Integer representation of height in pixels (0 if not image)
** caption : String representing photo caption
** blurHash : String representing blur hash
The sync message is received when the user sends a message from a linked device.
MessageReceivedV2(timestamp<x>, sender<s>, groupId<ay>, message<s>, mentions<a(sii)>, attachments<a(sssxibiiss)>)::
* timestamp : Integer value that is used by the system to send a ReceiptReceived reply
* sender : Phone number of the sender
* groupId : Byte array representing the internal group identifier (empty when private message)
* message : Message text
* mentions : Struct array of mentions: number, position, length
** number : String phone number
** position : Integer starting position of mention within message
** length : Integer length of mention within message
* attachments : Struct array of attachment metadata.
** contentType : String representing the MIME type of the attachment
** fileName : String representing file name if given by the Signal servers
** id : String representing remote identifier of attachment. This the name used by signal-cli to store the attachment, and the current user needs to have read access
** size : Long representing size of attachment in bytes
** keyLength : Integer representing key length
** voiceNote : boolean representing whether this attachment is a voice note
** width : Integer representation of width in pixels (0 if not image)
** height : Integer representation of height in pixels (0 if not image)
** caption : String representing photo caption
** blurHash : String representing blur hash
This signal is received whenever we get a private message or a message is posted in a group we are an active member
ReceiptReceived (timestamp<x>, sender<s>)::
* timestamp : Integer value that can be used to associate this e.g. with a sendMessage()
* sender : Phone number of the sender
This signal is sent by each recipient (e.g. each group member) after the message was successfully delivered to the device
== Examples
Send a text message (without attachment) to a contact::

View file

@ -1,11 +1,15 @@
package org.asamk;
import org.asamk.Signal.Error;
import org.asamk.signal.manager.AvatarStore;
import org.asamk.signal.manager.groups.GroupId;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.exceptions.DBusExecutionException;
import org.freedesktop.dbus.interfaces.DBusInterface;
import org.freedesktop.dbus.messages.DBusSignal;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Map;
@ -69,8 +73,6 @@ public interface Signal extends DBusInterface {
List<byte[]> getGroupIds();
List<String> getBase64GroupIds();
String getGroupName(byte[] groupId);
List<String> getGroupMembers(byte[] groupId);
@ -79,6 +81,45 @@ public interface Signal extends DBusInterface {
byte[] groupId, String name, List<String> members, String avatar
) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber, Error.GroupNotFound;
String updateGroup(
String base64GroupId,
String name,
String description,
List<String> addMembers,
List<String> removeMembers,
List<String> addAdmins,
List<String> removeAdmins,
boolean resetGroupLink,
String groupLinkState,
String addMemberPermission,
String editDetailsPermission,
String avatar,
Integer expirationTimer
) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber, Error.GroupNotFound;
String getGroupName(String base64GroupId);
// To get the group Ids in base 64 format, either use the getBaseGroupIds() method, or
// the getGroupIds(dummy) form, where dummy represents any string
List<String> getBase64GroupIds();
List<String> getGroupIds(String dummy);
void setGroupBlocked(String base64GroupId, boolean blocked) throws Error.GroupNotFound;
List<String> getGroupMembers(String dummy);
long sendGroupMessage(
String message, List<String> attachments, String base64GroupId
) throws Error.GroupNotFound, Error.Failure, Error.AttachmentInvalid;
long sendGroupMessageReaction(
String emoji, boolean remove, String targetAuthor, long targetSentTimestamp, String base64GroupId
) throws Error.GroupNotFound, Error.Failure, Error.InvalidNumber;
String updateGroup(
String base64GroupId, String name, List<String> members, String avatar
) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber, Error.GroupNotFound;
boolean isRegistered(String number);
List<Boolean> isRegistered(List<String> numbers);

View file

@ -73,7 +73,7 @@ public class UpdateGroupCommand implements DbusCommand, JsonRpcLocalCommand {
subparser.addArgument("-e", "--expiration").type(int.class).help("Set expiration time of messages (seconds)");
}
GroupLinkState getGroupLinkState(String value) throws UserErrorException {
public static GroupLinkState getGroupLinkState(String value) throws UserErrorException {
if (value == null) {
return null;
}
@ -90,7 +90,7 @@ public class UpdateGroupCommand implements DbusCommand, JsonRpcLocalCommand {
}
}
GroupPermission getGroupPermission(String value) throws UserErrorException {
public static GroupPermission getGroupPermission(String value) throws UserErrorException {
if (value == null) {
return null;
}

View file

@ -5,15 +5,19 @@ import org.asamk.signal.BaseConfig;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.PlainTextWriter;
import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.commands.UpdateGroupCommand;
import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.AttachmentInvalidException;
import org.asamk.signal.manager.AvatarStore;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.NotMasterDeviceException;
import org.asamk.signal.manager.api.Device;
import org.asamk.signal.manager.groups.GroupId;
import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
import org.asamk.signal.manager.groups.GroupLinkState;
import org.asamk.signal.manager.groups.GroupNotFoundException;
import org.asamk.signal.manager.groups.GroupPermission;
import org.asamk.signal.manager.groups.LastGroupAdminException;
import org.asamk.signal.manager.groups.NotAGroupMemberException;
import org.asamk.signal.manager.storage.identities.IdentityInfo;
@ -32,6 +36,7 @@ import org.whispersystems.signalservice.api.util.InvalidNumberException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@ -283,6 +288,11 @@ public class DbusSignalImpl implements Signal {
throw new Error.AttachmentInvalid(e.getMessage());
}
}
@Override
public long sendGroupMessage(final String message, final List<String> attachments, final String base64GroupId) {
byte[] groupId = Base64.getDecoder().decode(base64GroupId);
return sendGroupMessage(message, attachments, groupId);
}
@Override
public long sendGroupMessageReaction(
@ -309,6 +319,18 @@ public class DbusSignalImpl implements Signal {
}
}
@Override
public long sendGroupMessageReaction(
final String emoji,
final boolean remove,
final String targetAuthor,
final long targetSentTimestamp,
final String base64GroupId
) {
byte[] groupId = Base64.getDecoder().decode(base64GroupId);
return sendGroupMessageReaction(emoji, remove, targetAuthor, targetSentTimestamp, groupId);
}
// Since contact names might be empty if not defined, also potentially return
// the profile name
@Override
@ -362,6 +384,12 @@ public class DbusSignalImpl implements Signal {
}
}
@Override
public void setGroupBlocked(final String base64GroupId, final boolean blocked) {
byte[] groupId = Base64.getDecoder().decode(base64GroupId);
setGroupBlocked(groupId, blocked);
}
@Override
public List<byte[]> getGroupIds() {
var groups = m.getGroups();
@ -372,16 +400,6 @@ public class DbusSignalImpl implements Signal {
return ids;
}
@Override
public List<String> getBase64GroupIds() {
var groups = m.getGroups();
var ids = new ArrayList<String>(groups.size());
for (var group : groups) {
ids.add(group.getGroupId().toBase64());
}
return ids;
}
@Override
public String getGroupName(final byte[] groupId) {
var group = m.getGroup(GroupId.unknownVersion(groupId));
@ -406,6 +424,54 @@ public class DbusSignalImpl implements Signal {
}
}
// To get the group Ids in base 64 format, either use the getBaseGroupIds() method, or
// the getGroupIds(dummy) form, where dummy represents any string
@Override
public List<String> getBase64GroupIds() {
var groups = m.getGroups();
var ids = new ArrayList<String>(groups.size());
for (var group : groups) {
ids.add(group.getGroupId().toBase64());
}
return ids;
}
@Override
public List<String> getGroupIds(String dummy) {
var groups = m.getGroups();
var ids = new ArrayList<String>(groups.size());
for (var group : groups) {
ids.add(group.getGroupId().toBase64());
}
return ids;
}
@Override
public String getGroupName(final String base64GroupId) {
byte[] groupId = Base64.getDecoder().decode(base64GroupId);
var group = m.getGroup(GroupId.unknownVersion(groupId));
if (group == null) {
return "";
} else {
return group.getTitle();
}
}
@Override
public List<String> getGroupMembers(final String base64GroupId) {
byte[] groupId = Base64.getDecoder().decode(base64GroupId);
var group = m.getGroup(GroupId.unknownVersion(groupId));
if (group == null) {
return List.of();
} else {
return group.getMembers()
.stream()
.map(m::resolveSignalServiceAddress)
.map(Util::getLegacyIdentifier)
.collect(Collectors.toList());
}
}
@Override
public byte[] updateGroup(byte[] groupId, String name, List<String> members, String avatar) {
try {
@ -455,6 +521,169 @@ public class DbusSignalImpl implements Signal {
}
}
@Override
public String updateGroup(String base64GroupId, String name, List<String> members, String avatar) {
byte[] groupId = Base64.getDecoder().decode(base64GroupId);
groupId = updateGroup(groupId, name, members, avatar);
return Base64.getEncoder().encodeToString(groupId);
}
/*
GroupLinkState getGroupLinkState(String value) throws UserErrorException {
if (value == null) {
return null;
}
switch (value) {
case "enabled":
return GroupLinkState.ENABLED;
case "enabled-with-approval":
case "enabledWithApproval":
return GroupLinkState.ENABLED_WITH_APPROVAL;
case "disabled":
return GroupLinkState.DISABLED;
default:
throw new UserErrorException("Invalid group link state: " + value);
}
}
GroupPermission getGroupPermission(String value) throws UserErrorException {
if (value == null) {
return null;
}
switch (value) {
case "every-member":
case "everyMember":
return GroupPermission.EVERY_MEMBER;
case "only-admins":
case "onlyAdmins":
return GroupPermission.ONLY_ADMINS;
default:
throw new UserErrorException("Invalid group permission: " + value);
}
}
*/
/*
*
*
public Pair<Long, List<SendMessageResult>> updateGroup(
GroupId groupId,
String name,
String description,
List<String> addMembers,
List<String> removeMembers,
List<String> addAdmins,
List<String> removeAdmins,
boolean resetGroupLink,
GroupLinkState groupLinkState,
GroupPermission addMemberPermission,
GroupPermission editDetailsPermission,
File avatarFile,
Integer expirationTimer
*/
@Override
public String updateGroup(
String base64GroupId,
String name,
String description,
List<String> addMembers,
List<String> removeMembers,
List<String> addAdmins,
List<String> removeAdmins,
boolean resetGroupLink,
String groupLinkState,
String addMemberPermission,
String editDetailsPermission,
String avatar,
Integer expirationTimer
) {
try {
byte[] groupId = null;
File avatarFile = null;
if (base64GroupId.isEmpty()) {
throw new Error.GroupNotFound("No group specified.");
} else {
groupId = Base64.getDecoder().decode(base64GroupId);
}
if (name.isEmpty()) {
name = null;
}
if (description.isEmpty()) {
description= null;
}
if (addMembers.isEmpty()) {
addMembers = null;
}
if (removeMembers.isEmpty()) {
removeMembers = null;
}
if (addAdmins.isEmpty()) {
addAdmins = null;
}
if (removeAdmins.isEmpty()) {
removeAdmins = null;
}
if (groupLinkState.isEmpty()) {
groupLinkState = null;
}
if (addMemberPermission.isEmpty()) {
addMemberPermission = null;
}
if (editDetailsPermission.isEmpty()) {
editDetailsPermission = null;
}
if (avatar.isEmpty()) {
avatarFile = null;
} else {
avatarFile = new File(avatar);
//check if we are sending an empty file. If so, this tells Signal
// to delete the avatar, and we will delete it from the local AvatarStore
long fileSize = avatarFile.length();
if (fileSize == 0) {
try {
AvatarStore.deleteGroupAvatar(GroupId.unknownVersion(groupId));
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
}
}
}
if (groupId == null) {
final var results = m.createGroup(name, addMembers, avatar == null ? null : new File(avatar));
checkSendMessageResults(0, results.second());
return Base64.getEncoder().encodeToString(results.first().serialize());
} else {
final var results = m.updateGroup(GroupId.unknownVersion(groupId),
name,
description,
addMembers,
removeMembers,
addAdmins,
removeAdmins,
resetGroupLink,
groupLinkState == null ? null : UpdateGroupCommand.getGroupLinkState(groupLinkState),
addMemberPermission == null ? null : UpdateGroupCommand.getGroupPermission(addMemberPermission),
editDetailsPermission == null ? null : UpdateGroupCommand.getGroupPermission(editDetailsPermission),
avatarFile,
expirationTimer
);
if (results != null) {
checkSendMessageResults(results.first(), results.second());
}
return base64GroupId;
}
} catch (UserErrorException | IOException e) {
throw new Error.Failure(e.getMessage());
} catch ( GroupNotFoundException | NotAGroupMemberException e) {
throw new Error.GroupNotFound(e.getMessage());
} catch (InvalidNumberException e) {
throw new Error.InvalidNumber(e.getMessage());
} catch (AttachmentInvalidException e) {
throw new Error.AttachmentInvalid(e.getMessage());
}
}
@Override
public boolean isRegistered(String number) {
try {