mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-07 14:30:38 +00:00
Merge branch master into dbus_mentions_attachments
This commit is contained in:
commit
0583ad8f19
33 changed files with 1731 additions and 698 deletions
|
@ -1,9 +1,13 @@
|
|||
package org.asamk;
|
||||
|
||||
import org.asamk.signal.commands.exceptions.IOErrorException;
|
||||
import org.asamk.signal.dbus.DbusAttachment;
|
||||
import org.asamk.signal.dbus.DbusMention;
|
||||
|
||||
import org.freedesktop.dbus.DBusPath;
|
||||
import org.freedesktop.dbus.Struct;
|
||||
import org.freedesktop.dbus.annotations.DBusProperty;
|
||||
import org.freedesktop.dbus.annotations.Position;
|
||||
import org.freedesktop.dbus.exceptions.DBusException;
|
||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
import org.freedesktop.dbus.interfaces.DBusInterface;
|
||||
|
@ -84,14 +88,27 @@ public interface Signal extends DBusInterface {
|
|||
|
||||
void setContactBlocked(String number, boolean blocked) throws Error.InvalidNumber;
|
||||
|
||||
@Deprecated
|
||||
void setGroupBlocked(byte[] groupId, boolean blocked) throws Error.GroupNotFound, Error.InvalidGroupId;
|
||||
|
||||
@Deprecated
|
||||
List<byte[]> getGroupIds();
|
||||
|
||||
DBusPath getGroup(byte[] groupId);
|
||||
|
||||
List<StructGroup> listGroups();
|
||||
|
||||
@Deprecated
|
||||
String getGroupName(byte[] groupId) throws Error.InvalidGroupId;
|
||||
|
||||
@Deprecated
|
||||
List<String> getGroupMembers(byte[] groupId) throws Error.InvalidGroupId;
|
||||
|
||||
byte[] createGroup(
|
||||
String name, List<String> members, String avatar
|
||||
) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber;
|
||||
|
||||
@Deprecated
|
||||
byte[] updateGroup(
|
||||
byte[] groupId, String name, List<String> members, String avatar
|
||||
) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber, Error.GroupNotFound, Error.InvalidGroupId;
|
||||
|
@ -106,7 +123,7 @@ public interface Signal extends DBusInterface {
|
|||
|
||||
DBusPath getDevice(long deviceId);
|
||||
|
||||
List<DBusPath> listDevices() throws Error.Failure;
|
||||
List<StructDevice> listDevices() throws Error.Failure;
|
||||
|
||||
DBusPath getThisDevice();
|
||||
|
||||
|
@ -133,18 +150,23 @@ public interface Signal extends DBusInterface {
|
|||
|
||||
List<String> getContactNumber(final String name) throws Error.Failure;
|
||||
|
||||
@Deprecated
|
||||
void quitGroup(final byte[] groupId) throws Error.GroupNotFound, Error.Failure, Error.InvalidGroupId;
|
||||
|
||||
boolean isContactBlocked(final String number) throws Error.InvalidNumber;
|
||||
|
||||
@Deprecated
|
||||
boolean isGroupBlocked(final byte[] groupId) throws Error.InvalidGroupId;
|
||||
|
||||
@Deprecated
|
||||
boolean isMember(final byte[] groupId) throws Error.InvalidGroupId;
|
||||
|
||||
byte[] joinGroup(final String groupLink) throws Error.Failure;
|
||||
|
||||
String uploadStickerPack(String stickerPackPath) throws Error.Failure;
|
||||
|
||||
void submitRateLimitChallenge(String challenge, String captchaString) throws IOErrorException;
|
||||
|
||||
class MessageReceived extends DBusSignal {
|
||||
|
||||
private final long timestamp;
|
||||
|
@ -417,7 +439,37 @@ public interface Signal extends DBusInterface {
|
|||
}
|
||||
}
|
||||
|
||||
@DBusProperty(name = "Id", type = Integer.class, access = DBusProperty.Access.READ)
|
||||
class StructDevice extends Struct {
|
||||
|
||||
@Position(0)
|
||||
DBusPath objectPath;
|
||||
|
||||
@Position(1)
|
||||
Long id;
|
||||
|
||||
@Position(2)
|
||||
String name;
|
||||
|
||||
public StructDevice(final DBusPath objectPath, final Long id, final String name) {
|
||||
this.objectPath = objectPath;
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public DBusPath getObjectPath() {
|
||||
return objectPath;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@DBusProperty(name = "Id", type = Long.class, access = DBusProperty.Access.READ)
|
||||
@DBusProperty(name = "Name", type = String.class)
|
||||
@DBusProperty(name = "Created", type = String.class, access = DBusProperty.Access.READ)
|
||||
@DBusProperty(name = "LastSeen", type = String.class, access = DBusProperty.Access.READ)
|
||||
|
@ -426,6 +478,71 @@ public interface Signal extends DBusInterface {
|
|||
void removeDevice() throws Error.Failure;
|
||||
}
|
||||
|
||||
class StructGroup extends Struct {
|
||||
|
||||
@Position(0)
|
||||
DBusPath objectPath;
|
||||
|
||||
@Position(1)
|
||||
byte[] id;
|
||||
|
||||
@Position(2)
|
||||
String name;
|
||||
|
||||
public StructGroup(final DBusPath objectPath, final byte[] id, final String name) {
|
||||
this.objectPath = objectPath;
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public DBusPath getObjectPath() {
|
||||
return objectPath;
|
||||
}
|
||||
|
||||
public byte[] getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@DBusProperty(name = "Id", type = Byte[].class, access = DBusProperty.Access.READ)
|
||||
@DBusProperty(name = "Name", type = String.class)
|
||||
@DBusProperty(name = "Description", type = String.class)
|
||||
@DBusProperty(name = "Avatar", type = String.class, access = DBusProperty.Access.WRITE)
|
||||
@DBusProperty(name = "IsBlocked", type = Boolean.class)
|
||||
@DBusProperty(name = "IsMember", type = Boolean.class, access = DBusProperty.Access.READ)
|
||||
@DBusProperty(name = "IsAdmin", type = Boolean.class, access = DBusProperty.Access.READ)
|
||||
@DBusProperty(name = "MessageExpirationTimer", type = Integer.class)
|
||||
@DBusProperty(name = "Members", type = String[].class, access = DBusProperty.Access.READ)
|
||||
@DBusProperty(name = "PendingMembers", type = String[].class, access = DBusProperty.Access.READ)
|
||||
@DBusProperty(name = "RequestingMembers", type = String[].class, access = DBusProperty.Access.READ)
|
||||
@DBusProperty(name = "Admins", type = String[].class, access = DBusProperty.Access.READ)
|
||||
@DBusProperty(name = "PermissionAddMember", type = String.class)
|
||||
@DBusProperty(name = "PermissionEditDetails", type = String.class)
|
||||
@DBusProperty(name = "PermissionSendMessage", type = String.class)
|
||||
@DBusProperty(name = "GroupInviteLink", type = String.class, access = DBusProperty.Access.READ)
|
||||
interface Group extends DBusInterface, Properties {
|
||||
|
||||
void quitGroup() throws Error.Failure, Error.LastGroupAdmin;
|
||||
|
||||
void addMembers(List<String> recipients) throws Error.Failure;
|
||||
|
||||
void removeMembers(List<String> recipients) throws Error.Failure;
|
||||
|
||||
void addAdmins(List<String> recipients) throws Error.Failure;
|
||||
|
||||
void removeAdmins(List<String> recipients) throws Error.Failure;
|
||||
|
||||
void resetLink() throws Error.Failure;
|
||||
|
||||
void disableLink() throws Error.Failure;
|
||||
|
||||
void enableLink(boolean requiresApproval) throws Error.Failure;
|
||||
}
|
||||
|
||||
interface Error {
|
||||
|
||||
class AttachmentInvalid extends DBusExecutionException {
|
||||
|
@ -449,6 +566,13 @@ public interface Signal extends DBusInterface {
|
|||
}
|
||||
}
|
||||
|
||||
class DeviceNotFound extends DBusExecutionException {
|
||||
|
||||
public DeviceNotFound(final String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
class GroupNotFound extends DBusExecutionException {
|
||||
|
||||
public GroupNotFound(final String message) {
|
||||
|
@ -463,6 +587,13 @@ public interface Signal extends DBusInterface {
|
|||
}
|
||||
}
|
||||
|
||||
class LastGroupAdmin extends DBusExecutionException {
|
||||
|
||||
public LastGroupAdmin(final String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
class InvalidNumber extends DBusExecutionException {
|
||||
|
||||
public InvalidNumber(final String message) {
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.asamk.signal.manager.api.RecipientIdentifier;
|
|||
import org.asamk.signal.manager.groups.GroupId;
|
||||
import org.asamk.signal.manager.groups.GroupUtils;
|
||||
import org.asamk.signal.util.DateUtils;
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.slf4j.helpers.MessageFormatter;
|
||||
import org.whispersystems.libsignal.protocol.DecryptionErrorMessage;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
||||
|
@ -377,9 +376,6 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
writer.println("Received sync message with verified identities:");
|
||||
final var verifiedMessage = syncMessage.getVerified().get();
|
||||
writer.println("- {}: {}", formatContact(verifiedMessage.getDestination()), verifiedMessage.getVerified());
|
||||
var safetyNumber = Util.formatSafetyNumber(m.computeSafetyNumber(verifiedMessage.getDestination(),
|
||||
verifiedMessage.getIdentityKey()));
|
||||
writer.indentedWriter().println(safetyNumber);
|
||||
}
|
||||
if (syncMessage.getConfiguration().isPresent()) {
|
||||
writer.println("Received sync message with configuration:");
|
||||
|
|
|
@ -52,6 +52,8 @@ public class BlockCommand implements JsonRpcLocalCommand {
|
|||
for (var groupId : CommandUtil.getGroupIds(groupIdStrings)) {
|
||||
try {
|
||||
m.setGroupBlocked(groupId, true);
|
||||
} catch (NotMasterDeviceException e) {
|
||||
throw new UserErrorException("This command doesn't work on linked devices.");
|
||||
} catch (GroupNotFoundException e) {
|
||||
logger.warn("Group not found {}: {}", groupId.toBase64(), e.getMessage());
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -63,7 +63,7 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
|
|||
resolveMembers(group.getPendingMembers()),
|
||||
resolveMembers(group.getRequestingMembers()),
|
||||
resolveMembers(group.getAdminMembers()),
|
||||
group.getMessageExpirationTime() == 0 ? "disabled" : group.getMessageExpirationTime() + "s",
|
||||
group.getMessageExpirationTimer() == 0 ? "disabled" : group.getMessageExpirationTimer() + "s",
|
||||
groupInviteLink == null ? '-' : groupInviteLink.getUrl());
|
||||
} else {
|
||||
writer.println("Id: {} Name: {} Active: {} Blocked: {}",
|
||||
|
@ -91,11 +91,14 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
|
|||
group.getDescription(),
|
||||
group.isMember(),
|
||||
group.isBlocked(),
|
||||
group.getMessageExpirationTime(),
|
||||
group.getMessageExpirationTimer(),
|
||||
resolveJsonMembers(group.getMembers()),
|
||||
resolveJsonMembers(group.getPendingMembers()),
|
||||
resolveJsonMembers(group.getRequestingMembers()),
|
||||
resolveJsonMembers(group.getAdminMembers()),
|
||||
group.getPermissionAddMember().name(),
|
||||
group.getPermissionEditDetails().name(),
|
||||
group.getPermissionSendMessage().name(),
|
||||
groupInviteLink == null ? null : groupInviteLink.getUrl());
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
|
@ -122,6 +125,9 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
|
|||
public final Set<JsonGroupMember> pendingMembers;
|
||||
public final Set<JsonGroupMember> requestingMembers;
|
||||
public final Set<JsonGroupMember> admins;
|
||||
public final String permissionAddMember;
|
||||
public final String permissionEditDetails;
|
||||
public final String permissionSendMessage;
|
||||
public final String groupInviteLink;
|
||||
|
||||
public JsonGroup(
|
||||
|
@ -135,6 +141,9 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
|
|||
Set<JsonGroupMember> pendingMembers,
|
||||
Set<JsonGroupMember> requestingMembers,
|
||||
Set<JsonGroupMember> admins,
|
||||
final String permissionAddMember,
|
||||
final String permissionEditDetails,
|
||||
final String permissionSendMessage,
|
||||
String groupInviteLink
|
||||
) {
|
||||
this.id = id;
|
||||
|
@ -148,6 +157,9 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
|
|||
this.pendingMembers = pendingMembers;
|
||||
this.requestingMembers = requestingMembers;
|
||||
this.admins = admins;
|
||||
this.permissionAddMember = permissionAddMember;
|
||||
this.permissionEditDetails = permissionEditDetails;
|
||||
this.permissionSendMessage = permissionSendMessage;
|
||||
this.groupInviteLink = groupInviteLink;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ public class UnblockCommand implements JsonRpcLocalCommand {
|
|||
for (var groupId : CommandUtil.getGroupIds(groupIdStrings)) {
|
||||
try {
|
||||
m.setGroupBlocked(groupId, false);
|
||||
} catch (NotMasterDeviceException e) {
|
||||
throw new UserErrorException("This command doesn't work on linked devices.");
|
||||
} catch (GroupNotFoundException e) {
|
||||
logger.warn("Unknown group id: {}", groupId);
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
|
|||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||
import org.asamk.signal.manager.AttachmentInvalidException;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.api.UpdateGroup;
|
||||
import org.asamk.signal.manager.groups.GroupId;
|
||||
import org.asamk.signal.manager.groups.GroupLinkState;
|
||||
import org.asamk.signal.manager.groups.GroupNotFoundException;
|
||||
|
@ -145,21 +146,23 @@ public class UpdateGroupCommand implements JsonRpcLocalCommand {
|
|||
}
|
||||
|
||||
var results = m.updateGroup(groupId,
|
||||
groupName,
|
||||
groupDescription,
|
||||
groupMembers,
|
||||
groupRemoveMembers,
|
||||
groupAdmins,
|
||||
groupRemoveAdmins,
|
||||
groupResetLink,
|
||||
groupLinkState,
|
||||
groupAddMemberPermission,
|
||||
groupEditDetailsPermission,
|
||||
groupAvatar == null ? null : new File(groupAvatar),
|
||||
groupExpiration,
|
||||
groupSendMessagesPermission == null
|
||||
? null
|
||||
: groupSendMessagesPermission == GroupPermission.ONLY_ADMINS);
|
||||
UpdateGroup.newBuilder()
|
||||
.withName(groupName)
|
||||
.withDescription(groupDescription)
|
||||
.withMembers(groupMembers)
|
||||
.withRemoveMembers(groupRemoveMembers)
|
||||
.withAdmins(groupAdmins)
|
||||
.withRemoveAdmins(groupRemoveAdmins)
|
||||
.withResetGroupLink(groupResetLink)
|
||||
.withGroupLinkState(groupLinkState)
|
||||
.withAddMemberPermission(groupAddMemberPermission)
|
||||
.withEditDetailsPermission(groupEditDetailsPermission)
|
||||
.withAvatarFile(groupAvatar == null ? null : new File(groupAvatar))
|
||||
.withExpirationTimer(groupExpiration)
|
||||
.withIsAnnouncementGroup(groupSendMessagesPermission == null
|
||||
? null
|
||||
: groupSendMessagesPermission == GroupPermission.ONLY_ADMINS)
|
||||
.build());
|
||||
if (results != null) {
|
||||
timestamp = results.getTimestamp();
|
||||
ErrorUtils.handleSendMessageResults(results.getResults());
|
||||
|
|
|
@ -15,9 +15,9 @@ import org.asamk.signal.manager.api.RecipientIdentifier;
|
|||
import org.asamk.signal.manager.api.SendGroupMessageResults;
|
||||
import org.asamk.signal.manager.api.SendMessageResults;
|
||||
import org.asamk.signal.manager.api.TypingAction;
|
||||
import org.asamk.signal.manager.api.UpdateGroup;
|
||||
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.GroupSendingNotAllowedException;
|
||||
|
@ -30,7 +30,6 @@ import org.freedesktop.dbus.DBusPath;
|
|||
import org.freedesktop.dbus.connections.impl.DBusConnection;
|
||||
import org.freedesktop.dbus.exceptions.DBusException;
|
||||
import org.freedesktop.dbus.interfaces.DBusInterface;
|
||||
import org.whispersystems.libsignal.IdentityKey;
|
||||
import org.whispersystems.libsignal.InvalidKeyException;
|
||||
import org.whispersystems.libsignal.util.Pair;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
@ -145,13 +144,14 @@ public class DbusManagerImpl implements Manager {
|
|||
@Override
|
||||
public List<Device> getLinkedDevices() throws IOException {
|
||||
final var thisDevice = signal.getThisDevice();
|
||||
return signal.listDevices().stream().map(devicePath -> {
|
||||
final var device = getRemoteObject(devicePath, Signal.Device.class).GetAll("org.asamk.Signal.Device");
|
||||
return signal.listDevices().stream().map(d -> {
|
||||
final var device = getRemoteObject(d.getObjectPath(),
|
||||
Signal.Device.class).GetAll("org.asamk.Signal.Device");
|
||||
return new Device((long) device.get("Id").getValue(),
|
||||
(String) device.get("Name").getValue(),
|
||||
(long) device.get("Created").getValue(),
|
||||
(long) device.get("LastSeen").getValue(),
|
||||
thisDevice.equals(devicePath));
|
||||
thisDevice.equals(d.getObjectPath()));
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
@ -182,8 +182,8 @@ public class DbusManagerImpl implements Manager {
|
|||
|
||||
@Override
|
||||
public List<Group> getGroups() {
|
||||
final var groupIds = signal.getGroupIds();
|
||||
return groupIds.stream().map(id -> getGroup(GroupId.unknownVersion(id))).collect(Collectors.toList());
|
||||
final var groups = signal.listGroups();
|
||||
return groups.stream().map(Signal.StructGroup::getObjectPath).map(this::getGroup).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -193,7 +193,8 @@ public class DbusManagerImpl implements Manager {
|
|||
if (groupAdmins.size() > 0) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
signal.quitGroup(groupId.serialize());
|
||||
final var group = getRemoteObject(signal.getGroup(groupId.serialize()), Signal.Group.class);
|
||||
group.quitGroup();
|
||||
return new SendGroupMessageResults(0, List.of());
|
||||
}
|
||||
|
||||
|
@ -206,8 +207,7 @@ public class DbusManagerImpl implements Manager {
|
|||
public Pair<GroupId, SendGroupMessageResults> createGroup(
|
||||
final String name, final Set<RecipientIdentifier.Single> members, final File avatarFile
|
||||
) throws IOException, AttachmentInvalidException {
|
||||
final var newGroupId = signal.updateGroup(new byte[0],
|
||||
emptyIfNull(name),
|
||||
final var newGroupId = signal.createGroup(emptyIfNull(name),
|
||||
members.stream().map(RecipientIdentifier.Single::getIdentifier).collect(Collectors.toList()),
|
||||
avatarFile == null ? "" : avatarFile.getPath());
|
||||
return new Pair<>(GroupId.unknownVersion(newGroupId), new SendGroupMessageResults(0, List.of()));
|
||||
|
@ -215,25 +215,76 @@ public class DbusManagerImpl implements Manager {
|
|||
|
||||
@Override
|
||||
public SendGroupMessageResults updateGroup(
|
||||
final GroupId groupId,
|
||||
final String name,
|
||||
final String description,
|
||||
final Set<RecipientIdentifier.Single> members,
|
||||
final Set<RecipientIdentifier.Single> removeMembers,
|
||||
final Set<RecipientIdentifier.Single> admins,
|
||||
final Set<RecipientIdentifier.Single> removeAdmins,
|
||||
final boolean resetGroupLink,
|
||||
final GroupLinkState groupLinkState,
|
||||
final GroupPermission addMemberPermission,
|
||||
final GroupPermission editDetailsPermission,
|
||||
final File avatarFile,
|
||||
final Integer expirationTimer,
|
||||
final Boolean isAnnouncementGroup
|
||||
final GroupId groupId, final UpdateGroup updateGroup
|
||||
) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException, GroupSendingNotAllowedException {
|
||||
signal.updateGroup(groupId.serialize(),
|
||||
emptyIfNull(name),
|
||||
members.stream().map(RecipientIdentifier.Single::getIdentifier).collect(Collectors.toList()),
|
||||
avatarFile == null ? "" : avatarFile.getPath());
|
||||
final var group = getRemoteObject(signal.getGroup(groupId.serialize()), Signal.Group.class);
|
||||
if (updateGroup.getName() != null) {
|
||||
group.Set("org.asamk.Signal.Group", "Name", updateGroup.getName());
|
||||
}
|
||||
if (updateGroup.getDescription() != null) {
|
||||
group.Set("org.asamk.Signal.Group", "Description", updateGroup.getDescription());
|
||||
}
|
||||
if (updateGroup.getAvatarFile() != null) {
|
||||
group.Set("org.asamk.Signal.Group",
|
||||
"Avatar",
|
||||
updateGroup.getAvatarFile() == null ? "" : updateGroup.getAvatarFile().getPath());
|
||||
}
|
||||
if (updateGroup.getExpirationTimer() != null) {
|
||||
group.Set("org.asamk.Signal.Group", "MessageExpirationTimer", updateGroup.getExpirationTimer());
|
||||
}
|
||||
if (updateGroup.getAddMemberPermission() != null) {
|
||||
group.Set("org.asamk.Signal.Group", "PermissionAddMember", updateGroup.getAddMemberPermission().name());
|
||||
}
|
||||
if (updateGroup.getEditDetailsPermission() != null) {
|
||||
group.Set("org.asamk.Signal.Group", "PermissionEditDetails", updateGroup.getEditDetailsPermission().name());
|
||||
}
|
||||
if (updateGroup.getIsAnnouncementGroup() != null) {
|
||||
group.Set("org.asamk.Signal.Group",
|
||||
"PermissionSendMessage",
|
||||
updateGroup.getIsAnnouncementGroup()
|
||||
? GroupPermission.ONLY_ADMINS.name()
|
||||
: GroupPermission.EVERY_MEMBER.name());
|
||||
}
|
||||
if (updateGroup.getMembers() != null) {
|
||||
group.addMembers(updateGroup.getMembers()
|
||||
.stream()
|
||||
.map(RecipientIdentifier.Single::getIdentifier)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
if (updateGroup.getRemoveMembers() != null) {
|
||||
group.removeMembers(updateGroup.getRemoveMembers()
|
||||
.stream()
|
||||
.map(RecipientIdentifier.Single::getIdentifier)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
if (updateGroup.getAdmins() != null) {
|
||||
group.addAdmins(updateGroup.getAdmins()
|
||||
.stream()
|
||||
.map(RecipientIdentifier.Single::getIdentifier)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
if (updateGroup.getRemoveAdmins() != null) {
|
||||
group.removeAdmins(updateGroup.getRemoveAdmins()
|
||||
.stream()
|
||||
.map(RecipientIdentifier.Single::getIdentifier)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
if (updateGroup.isResetGroupLink()) {
|
||||
group.resetLink();
|
||||
}
|
||||
if (updateGroup.getGroupLinkState() != null) {
|
||||
switch (updateGroup.getGroupLinkState()) {
|
||||
case DISABLED:
|
||||
group.disableLink();
|
||||
break;
|
||||
case ENABLED:
|
||||
group.enableLink(false);
|
||||
break;
|
||||
case ENABLED_WITH_APPROVAL:
|
||||
group.enableLink(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new SendGroupMessageResults(0, List.of());
|
||||
}
|
||||
|
||||
|
@ -343,7 +394,12 @@ public class DbusManagerImpl implements Manager {
|
|||
public void setGroupBlocked(
|
||||
final GroupId groupId, final boolean blocked
|
||||
) throws GroupNotFoundException, IOException {
|
||||
signal.setGroupBlocked(groupId.serialize(), blocked);
|
||||
setGroupProperty(groupId, "IsBlocked", blocked);
|
||||
}
|
||||
|
||||
private void setGroupProperty(final GroupId groupId, final String propertyName, final boolean blocked) {
|
||||
final var group = getRemoteObject(signal.getGroup(groupId.serialize()), Signal.Group.class);
|
||||
group.Set("org.asamk.Signal.Group", propertyName, blocked);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -410,19 +466,41 @@ public class DbusManagerImpl implements Manager {
|
|||
|
||||
@Override
|
||||
public Group getGroup(final GroupId groupId) {
|
||||
final var id = groupId.serialize();
|
||||
return new Group(groupId,
|
||||
signal.getGroupName(id),
|
||||
null,
|
||||
null,
|
||||
signal.getGroupMembers(id).stream().map(m -> new RecipientAddress(null, m)).collect(Collectors.toSet()),
|
||||
Set.of(),
|
||||
Set.of(),
|
||||
Set.of(),
|
||||
signal.isGroupBlocked(id),
|
||||
0,
|
||||
false,
|
||||
signal.isMember(id));
|
||||
final var groupPath = signal.getGroup(groupId.serialize());
|
||||
return getGroup(groupPath);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Group getGroup(final DBusPath groupPath) {
|
||||
final var group = getRemoteObject(groupPath, Signal.Group.class).GetAll("org.asamk.Signal.Group");
|
||||
final var id = (byte[]) group.get("Id").getValue();
|
||||
try {
|
||||
return new Group(GroupId.unknownVersion(id),
|
||||
(String) group.get("Name").getValue(),
|
||||
(String) group.get("Description").getValue(),
|
||||
GroupInviteLinkUrl.fromUri((String) group.get("GroupInviteLink").getValue()),
|
||||
((List<String>) group.get("Members").getValue()).stream()
|
||||
.map(m -> new RecipientAddress(null, m))
|
||||
.collect(Collectors.toSet()),
|
||||
((List<String>) group.get("PendingMembers").getValue()).stream()
|
||||
.map(m -> new RecipientAddress(null, m))
|
||||
.collect(Collectors.toSet()),
|
||||
((List<String>) group.get("RequestingMembers").getValue()).stream()
|
||||
.map(m -> new RecipientAddress(null, m))
|
||||
.collect(Collectors.toSet()),
|
||||
((List<String>) group.get("Admins").getValue()).stream()
|
||||
.map(m -> new RecipientAddress(null, m))
|
||||
.collect(Collectors.toSet()),
|
||||
(boolean) group.get("IsBlocked").getValue(),
|
||||
(int) group.get("MessageExpirationTimer").getValue(),
|
||||
GroupPermission.valueOf((String) group.get("PermissionAddMember").getValue()),
|
||||
GroupPermission.valueOf((String) group.get("PermissionEditDetails").getValue()),
|
||||
GroupPermission.valueOf((String) group.get("PermissionSendMessage").getValue()),
|
||||
(boolean) group.get("IsMember").getValue(),
|
||||
(boolean) group.get("IsAdmin").getValue());
|
||||
} catch (GroupInviteLinkUrl.InvalidGroupLinkException | GroupInviteLinkUrl.UnknownGroupLinkVersionException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -459,13 +537,6 @@ public class DbusManagerImpl implements Manager {
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String computeSafetyNumber(
|
||||
final SignalServiceAddress theirAddress, final IdentityKey theirIdentityKey
|
||||
) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignalServiceAddress resolveSignalServiceAddress(final SignalServiceAddress address) {
|
||||
return address;
|
||||
|
|
|
@ -51,6 +51,7 @@ public abstract class DbusProperties implements Properties {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Variant<?>> GetAll(final String interface_name) {
|
||||
final var handler = getHandlerOptional(interface_name);
|
||||
if (handler.isEmpty()) {
|
||||
|
@ -61,6 +62,9 @@ public abstract class DbusProperties implements Properties {
|
|||
.getProperties()
|
||||
.stream()
|
||||
.filter(p -> p.getGetter() != null)
|
||||
.collect(Collectors.toMap(DbusProperty::getName, p -> new Variant<>(p.getGetter().get())));
|
||||
.collect(Collectors.toMap(DbusProperty::getName, p -> {
|
||||
final Object o = p.getGetter().get();
|
||||
return o instanceof Variant ? (Variant<Object>) o : new Variant<>(o);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,12 @@ public class DbusProperty<T> {
|
|||
this.setter = null;
|
||||
}
|
||||
|
||||
public DbusProperty(final String name, final Consumer<T> setter) {
|
||||
this.name = name;
|
||||
this.getter = null;
|
||||
this.setter = setter;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.asamk.signal.dbus;
|
|||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.signal.BaseConfig;
|
||||
import org.asamk.signal.commands.exceptions.IOErrorException;
|
||||
import org.asamk.signal.manager.AttachmentInvalidException;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.NotMasterDeviceException;
|
||||
|
@ -11,9 +12,12 @@ import org.asamk.signal.manager.api.Identity;
|
|||
import org.asamk.signal.manager.api.Message;
|
||||
import org.asamk.signal.manager.api.RecipientIdentifier;
|
||||
import org.asamk.signal.manager.api.TypingAction;
|
||||
import org.asamk.signal.manager.api.UpdateGroup;
|
||||
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.GroupSendingNotAllowedException;
|
||||
import org.asamk.signal.manager.groups.LastGroupAdminException;
|
||||
import org.asamk.signal.manager.groups.NotAGroupMemberException;
|
||||
|
@ -24,6 +28,7 @@ import org.freedesktop.dbus.DBusPath;
|
|||
import org.freedesktop.dbus.connections.impl.DBusConnection;
|
||||
import org.freedesktop.dbus.exceptions.DBusException;
|
||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
import org.freedesktop.dbus.types.Variant;
|
||||
import org.whispersystems.libsignal.InvalidKeyException;
|
||||
import org.whispersystems.libsignal.util.Pair;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
@ -38,6 +43,8 @@ import java.io.IOException;
|
|||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -55,7 +62,8 @@ public class DbusSignalImpl implements Signal {
|
|||
private final String objectPath;
|
||||
|
||||
private DBusPath thisDevice;
|
||||
private final List<DBusPath> devices = new ArrayList<>();
|
||||
private final List<StructDevice> devices = new ArrayList<>();
|
||||
private final List<StructGroup> groups = new ArrayList<>();
|
||||
|
||||
public DbusSignalImpl(final Manager m, DBusConnection connection, final String objectPath) {
|
||||
this.m = m;
|
||||
|
@ -65,6 +73,7 @@ public class DbusSignalImpl implements Signal {
|
|||
|
||||
public void initObjects() {
|
||||
updateDevices();
|
||||
updateGroups();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
|
@ -81,6 +90,18 @@ public class DbusSignalImpl implements Signal {
|
|||
return m.getSelfNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submitRateLimitChallenge(String challenge, String captchaString) throws IOErrorException {
|
||||
final var captcha = captchaString == null ? null : captchaString.replace("signalcaptcha://", "");
|
||||
|
||||
try {
|
||||
m.submitRateLimitRecaptchaChallenge(challenge, captcha);
|
||||
} catch (IOException e) {
|
||||
throw new IOErrorException("Submit challenge error: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDevice(String uri) {
|
||||
try {
|
||||
|
@ -97,45 +118,19 @@ public class DbusSignalImpl implements Signal {
|
|||
@Override
|
||||
public DBusPath getDevice(long deviceId) {
|
||||
updateDevices();
|
||||
return new DBusPath(getDeviceObjectPath(objectPath, deviceId));
|
||||
final var deviceOptional = devices.stream().filter(g -> g.getId().equals(deviceId)).findFirst();
|
||||
if (deviceOptional.isEmpty()) {
|
||||
throw new Error.DeviceNotFound("Device not found");
|
||||
}
|
||||
return deviceOptional.get().getObjectPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DBusPath> listDevices() {
|
||||
public List<StructDevice> listDevices() {
|
||||
updateDevices();
|
||||
return this.devices;
|
||||
}
|
||||
|
||||
private void updateDevices() {
|
||||
List<org.asamk.signal.manager.api.Device> linkedDevices;
|
||||
try {
|
||||
linkedDevices = m.getLinkedDevices();
|
||||
} catch (IOException | Error.Failure e) {
|
||||
throw new Error.Failure("Failed to get linked devices: " + e.getMessage());
|
||||
}
|
||||
|
||||
unExportDevices();
|
||||
|
||||
linkedDevices.forEach(d -> {
|
||||
final var object = new DbusSignalDeviceImpl(d);
|
||||
final var deviceObjectPath = object.getObjectPath();
|
||||
try {
|
||||
connection.exportObject(object);
|
||||
} catch (DBusException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (d.isThisDevice()) {
|
||||
thisDevice = new DBusPath(deviceObjectPath);
|
||||
}
|
||||
this.devices.add(new DBusPath(deviceObjectPath));
|
||||
});
|
||||
}
|
||||
|
||||
private void unExportDevices() {
|
||||
this.devices.stream().map(DBusPath::getPath).forEach(connection::unExportObject);
|
||||
this.devices.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DBusPath getThisDevice() {
|
||||
updateDevices();
|
||||
|
@ -410,6 +405,8 @@ public class DbusSignalImpl implements Signal {
|
|||
public void setGroupBlocked(final byte[] groupId, final boolean blocked) {
|
||||
try {
|
||||
m.setGroupBlocked(getGroupId(groupId), blocked);
|
||||
} catch (NotMasterDeviceException e) {
|
||||
throw new Error.Failure("This command doesn't work on linked devices.");
|
||||
} catch (GroupNotFoundException e) {
|
||||
throw new Error.GroupNotFound(e.getMessage());
|
||||
} catch (IOException e) {
|
||||
|
@ -427,6 +424,22 @@ public class DbusSignalImpl implements Signal {
|
|||
return ids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DBusPath getGroup(final byte[] groupId) {
|
||||
updateGroups();
|
||||
final var groupOptional = groups.stream().filter(g -> Arrays.equals(g.getId(), groupId)).findFirst();
|
||||
if (groupOptional.isEmpty()) {
|
||||
throw new Error.GroupNotFound("Group not found");
|
||||
}
|
||||
return groupOptional.get().getObjectPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StructGroup> listGroups() {
|
||||
updateGroups();
|
||||
return groups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroupName(final byte[] groupId) {
|
||||
var group = m.getGroup(getGroupId(groupId));
|
||||
|
@ -443,10 +456,18 @@ public class DbusSignalImpl implements Signal {
|
|||
if (group == null) {
|
||||
return List.of();
|
||||
} else {
|
||||
return group.getMembers().stream().map(RecipientAddress::getLegacyIdentifier).collect(Collectors.toList());
|
||||
final var members = group.getMembers();
|
||||
return getRecipientStrings(members);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] createGroup(
|
||||
final String name, final List<String> members, final String avatar
|
||||
) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber {
|
||||
return updateGroup(new byte[0], name, members, avatar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] updateGroup(byte[] groupId, String name, List<String> members, String avatar) {
|
||||
try {
|
||||
|
@ -460,19 +481,11 @@ public class DbusSignalImpl implements Signal {
|
|||
return results.first().serialize();
|
||||
} else {
|
||||
final var results = m.updateGroup(getGroupId(groupId),
|
||||
name,
|
||||
null,
|
||||
memberIdentifiers,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
avatar == null ? null : new File(avatar),
|
||||
null,
|
||||
null);
|
||||
UpdateGroup.newBuilder()
|
||||
.withName(name)
|
||||
.withMembers(memberIdentifiers)
|
||||
.withAvatarFile(avatar == null ? null : new File(avatar))
|
||||
.build());
|
||||
if (results != null) {
|
||||
checkSendMessageResults(results.getTimestamp(), results.getResults());
|
||||
}
|
||||
|
@ -752,6 +765,10 @@ public class DbusSignalImpl implements Signal {
|
|||
throw new Error.Failure(message.toString());
|
||||
}
|
||||
|
||||
private static List<String> getRecipientStrings(final Set<RecipientAddress> members) {
|
||||
return members.stream().map(RecipientAddress::getLegacyIdentifier).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static Set<RecipientIdentifier.Single> getSingleRecipientIdentifiers(
|
||||
final Collection<String> recipientStrings, final String localNumber
|
||||
) throws DBusExecutionException {
|
||||
|
@ -788,21 +805,87 @@ public class DbusSignalImpl implements Signal {
|
|||
return name.isEmpty() ? null : name;
|
||||
}
|
||||
|
||||
private String emptyIfNull(final String string) {
|
||||
return string == null ? "" : string;
|
||||
}
|
||||
|
||||
private static String getDeviceObjectPath(String basePath, long deviceId) {
|
||||
return basePath + "/Devices/" + deviceId;
|
||||
}
|
||||
|
||||
private void updateDevices() {
|
||||
List<org.asamk.signal.manager.api.Device> linkedDevices;
|
||||
try {
|
||||
linkedDevices = m.getLinkedDevices();
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure("Failed to get linked devices: " + e.getMessage());
|
||||
}
|
||||
|
||||
unExportDevices();
|
||||
|
||||
linkedDevices.forEach(d -> {
|
||||
final var object = new DbusSignalDeviceImpl(d);
|
||||
final var deviceObjectPath = object.getObjectPath();
|
||||
try {
|
||||
connection.exportObject(object);
|
||||
} catch (DBusException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (d.isThisDevice()) {
|
||||
thisDevice = new DBusPath(deviceObjectPath);
|
||||
}
|
||||
this.devices.add(new StructDevice(new DBusPath(deviceObjectPath), d.getId(), emptyIfNull(d.getName())));
|
||||
});
|
||||
}
|
||||
|
||||
private void unExportDevices() {
|
||||
this.devices.stream()
|
||||
.map(StructDevice::getObjectPath)
|
||||
.map(DBusPath::getPath)
|
||||
.forEach(connection::unExportObject);
|
||||
this.devices.clear();
|
||||
}
|
||||
|
||||
private static String getGroupObjectPath(String basePath, byte[] groupId) {
|
||||
return basePath + "/Groups/" + Base64.getEncoder()
|
||||
.encodeToString(groupId)
|
||||
.replace("+", "_")
|
||||
.replace("/", "_")
|
||||
.replace("=", "_");
|
||||
}
|
||||
|
||||
private void updateGroups() {
|
||||
List<org.asamk.signal.manager.api.Group> groups;
|
||||
groups = m.getGroups();
|
||||
|
||||
unExportGroups();
|
||||
|
||||
groups.forEach(g -> {
|
||||
final var object = new DbusSignalGroupImpl(g.getGroupId());
|
||||
try {
|
||||
connection.exportObject(object);
|
||||
} catch (DBusException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.groups.add(new StructGroup(new DBusPath(object.getObjectPath()),
|
||||
g.getGroupId().serialize(),
|
||||
emptyIfNull(g.getTitle())));
|
||||
});
|
||||
}
|
||||
|
||||
private void unExportGroups() {
|
||||
this.groups.stream().map(StructGroup::getObjectPath).map(DBusPath::getPath).forEach(connection::unExportObject);
|
||||
this.groups.clear();
|
||||
}
|
||||
|
||||
public class DbusSignalDeviceImpl extends DbusProperties implements Signal.Device {
|
||||
|
||||
private final org.asamk.signal.manager.api.Device device;
|
||||
|
||||
public DbusSignalDeviceImpl(final org.asamk.signal.manager.api.Device device) {
|
||||
super();
|
||||
super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Device",
|
||||
List.of(new DbusProperty<>("Id", device::getId),
|
||||
new DbusProperty<>("Name",
|
||||
() -> device.getName() == null ? "" : device.getName(),
|
||||
this::setDeviceName),
|
||||
new DbusProperty<>("Name", () -> emptyIfNull(device.getName()), this::setDeviceName),
|
||||
new DbusProperty<>("Created", device::getCreated),
|
||||
new DbusProperty<>("LastSeen", device::getLastSeen))));
|
||||
this.device = device;
|
||||
|
@ -836,4 +919,168 @@ public class DbusSignalImpl implements Signal {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class DbusSignalGroupImpl extends DbusProperties implements Signal.Group {
|
||||
|
||||
private final GroupId groupId;
|
||||
|
||||
public DbusSignalGroupImpl(final GroupId groupId) {
|
||||
this.groupId = groupId;
|
||||
super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Group",
|
||||
List.of(new DbusProperty<>("Id", groupId::serialize),
|
||||
new DbusProperty<>("Name", () -> emptyIfNull(getGroup().getTitle()), this::setGroupName),
|
||||
new DbusProperty<>("Description",
|
||||
() -> emptyIfNull(getGroup().getDescription()),
|
||||
this::setGroupDescription),
|
||||
new DbusProperty<>("Avatar", this::setGroupAvatar),
|
||||
new DbusProperty<>("IsBlocked", () -> getGroup().isBlocked(), this::setIsBlocked),
|
||||
new DbusProperty<>("IsMember", () -> getGroup().isMember()),
|
||||
new DbusProperty<>("IsAdmin", () -> getGroup().isAdmin()),
|
||||
new DbusProperty<>("MessageExpirationTimer",
|
||||
() -> getGroup().getMessageExpirationTimer(),
|
||||
this::setMessageExpirationTime),
|
||||
new DbusProperty<>("Members",
|
||||
() -> new Variant<>(getRecipientStrings(getGroup().getMembers()), "as")),
|
||||
new DbusProperty<>("PendingMembers",
|
||||
() -> new Variant<>(getRecipientStrings(getGroup().getPendingMembers()), "as")),
|
||||
new DbusProperty<>("RequestingMembers",
|
||||
() -> new Variant<>(getRecipientStrings(getGroup().getRequestingMembers()), "as")),
|
||||
new DbusProperty<>("Admins",
|
||||
() -> new Variant<>(getRecipientStrings(getGroup().getAdminMembers()), "as")),
|
||||
new DbusProperty<>("PermissionAddMember",
|
||||
() -> getGroup().getPermissionAddMember().name(),
|
||||
this::setGroupPermissionAddMember),
|
||||
new DbusProperty<>("PermissionEditDetails",
|
||||
() -> getGroup().getPermissionEditDetails().name(),
|
||||
this::setGroupPermissionEditDetails),
|
||||
new DbusProperty<>("PermissionSendMessage",
|
||||
() -> getGroup().getPermissionSendMessage().name(),
|
||||
this::setGroupPermissionSendMessage),
|
||||
new DbusProperty<>("GroupInviteLink", () -> {
|
||||
final var groupInviteLinkUrl = getGroup().getGroupInviteLinkUrl();
|
||||
return groupInviteLinkUrl == null ? "" : groupInviteLinkUrl.getUrl();
|
||||
}))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getObjectPath() {
|
||||
return getGroupObjectPath(objectPath, groupId.serialize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void quitGroup() throws Error.Failure {
|
||||
try {
|
||||
m.quitGroup(groupId, Set.of());
|
||||
} catch (GroupNotFoundException | NotAGroupMemberException e) {
|
||||
throw new Error.GroupNotFound(e.getMessage());
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure(e.getMessage());
|
||||
} catch (LastGroupAdminException e) {
|
||||
throw new Error.LastGroupAdmin(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMembers(final List<String> recipients) throws Error.Failure {
|
||||
final var memberIdentifiers = getSingleRecipientIdentifiers(recipients, m.getSelfNumber());
|
||||
updateGroup(UpdateGroup.newBuilder().withMembers(memberIdentifiers).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMembers(final List<String> recipients) throws Error.Failure {
|
||||
final var memberIdentifiers = getSingleRecipientIdentifiers(recipients, m.getSelfNumber());
|
||||
updateGroup(UpdateGroup.newBuilder().withRemoveMembers(memberIdentifiers).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAdmins(final List<String> recipients) throws Error.Failure {
|
||||
final var memberIdentifiers = getSingleRecipientIdentifiers(recipients, m.getSelfNumber());
|
||||
updateGroup(UpdateGroup.newBuilder().withAdmins(memberIdentifiers).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAdmins(final List<String> recipients) throws Error.Failure {
|
||||
final var memberIdentifiers = getSingleRecipientIdentifiers(recipients, m.getSelfNumber());
|
||||
updateGroup(UpdateGroup.newBuilder().withRemoveAdmins(memberIdentifiers).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetLink() throws Error.Failure {
|
||||
updateGroup(UpdateGroup.newBuilder().withResetGroupLink(true).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableLink() throws Error.Failure {
|
||||
updateGroup(UpdateGroup.newBuilder().withGroupLinkState(GroupLinkState.DISABLED).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableLink(final boolean requiresApproval) throws Error.Failure {
|
||||
updateGroup(UpdateGroup.newBuilder()
|
||||
.withGroupLinkState(requiresApproval
|
||||
? GroupLinkState.ENABLED_WITH_APPROVAL
|
||||
: GroupLinkState.ENABLED)
|
||||
.build());
|
||||
}
|
||||
|
||||
private org.asamk.signal.manager.api.Group getGroup() {
|
||||
return m.getGroup(groupId);
|
||||
}
|
||||
|
||||
private void setGroupName(final String name) {
|
||||
updateGroup(UpdateGroup.newBuilder().withName(name).build());
|
||||
}
|
||||
|
||||
private void setGroupDescription(final String description) {
|
||||
updateGroup(UpdateGroup.newBuilder().withDescription(description).build());
|
||||
}
|
||||
|
||||
private void setGroupAvatar(final String avatar) {
|
||||
updateGroup(UpdateGroup.newBuilder().withAvatarFile(new File(avatar)).build());
|
||||
}
|
||||
|
||||
private void setMessageExpirationTime(final int expirationTime) {
|
||||
updateGroup(UpdateGroup.newBuilder().withExpirationTimer(expirationTime).build());
|
||||
}
|
||||
|
||||
private void setGroupPermissionAddMember(final String permission) {
|
||||
updateGroup(UpdateGroup.newBuilder().withAddMemberPermission(GroupPermission.valueOf(permission)).build());
|
||||
}
|
||||
|
||||
private void setGroupPermissionEditDetails(final String permission) {
|
||||
updateGroup(UpdateGroup.newBuilder()
|
||||
.withEditDetailsPermission(GroupPermission.valueOf(permission))
|
||||
.build());
|
||||
}
|
||||
|
||||
private void setGroupPermissionSendMessage(final String permission) {
|
||||
updateGroup(UpdateGroup.newBuilder()
|
||||
.withIsAnnouncementGroup(GroupPermission.valueOf(permission) == GroupPermission.ONLY_ADMINS)
|
||||
.build());
|
||||
}
|
||||
|
||||
private void setIsBlocked(final boolean isBlocked) {
|
||||
try {
|
||||
m.setGroupBlocked(groupId, isBlocked);
|
||||
} catch (NotMasterDeviceException e) {
|
||||
throw new Error.Failure("This command doesn't work on linked devices.");
|
||||
} catch (GroupNotFoundException e) {
|
||||
throw new Error.GroupNotFound(e.getMessage());
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void updateGroup(final UpdateGroup updateGroup) {
|
||||
try {
|
||||
m.updateGroup(groupId, updateGroup);
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure(e.getMessage());
|
||||
} catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
|
||||
throw new Error.GroupNotFound(e.getMessage());
|
||||
} catch (AttachmentInvalidException e) {
|
||||
throw new Error.AttachmentInvalid(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue