mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Implement configuring of group link
This commit is contained in:
parent
3de30e166f
commit
03589f858b
7 changed files with 121 additions and 5 deletions
|
@ -23,6 +23,7 @@ import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
|
||||||
import org.asamk.signal.manager.groups.GroupId;
|
import org.asamk.signal.manager.groups.GroupId;
|
||||||
import org.asamk.signal.manager.groups.GroupIdV1;
|
import org.asamk.signal.manager.groups.GroupIdV1;
|
||||||
import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
|
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.GroupNotFoundException;
|
||||||
import org.asamk.signal.manager.groups.GroupUtils;
|
import org.asamk.signal.manager.groups.GroupUtils;
|
||||||
import org.asamk.signal.manager.groups.NotAGroupMemberException;
|
import org.asamk.signal.manager.groups.NotAGroupMemberException;
|
||||||
|
@ -833,6 +834,8 @@ public class Manager implements Closeable {
|
||||||
List<String> removeMembers,
|
List<String> removeMembers,
|
||||||
List<String> admins,
|
List<String> admins,
|
||||||
List<String> removeAdmins,
|
List<String> removeAdmins,
|
||||||
|
boolean resetGroupLink,
|
||||||
|
GroupLinkState groupLinkState,
|
||||||
File avatarFile
|
File avatarFile
|
||||||
) throws IOException, GroupNotFoundException, AttachmentInvalidException, InvalidNumberException, NotAGroupMemberException {
|
) throws IOException, GroupNotFoundException, AttachmentInvalidException, InvalidNumberException, NotAGroupMemberException {
|
||||||
return updateGroup(groupId,
|
return updateGroup(groupId,
|
||||||
|
@ -842,6 +845,8 @@ public class Manager implements Closeable {
|
||||||
removeMembers == null ? null : getSignalServiceAddresses(removeMembers),
|
removeMembers == null ? null : getSignalServiceAddresses(removeMembers),
|
||||||
admins == null ? null : getSignalServiceAddresses(admins),
|
admins == null ? null : getSignalServiceAddresses(admins),
|
||||||
removeAdmins == null ? null : getSignalServiceAddresses(removeAdmins),
|
removeAdmins == null ? null : getSignalServiceAddresses(removeAdmins),
|
||||||
|
resetGroupLink,
|
||||||
|
groupLinkState,
|
||||||
avatarFile);
|
avatarFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -853,6 +858,8 @@ public class Manager implements Closeable {
|
||||||
final Set<RecipientId> removeMembers,
|
final Set<RecipientId> removeMembers,
|
||||||
final Set<RecipientId> admins,
|
final Set<RecipientId> admins,
|
||||||
final Set<RecipientId> removeAdmins,
|
final Set<RecipientId> removeAdmins,
|
||||||
|
final boolean resetGroupLink,
|
||||||
|
final GroupLinkState groupLinkState,
|
||||||
final File avatarFile
|
final File avatarFile
|
||||||
) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
|
) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
|
||||||
var group = getGroupForUpdating(groupId);
|
var group = getGroupForUpdating(groupId);
|
||||||
|
@ -865,6 +872,8 @@ public class Manager implements Closeable {
|
||||||
removeMembers,
|
removeMembers,
|
||||||
admins,
|
admins,
|
||||||
removeAdmins,
|
removeAdmins,
|
||||||
|
resetGroupLink,
|
||||||
|
groupLinkState,
|
||||||
avatarFile);
|
avatarFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -928,6 +937,8 @@ public class Manager implements Closeable {
|
||||||
final Set<RecipientId> removeMembers,
|
final Set<RecipientId> removeMembers,
|
||||||
final Set<RecipientId> admins,
|
final Set<RecipientId> admins,
|
||||||
final Set<RecipientId> removeAdmins,
|
final Set<RecipientId> removeAdmins,
|
||||||
|
final boolean resetGroupLink,
|
||||||
|
final GroupLinkState groupLinkState,
|
||||||
final File avatarFile
|
final File avatarFile
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
Pair<Long, List<SendMessageResult>> result = null;
|
Pair<Long, List<SendMessageResult>> result = null;
|
||||||
|
@ -989,6 +1000,16 @@ public class Manager implements Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (resetGroupLink) {
|
||||||
|
var groupGroupChangePair = groupV2Helper.resetGroupLinkPassword(group);
|
||||||
|
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (groupLinkState != null) {
|
||||||
|
var groupGroupChangePair = groupV2Helper.setGroupLinkState(group, groupLinkState);
|
||||||
|
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
|
||||||
|
}
|
||||||
|
|
||||||
if (result == null || name != null || description != null || avatarFile != null) {
|
if (result == null || name != null || description != null || avatarFile != null) {
|
||||||
var groupGroupChangePair = groupV2Helper.updateGroup(group, name, description, avatarFile);
|
var groupGroupChangePair = groupV2Helper.updateGroup(group, name, description, avatarFile);
|
||||||
if (avatarFile != null) {
|
if (avatarFile != null) {
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package org.asamk.signal.manager.groups;
|
||||||
|
|
||||||
|
public enum GroupLinkState {
|
||||||
|
ENABLED,
|
||||||
|
ENABLED_WITH_APPROVAL,
|
||||||
|
DISABLED,
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package org.asamk.signal.manager.helper;
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
|
||||||
import org.asamk.signal.manager.groups.GroupLinkPassword;
|
import org.asamk.signal.manager.groups.GroupLinkPassword;
|
||||||
|
import org.asamk.signal.manager.groups.GroupLinkState;
|
||||||
import org.asamk.signal.manager.groups.GroupUtils;
|
import org.asamk.signal.manager.groups.GroupUtils;
|
||||||
import org.asamk.signal.manager.storage.groups.GroupInfoV2;
|
import org.asamk.signal.manager.storage.groups.GroupInfoV2;
|
||||||
import org.asamk.signal.manager.storage.recipients.Profile;
|
import org.asamk.signal.manager.storage.recipients.Profile;
|
||||||
|
@ -290,6 +291,29 @@ public class GroupV2Helper {
|
||||||
return revokeInvites(groupInfoV2, memberUuids);
|
return revokeInvites(groupInfoV2, memberUuids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Pair<DecryptedGroup, GroupChange> resetGroupLinkPassword(GroupInfoV2 groupInfoV2) throws IOException {
|
||||||
|
final GroupsV2Operations.GroupOperations groupOperations = getGroupOperations(groupInfoV2);
|
||||||
|
final var newGroupLinkPassword = GroupLinkPassword.createNew().serialize();
|
||||||
|
final var change = groupOperations.createModifyGroupLinkPasswordChange(newGroupLinkPassword);
|
||||||
|
return commitChange(groupInfoV2, change);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pair<DecryptedGroup, GroupChange> setGroupLinkState(
|
||||||
|
GroupInfoV2 groupInfoV2, GroupLinkState state
|
||||||
|
) throws IOException {
|
||||||
|
final GroupsV2Operations.GroupOperations groupOperations = getGroupOperations(groupInfoV2);
|
||||||
|
|
||||||
|
final var accessRequired = toAccessControl(state);
|
||||||
|
final var requiresNewPassword = state != GroupLinkState.DISABLED && groupInfoV2.getGroup()
|
||||||
|
.getInviteLinkPassword()
|
||||||
|
.isEmpty();
|
||||||
|
|
||||||
|
final var change = requiresNewPassword ? groupOperations.createModifyGroupLinkPasswordAndRightsChange(
|
||||||
|
GroupLinkPassword.createNew().serialize(),
|
||||||
|
accessRequired) : groupOperations.createChangeJoinByLinkRights(accessRequired);
|
||||||
|
return commitChange(groupInfoV2, change);
|
||||||
|
}
|
||||||
|
|
||||||
public GroupChange joinGroup(
|
public GroupChange joinGroup(
|
||||||
GroupMasterKey groupMasterKey,
|
GroupMasterKey groupMasterKey,
|
||||||
GroupLinkPassword groupLinkPassword,
|
GroupLinkPassword groupLinkPassword,
|
||||||
|
@ -345,6 +369,19 @@ public class GroupV2Helper {
|
||||||
return commitChange(groupInfoV2, change);
|
return commitChange(groupInfoV2, change);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AccessControl.AccessRequired toAccessControl(final GroupLinkState state) {
|
||||||
|
switch (state) {
|
||||||
|
case DISABLED:
|
||||||
|
return AccessControl.AccessRequired.UNSATISFIABLE;
|
||||||
|
case ENABLED:
|
||||||
|
return AccessControl.AccessRequired.ANY;
|
||||||
|
case ENABLED_WITH_APPROVAL:
|
||||||
|
return AccessControl.AccessRequired.ADMINISTRATOR;
|
||||||
|
default:
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private GroupsV2Operations.GroupOperations getGroupOperations(final GroupInfoV2 groupInfoV2) {
|
private GroupsV2Operations.GroupOperations getGroupOperations(final GroupInfoV2 groupInfoV2) {
|
||||||
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
||||||
return groupsV2Operations.forGroup(groupSecretParams);
|
return groupsV2Operations.forGroup(groupSecretParams);
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class GroupInfoV2 extends GroupInfo {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GroupInviteLinkUrl getGroupInviteLink() {
|
public GroupInviteLinkUrl getGroupInviteLink() {
|
||||||
if (this.group == null || this.group.getInviteLinkPassword() == null || (
|
if (this.group == null || this.group.getInviteLinkPassword().isEmpty() || (
|
||||||
this.group.getAccessControl().getAddFromInviteLink() != AccessControl.AccessRequired.ANY
|
this.group.getAccessControl().getAddFromInviteLink() != AccessControl.AccessRequired.ANY
|
||||||
&& this.group.getAccessControl().getAddFromInviteLink()
|
&& this.group.getAccessControl().getAddFromInviteLink()
|
||||||
!= AccessControl.AccessRequired.ADMINISTRATOR
|
!= AccessControl.AccessRequired.ADMINISTRATOR
|
||||||
|
|
35
src/main/java/org/asamk/signal/GroupLinkState.java
Normal file
35
src/main/java/org/asamk/signal/GroupLinkState.java
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package org.asamk.signal;
|
||||||
|
|
||||||
|
public enum GroupLinkState {
|
||||||
|
ENABLED {
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "enabled";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ENABLED_WITH_APPROVAL {
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "enabled-with-approval";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
DISABLED {
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "disabled";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public org.asamk.signal.manager.groups.GroupLinkState toLinkState() {
|
||||||
|
switch (this) {
|
||||||
|
case ENABLED:
|
||||||
|
return org.asamk.signal.manager.groups.GroupLinkState.ENABLED;
|
||||||
|
case ENABLED_WITH_APPROVAL:
|
||||||
|
return org.asamk.signal.manager.groups.GroupLinkState.ENABLED_WITH_APPROVAL;
|
||||||
|
case DISABLED:
|
||||||
|
return org.asamk.signal.manager.groups.GroupLinkState.DISABLED;
|
||||||
|
default:
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,11 @@
|
||||||
package org.asamk.signal.commands;
|
package org.asamk.signal.commands;
|
||||||
|
|
||||||
|
import net.sourceforge.argparse4j.impl.Arguments;
|
||||||
import net.sourceforge.argparse4j.inf.Namespace;
|
import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
import net.sourceforge.argparse4j.inf.Subparser;
|
import net.sourceforge.argparse4j.inf.Subparser;
|
||||||
|
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
|
import org.asamk.signal.GroupLinkState;
|
||||||
import org.asamk.signal.PlainTextWriterImpl;
|
import org.asamk.signal.PlainTextWriterImpl;
|
||||||
import org.asamk.signal.commands.exceptions.CommandException;
|
import org.asamk.signal.commands.exceptions.CommandException;
|
||||||
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
|
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
|
||||||
|
@ -46,6 +48,12 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
|
||||||
.nargs("*")
|
.nargs("*")
|
||||||
.help("Specify one or more members to remove group admin privileges");
|
.help("Specify one or more members to remove group admin privileges");
|
||||||
|
|
||||||
|
subparser.addArgument("--reset-link")
|
||||||
|
.action(Arguments.storeTrue())
|
||||||
|
.help("Reset group link and create new link password");
|
||||||
|
subparser.addArgument("--link")
|
||||||
|
.help("Set group link state, with or without admin approval")
|
||||||
|
.type(Arguments.enumStringType(GroupLinkState.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -65,16 +73,20 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
|
||||||
|
|
||||||
var groupDescription = ns.getString("description");
|
var groupDescription = ns.getString("description");
|
||||||
|
|
||||||
List<String> groupMembers = ns.getList("member");
|
var groupMembers = ns.<String>getList("member");
|
||||||
|
|
||||||
List<String> groupRemoveMembers = ns.getList("remove-member");
|
var groupRemoveMembers = ns.<String>getList("remove-member");
|
||||||
|
|
||||||
List<String> groupAdmins = ns.getList("admin");
|
var groupAdmins = ns.<String>getList("admin");
|
||||||
|
|
||||||
List<String> groupRemoveAdmins = ns.getList("remove-admin");
|
var groupRemoveAdmins = ns.<String>getList("remove-admin");
|
||||||
|
|
||||||
var groupAvatar = ns.getString("avatar");
|
var groupAvatar = ns.getString("avatar");
|
||||||
|
|
||||||
|
var groupResetLink = ns.getBoolean("reset-link");
|
||||||
|
|
||||||
|
var groupLinkState = ns.<GroupLinkState>get("link");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (groupId == null) {
|
if (groupId == null) {
|
||||||
var results = m.createGroup(groupName,
|
var results = m.createGroup(groupName,
|
||||||
|
@ -91,6 +103,8 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
|
||||||
groupRemoveMembers,
|
groupRemoveMembers,
|
||||||
groupAdmins,
|
groupAdmins,
|
||||||
groupRemoveAdmins,
|
groupRemoveAdmins,
|
||||||
|
groupResetLink,
|
||||||
|
groupLinkState != null ? groupLinkState.toLinkState() : null,
|
||||||
groupAvatar == null ? null : new File(groupAvatar));
|
groupAvatar == null ? null : new File(groupAvatar));
|
||||||
ErrorUtils.handleTimestampAndSendMessageResults(writer, results.first(), results.second());
|
ErrorUtils.handleTimestampAndSendMessageResults(writer, results.first(), results.second());
|
||||||
}
|
}
|
||||||
|
|
|
@ -347,6 +347,8 @@ public class DbusSignalImpl implements Signal {
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
|
false,
|
||||||
|
null,
|
||||||
avatar == null ? null : new File(avatar));
|
avatar == null ? null : new File(avatar));
|
||||||
checkSendMessageResults(results.first(), results.second());
|
checkSendMessageResults(results.first(), results.second());
|
||||||
return groupId;
|
return groupId;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue