mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +00:00
Implement announcement groups
This commit is contained in:
parent
b745f1f902
commit
610e32aa52
5 changed files with 38 additions and 7 deletions
|
@ -809,7 +809,8 @@ public class Manager implements Closeable {
|
||||||
GroupPermission addMemberPermission,
|
GroupPermission addMemberPermission,
|
||||||
GroupPermission editDetailsPermission,
|
GroupPermission editDetailsPermission,
|
||||||
File avatarFile,
|
File avatarFile,
|
||||||
Integer expirationTimer
|
Integer expirationTimer,
|
||||||
|
Boolean isAnnouncementGroup
|
||||||
) throws IOException, GroupNotFoundException, AttachmentInvalidException, InvalidNumberException, NotAGroupMemberException {
|
) throws IOException, GroupNotFoundException, AttachmentInvalidException, InvalidNumberException, NotAGroupMemberException {
|
||||||
return updateGroup(groupId,
|
return updateGroup(groupId,
|
||||||
name,
|
name,
|
||||||
|
@ -823,7 +824,8 @@ public class Manager implements Closeable {
|
||||||
addMemberPermission,
|
addMemberPermission,
|
||||||
editDetailsPermission,
|
editDetailsPermission,
|
||||||
avatarFile,
|
avatarFile,
|
||||||
expirationTimer);
|
expirationTimer,
|
||||||
|
isAnnouncementGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pair<Long, List<SendMessageResult>> updateGroup(
|
private Pair<Long, List<SendMessageResult>> updateGroup(
|
||||||
|
@ -839,7 +841,8 @@ public class Manager implements Closeable {
|
||||||
final GroupPermission addMemberPermission,
|
final GroupPermission addMemberPermission,
|
||||||
final GroupPermission editDetailsPermission,
|
final GroupPermission editDetailsPermission,
|
||||||
final File avatarFile,
|
final File avatarFile,
|
||||||
final Integer expirationTimer
|
final Integer expirationTimer,
|
||||||
|
final Boolean isAnnouncementGroup
|
||||||
) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
|
) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
|
||||||
var group = getGroupForUpdating(groupId);
|
var group = getGroupForUpdating(groupId);
|
||||||
|
|
||||||
|
@ -857,7 +860,8 @@ public class Manager implements Closeable {
|
||||||
addMemberPermission,
|
addMemberPermission,
|
||||||
editDetailsPermission,
|
editDetailsPermission,
|
||||||
avatarFile,
|
avatarFile,
|
||||||
expirationTimer);
|
expirationTimer,
|
||||||
|
isAnnouncementGroup);
|
||||||
} catch (ConflictException e) {
|
} catch (ConflictException e) {
|
||||||
// Detected conflicting update, refreshing group and trying again
|
// Detected conflicting update, refreshing group and trying again
|
||||||
group = getGroup(groupId, true);
|
group = getGroup(groupId, true);
|
||||||
|
@ -873,7 +877,8 @@ public class Manager implements Closeable {
|
||||||
addMemberPermission,
|
addMemberPermission,
|
||||||
editDetailsPermission,
|
editDetailsPermission,
|
||||||
avatarFile,
|
avatarFile,
|
||||||
expirationTimer);
|
expirationTimer,
|
||||||
|
isAnnouncementGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -948,7 +953,8 @@ public class Manager implements Closeable {
|
||||||
final GroupPermission addMemberPermission,
|
final GroupPermission addMemberPermission,
|
||||||
final GroupPermission editDetailsPermission,
|
final GroupPermission editDetailsPermission,
|
||||||
final File avatarFile,
|
final File avatarFile,
|
||||||
Integer expirationTimer
|
final Integer expirationTimer,
|
||||||
|
final Boolean isAnnouncementGroup
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
Pair<Long, List<SendMessageResult>> result = null;
|
Pair<Long, List<SendMessageResult>> result = null;
|
||||||
if (group.isPendingMember(account.getSelfRecipientId())) {
|
if (group.isPendingMember(account.getSelfRecipientId())) {
|
||||||
|
@ -1034,6 +1040,11 @@ public class Manager implements Closeable {
|
||||||
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
|
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isAnnouncementGroup != null) {
|
||||||
|
var groupGroupChangePair = groupV2Helper.setIsAnnouncementGroup(group, isAnnouncementGroup);
|
||||||
|
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
|
||||||
|
}
|
||||||
|
|
||||||
if (name != null || description != null || avatarFile != null) {
|
if (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) {
|
||||||
|
|
|
@ -407,6 +407,14 @@ public class GroupV2Helper {
|
||||||
return commitChange(groupInfoV2, change);
|
return commitChange(groupInfoV2, change);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Pair<DecryptedGroup, GroupChange> setIsAnnouncementGroup(
|
||||||
|
GroupInfoV2 groupInfoV2, boolean isAnnouncementGroup
|
||||||
|
) throws IOException {
|
||||||
|
final GroupsV2Operations.GroupOperations groupOperations = getGroupOperations(groupInfoV2);
|
||||||
|
final var change = groupOperations.createAnnouncementGroupChange(isAnnouncementGroup);
|
||||||
|
return commitChange(groupInfoV2, change);
|
||||||
|
}
|
||||||
|
|
||||||
private AccessControl.AccessRequired toAccessControl(final GroupLinkState state) {
|
private AccessControl.AccessRequired toAccessControl(final GroupLinkState state) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case DISABLED:
|
case DISABLED:
|
||||||
|
|
|
@ -287,6 +287,10 @@ Set permission to add new group members: `every-member`, `only-admins`
|
||||||
*--set-permission-edit-details* PERMISSION::
|
*--set-permission-edit-details* PERMISSION::
|
||||||
Set permission to edit group details: `every-member`, `only-admins`
|
Set permission to edit group details: `every-member`, `only-admins`
|
||||||
|
|
||||||
|
*--set-permission-send-messages* PERMISSION::
|
||||||
|
Set permission to send messages in group: `every-member`, `only-admins`
|
||||||
|
Groups where only admins can send messages are also called announcement groups
|
||||||
|
|
||||||
*-e* EXPIRATION_SECONDS, *--expiration* EXPIRATION_SECONDS::
|
*-e* EXPIRATION_SECONDS, *--expiration* EXPIRATION_SECONDS::
|
||||||
Set expiration time of messages (seconds).
|
Set expiration time of messages (seconds).
|
||||||
To disable expiration set expiration time to 0.
|
To disable expiration set expiration time to 0.
|
||||||
|
|
|
@ -70,6 +70,9 @@ public class UpdateGroupCommand implements DbusCommand, JsonRpcLocalCommand {
|
||||||
subparser.addArgument("--set-permission-edit-details")
|
subparser.addArgument("--set-permission-edit-details")
|
||||||
.help("Set permission to edit group details")
|
.help("Set permission to edit group details")
|
||||||
.choices("every-member", "only-admins");
|
.choices("every-member", "only-admins");
|
||||||
|
subparser.addArgument("--set-permission-send-messages")
|
||||||
|
.help("Set permission to send messages")
|
||||||
|
.choices("every-member", "only-admins");
|
||||||
|
|
||||||
subparser.addArgument("-e", "--expiration").type(int.class).help("Set expiration time of messages (seconds)");
|
subparser.addArgument("-e", "--expiration").type(int.class).help("Set expiration time of messages (seconds)");
|
||||||
}
|
}
|
||||||
|
@ -133,6 +136,7 @@ public class UpdateGroupCommand implements DbusCommand, JsonRpcLocalCommand {
|
||||||
var groupExpiration = ns.getInt("expiration");
|
var groupExpiration = ns.getInt("expiration");
|
||||||
var groupAddMemberPermission = getGroupPermission(ns.getString("set-permission-add-member"));
|
var groupAddMemberPermission = getGroupPermission(ns.getString("set-permission-add-member"));
|
||||||
var groupEditDetailsPermission = getGroupPermission(ns.getString("set-permission-edit-details"));
|
var groupEditDetailsPermission = getGroupPermission(ns.getString("set-permission-edit-details"));
|
||||||
|
var groupSendMessagesPermission = getGroupPermission(ns.getString("set-permission-send-messages"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
boolean isNewGroup = false;
|
boolean isNewGroup = false;
|
||||||
|
@ -160,7 +164,10 @@ public class UpdateGroupCommand implements DbusCommand, JsonRpcLocalCommand {
|
||||||
groupAddMemberPermission,
|
groupAddMemberPermission,
|
||||||
groupEditDetailsPermission,
|
groupEditDetailsPermission,
|
||||||
groupAvatar == null ? null : new File(groupAvatar),
|
groupAvatar == null ? null : new File(groupAvatar),
|
||||||
groupExpiration);
|
groupExpiration,
|
||||||
|
groupSendMessagesPermission == null
|
||||||
|
? null
|
||||||
|
: groupSendMessagesPermission == GroupPermission.ONLY_ADMINS);
|
||||||
Long timestamp = null;
|
Long timestamp = null;
|
||||||
if (results != null) {
|
if (results != null) {
|
||||||
timestamp = results.first();
|
timestamp = results.first();
|
||||||
|
|
|
@ -358,6 +358,7 @@ public class DbusSignalImpl implements Signal {
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
avatar == null ? null : new File(avatar),
|
avatar == null ? null : new File(avatar),
|
||||||
|
null,
|
||||||
null);
|
null);
|
||||||
if (results != null) {
|
if (results != null) {
|
||||||
checkSendMessageResults(results.first(), results.second());
|
checkSendMessageResults(results.first(), results.second());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue