mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Implement setting expiration timer for groups
This commit is contained in:
parent
03589f858b
commit
7170a68571
4 changed files with 48 additions and 17 deletions
|
@ -836,7 +836,8 @@ public class Manager implements Closeable {
|
|||
List<String> removeAdmins,
|
||||
boolean resetGroupLink,
|
||||
GroupLinkState groupLinkState,
|
||||
File avatarFile
|
||||
File avatarFile,
|
||||
Integer expirationTimer
|
||||
) throws IOException, GroupNotFoundException, AttachmentInvalidException, InvalidNumberException, NotAGroupMemberException {
|
||||
return updateGroup(groupId,
|
||||
name,
|
||||
|
@ -847,7 +848,8 @@ public class Manager implements Closeable {
|
|||
removeAdmins == null ? null : getSignalServiceAddresses(removeAdmins),
|
||||
resetGroupLink,
|
||||
groupLinkState,
|
||||
avatarFile);
|
||||
avatarFile,
|
||||
expirationTimer);
|
||||
}
|
||||
|
||||
private Pair<Long, List<SendMessageResult>> updateGroup(
|
||||
|
@ -860,7 +862,8 @@ public class Manager implements Closeable {
|
|||
final Set<RecipientId> removeAdmins,
|
||||
final boolean resetGroupLink,
|
||||
final GroupLinkState groupLinkState,
|
||||
final File avatarFile
|
||||
final File avatarFile,
|
||||
Integer expirationTimer
|
||||
) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
|
||||
var group = getGroupForUpdating(groupId);
|
||||
|
||||
|
@ -874,10 +877,16 @@ public class Manager implements Closeable {
|
|||
removeAdmins,
|
||||
resetGroupLink,
|
||||
groupLinkState,
|
||||
avatarFile);
|
||||
avatarFile,
|
||||
expirationTimer);
|
||||
}
|
||||
|
||||
return updateGroupV1((GroupInfoV1) group, name, members, avatarFile);
|
||||
final var gv1 = (GroupInfoV1) group;
|
||||
final var result = updateGroupV1(gv1, name, members, avatarFile);
|
||||
if (expirationTimer != null) {
|
||||
setExpirationTimer(gv1, expirationTimer);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Pair<Long, List<SendMessageResult>> updateGroupV1(
|
||||
|
@ -939,7 +948,8 @@ public class Manager implements Closeable {
|
|||
final Set<RecipientId> removeAdmins,
|
||||
final boolean resetGroupLink,
|
||||
final GroupLinkState groupLinkState,
|
||||
final File avatarFile
|
||||
final File avatarFile,
|
||||
Integer expirationTimer
|
||||
) throws IOException {
|
||||
Pair<Long, List<SendMessageResult>> result = null;
|
||||
if (group.isPendingMember(account.getSelfRecipientId())) {
|
||||
|
@ -1010,6 +1020,11 @@ public class Manager implements Closeable {
|
|||
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
|
||||
}
|
||||
|
||||
if (expirationTimer != null) {
|
||||
var groupGroupChangePair = groupV2Helper.setMessageExpirationTimer(group, expirationTimer);
|
||||
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
|
||||
}
|
||||
|
||||
if (result == null || name != null || description != null || avatarFile != null) {
|
||||
var groupGroupChangePair = groupV2Helper.updateGroup(group, name, description, avatarFile);
|
||||
if (avatarFile != null) {
|
||||
|
@ -1306,15 +1321,17 @@ public class Manager implements Closeable {
|
|||
/**
|
||||
* Change the expiration timer for a group
|
||||
*/
|
||||
public void setExpirationTimer(GroupId groupId, int messageExpirationTimer) {
|
||||
var g = getGroup(groupId);
|
||||
if (g instanceof GroupInfoV1) {
|
||||
var groupInfoV1 = (GroupInfoV1) g;
|
||||
groupInfoV1.messageExpirationTime = messageExpirationTimer;
|
||||
account.getGroupStore().updateGroup(groupInfoV1);
|
||||
} else {
|
||||
throw new RuntimeException("TODO Not implemented!");
|
||||
}
|
||||
private void setExpirationTimer(
|
||||
GroupInfoV1 groupInfoV1, int messageExpirationTimer
|
||||
) throws NotAGroupMemberException, GroupNotFoundException, IOException {
|
||||
groupInfoV1.messageExpirationTime = messageExpirationTimer;
|
||||
account.getGroupStore().updateGroup(groupInfoV1);
|
||||
sendExpirationTimerUpdate(groupInfoV1.getGroupId());
|
||||
}
|
||||
|
||||
private void sendExpirationTimerUpdate(GroupIdV1 groupId) throws IOException, NotAGroupMemberException, GroupNotFoundException {
|
||||
final var messageBuilder = SignalServiceDataMessage.newBuilder().asExpirationUpdate();
|
||||
sendGroupMessage(messageBuilder, groupId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -369,6 +369,14 @@ public class GroupV2Helper {
|
|||
return commitChange(groupInfoV2, change);
|
||||
}
|
||||
|
||||
public Pair<DecryptedGroup, GroupChange> setMessageExpirationTimer(
|
||||
GroupInfoV2 groupInfoV2, int messageExpirationTimer
|
||||
) throws IOException {
|
||||
final GroupsV2Operations.GroupOperations groupOperations = getGroupOperations(groupInfoV2);
|
||||
final var change = groupOperations.createModifyGroupTimerChange(messageExpirationTimer);
|
||||
return commitChange(groupInfoV2, change);
|
||||
}
|
||||
|
||||
private AccessControl.AccessRequired toAccessControl(final GroupLinkState state) {
|
||||
switch (state) {
|
||||
case DISABLED:
|
||||
|
|
|
@ -54,6 +54,8 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
|
|||
subparser.addArgument("--link")
|
||||
.help("Set group link state, with or without admin approval")
|
||||
.type(Arguments.enumStringType(GroupLinkState.class));
|
||||
|
||||
subparser.addArgument("-e", "--expiration").type(int.class).help("Set expiration time of messages (seconds)");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -87,6 +89,8 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
|
|||
|
||||
var groupLinkState = ns.<GroupLinkState>get("link");
|
||||
|
||||
var groupExpiration = ns.getInt("expiration");
|
||||
|
||||
try {
|
||||
if (groupId == null) {
|
||||
var results = m.createGroup(groupName,
|
||||
|
@ -105,7 +109,8 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
|
|||
groupRemoveAdmins,
|
||||
groupResetLink,
|
||||
groupLinkState != null ? groupLinkState.toLinkState() : null,
|
||||
groupAvatar == null ? null : new File(groupAvatar));
|
||||
groupAvatar == null ? null : new File(groupAvatar),
|
||||
groupExpiration);
|
||||
ErrorUtils.handleTimestampAndSendMessageResults(writer, results.first(), results.second());
|
||||
}
|
||||
} catch (AttachmentInvalidException e) {
|
||||
|
|
|
@ -349,7 +349,8 @@ public class DbusSignalImpl implements Signal {
|
|||
null,
|
||||
false,
|
||||
null,
|
||||
avatar == null ? null : new File(avatar));
|
||||
avatar == null ? null : new File(avatar),
|
||||
null);
|
||||
checkSendMessageResults(results.first(), results.second());
|
||||
return groupId;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue