mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Implement new dbus group interface
This commit is contained in:
parent
b5d4a5000b
commit
997b4f0c3f
15 changed files with 803 additions and 136 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -183,8 +183,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
|
||||
|
@ -194,7 +194,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());
|
||||
}
|
||||
|
||||
|
@ -207,8 +208,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()));
|
||||
|
@ -216,25 +216,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());
|
||||
}
|
||||
|
||||
|
@ -344,7 +395,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
|
||||
|
@ -411,19 +467,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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.asamk.signal.dbus;
|
||||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.Signal.Error;
|
||||
import org.asamk.signal.BaseConfig;
|
||||
import org.asamk.signal.commands.exceptions.IOErrorException;
|
||||
import org.asamk.signal.manager.AttachmentInvalidException;
|
||||
|
@ -13,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;
|
||||
|
@ -26,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;
|
||||
|
@ -40,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;
|
||||
|
@ -58,6 +63,7 @@ public class DbusSignalImpl implements Signal {
|
|||
|
||||
private DBusPath thisDevice;
|
||||
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;
|
||||
|
@ -67,6 +73,7 @@ public class DbusSignalImpl implements Signal {
|
|||
|
||||
public void initObjects() {
|
||||
updateDevices();
|
||||
updateGroups();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
|
@ -415,6 +422,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));
|
||||
|
@ -431,10 +454,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 {
|
||||
|
@ -448,19 +479,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());
|
||||
}
|
||||
|
@ -740,6 +763,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 {
|
||||
|
@ -817,6 +844,38 @@ public class DbusSignalImpl implements Signal {
|
|||
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;
|
||||
|
@ -858,4 +917,166 @@ 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 (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