mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Add group descriptions
This commit is contained in:
parent
8e8eed7b06
commit
dd0effc10c
8 changed files with 108 additions and 10 deletions
|
@ -783,17 +783,17 @@ public class Manager implements Closeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pair<GroupId, List<SendMessageResult>> updateGroup(
|
public Pair<GroupId, List<SendMessageResult>> updateGroup(
|
||||||
GroupId groupId, String name, List<String> members, File avatarFile
|
GroupId groupId, String name, String description, List<String> members, File avatarFile
|
||||||
) throws IOException, GroupNotFoundException, AttachmentInvalidException, InvalidNumberException, NotAGroupMemberException {
|
) throws IOException, GroupNotFoundException, AttachmentInvalidException, InvalidNumberException, NotAGroupMemberException {
|
||||||
final var membersRecipientIds = members == null ? null : getSignalServiceAddresses(members);
|
final var membersRecipientIds = members == null ? null : getSignalServiceAddresses(members);
|
||||||
if (membersRecipientIds != null) {
|
if (membersRecipientIds != null) {
|
||||||
membersRecipientIds.remove(account.getSelfRecipientId());
|
membersRecipientIds.remove(account.getSelfRecipientId());
|
||||||
}
|
}
|
||||||
return sendUpdateGroupMessage(groupId, name, membersRecipientIds, avatarFile);
|
return sendUpdateGroupMessage(groupId, name, description, membersRecipientIds, avatarFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pair<GroupId, List<SendMessageResult>> sendUpdateGroupMessage(
|
private Pair<GroupId, List<SendMessageResult>> sendUpdateGroupMessage(
|
||||||
GroupId groupId, String name, Set<RecipientId> members, File avatarFile
|
GroupId groupId, String name, String description, Set<RecipientId> members, File avatarFile
|
||||||
) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
|
) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
|
||||||
GroupInfo g;
|
GroupInfo g;
|
||||||
SignalServiceDataMessage.Builder messageBuilder;
|
SignalServiceDataMessage.Builder messageBuilder;
|
||||||
|
@ -809,6 +809,7 @@ public class Manager implements Closeable {
|
||||||
messageBuilder = getGroupUpdateMessageBuilder(gv1);
|
messageBuilder = getGroupUpdateMessageBuilder(gv1);
|
||||||
g = gv1;
|
g = gv1;
|
||||||
} else {
|
} else {
|
||||||
|
// TODO set description as well
|
||||||
final var gv2 = gv2Pair.first();
|
final var gv2 = gv2Pair.first();
|
||||||
final var decryptedGroup = gv2Pair.second();
|
final var decryptedGroup = gv2Pair.second();
|
||||||
|
|
||||||
|
@ -843,8 +844,8 @@ public class Manager implements Closeable {
|
||||||
groupGroupChangePair.second());
|
groupGroupChangePair.second());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result == null || name != null || avatarFile != null) {
|
if (result == null || name != null || description != null || avatarFile != null) {
|
||||||
var groupGroupChangePair = groupHelper.updateGroupV2(groupInfoV2, name, avatarFile);
|
var groupGroupChangePair = groupHelper.updateGroupV2(groupInfoV2, name, description, avatarFile);
|
||||||
if (avatarFile != null) {
|
if (avatarFile != null) {
|
||||||
avatarStore.storeGroupAvatar(groupInfoV2.getGroupId(),
|
avatarStore.storeGroupAvatar(groupInfoV2.getGroupId(),
|
||||||
outputStream -> IOUtils.copyFileToStream(avatarFile, outputStream));
|
outputStream -> IOUtils.copyFileToStream(avatarFile, outputStream));
|
||||||
|
|
|
@ -196,13 +196,17 @@ public class GroupHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pair<DecryptedGroup, GroupChange> updateGroupV2(
|
public Pair<DecryptedGroup, GroupChange> updateGroupV2(
|
||||||
GroupInfoV2 groupInfoV2, String name, File avatarFile
|
GroupInfoV2 groupInfoV2, String name, String description, File avatarFile
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
||||||
var groupOperations = groupsV2Operations.forGroup(groupSecretParams);
|
var groupOperations = groupsV2Operations.forGroup(groupSecretParams);
|
||||||
|
|
||||||
var change = name != null ? groupOperations.createModifyGroupTitle(name) : GroupChange.Actions.newBuilder();
|
var change = name != null ? groupOperations.createModifyGroupTitle(name) : GroupChange.Actions.newBuilder();
|
||||||
|
|
||||||
|
if (description != null) {
|
||||||
|
change.setModifyDescription(groupOperations.createModifyGroupDescription(description));
|
||||||
|
}
|
||||||
|
|
||||||
if (avatarFile != null) {
|
if (avatarFile != null) {
|
||||||
final var avatarBytes = readAvatarBytes(avatarFile);
|
final var avatarBytes = readAvatarBytes(avatarFile);
|
||||||
var avatarCdnKey = groupsV2Api.uploadAvatar(avatarBytes,
|
var avatarCdnKey = groupsV2Api.uploadAvatar(avatarBytes,
|
||||||
|
|
|
@ -14,6 +14,10 @@ public abstract class GroupInfo {
|
||||||
|
|
||||||
public abstract String getTitle();
|
public abstract String getTitle();
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract GroupInviteLinkUrl getGroupInviteLink();
|
public abstract GroupInviteLinkUrl getGroupInviteLink();
|
||||||
|
|
||||||
public abstract Set<RecipientId> getMembers();
|
public abstract Set<RecipientId> getMembers();
|
||||||
|
|
|
@ -59,6 +59,14 @@ public class GroupInfoV2 extends GroupInfo {
|
||||||
return this.group.getTitle();
|
return this.group.getTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
if (this.group == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return this.group.getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GroupInviteLinkUrl getGroupInviteLink() {
|
public GroupInviteLinkUrl getGroupInviteLink() {
|
||||||
if (this.group == null || this.group.getInviteLinkPassword() == null || (
|
if (this.group == null || this.group.getInviteLinkPassword() == null || (
|
||||||
|
|
|
@ -20,6 +20,7 @@ import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -285,6 +286,14 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
DateUtils.formatTimestamp(rm.getTimestamp()));
|
DateUtils.formatTimestamp(rm.getTimestamp()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (syncMessage.getViewed().isPresent()) {
|
||||||
|
writer.println("Received sync viewed messages list");
|
||||||
|
for (var vm : syncMessage.getViewed().get()) {
|
||||||
|
writer.println("- From: {} Message timestamp: {}",
|
||||||
|
formatContact(vm.getSender()),
|
||||||
|
DateUtils.formatTimestamp(vm.getTimestamp()));
|
||||||
|
}
|
||||||
|
}
|
||||||
if (syncMessage.getRequest().isPresent()) {
|
if (syncMessage.getRequest().isPresent()) {
|
||||||
String type;
|
String type;
|
||||||
if (syncMessage.getRequest().get().isContactsRequest()) {
|
if (syncMessage.getRequest().get().isContactsRequest()) {
|
||||||
|
@ -643,8 +652,19 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
pointer.getPreview().isPresent() ? " (Preview is available: "
|
pointer.getPreview().isPresent() ? " (Preview is available: "
|
||||||
+ pointer.getPreview().get().length
|
+ pointer.getPreview().get().length
|
||||||
+ " bytes)" : "");
|
+ " bytes)" : "");
|
||||||
writer.println("Voice note: {}", pointer.getVoiceNote() ? "yes" : "no");
|
final var flags = new ArrayList<String>();
|
||||||
writer.println("Borderless: {}", pointer.isBorderless() ? "yes" : "no");
|
if (pointer.getVoiceNote()) {
|
||||||
|
flags.add("voice note");
|
||||||
|
}
|
||||||
|
if (pointer.isBorderless()) {
|
||||||
|
flags.add("borderless");
|
||||||
|
}
|
||||||
|
if (pointer.isGif()) {
|
||||||
|
flags.add("video gif");
|
||||||
|
}
|
||||||
|
if (flags.size() > 0) {
|
||||||
|
writer.println("Flags: {}", String.join(", ", flags));
|
||||||
|
}
|
||||||
if (pointer.getWidth() > 0 || pointer.getHeight() > 0) {
|
if (pointer.getWidth() > 0 || pointer.getHeight() > 0) {
|
||||||
writer.println("Dimensions: {}x{}", pointer.getWidth(), pointer.getHeight());
|
writer.println("Dimensions: {}x{}", pointer.getWidth(), pointer.getHeight());
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,9 +38,10 @@ public class ListGroupsCommand implements LocalCommand {
|
||||||
final var groupInviteLink = group.getGroupInviteLink();
|
final var groupInviteLink = group.getGroupInviteLink();
|
||||||
|
|
||||||
writer.println(
|
writer.println(
|
||||||
"Id: {} Name: {} Active: {} Blocked: {} Members: {} Pending members: {} Requesting members: {} Link: {}",
|
"Id: {} Name: {} Description: {} Active: {} Blocked: {} Members: {} Pending members: {} Requesting members: {} Link: {}",
|
||||||
group.getGroupId().toBase64(),
|
group.getGroupId().toBase64(),
|
||||||
group.getTitle(),
|
group.getTitle(),
|
||||||
|
group.getDescription(),
|
||||||
group.isMember(m.getSelfRecipientId()),
|
group.isMember(m.getSelfRecipientId()),
|
||||||
group.isBlocked(),
|
group.isBlocked(),
|
||||||
resolveMembers(m, group.getMembers()),
|
resolveMembers(m, group.getMembers()),
|
||||||
|
@ -81,6 +82,7 @@ public class ListGroupsCommand implements LocalCommand {
|
||||||
|
|
||||||
jsonGroups.add(new JsonGroup(group.getGroupId().toBase64(),
|
jsonGroups.add(new JsonGroup(group.getGroupId().toBase64(),
|
||||||
group.getTitle(),
|
group.getTitle(),
|
||||||
|
group.getDescription(),
|
||||||
group.isMember(m.getSelfRecipientId()),
|
group.isMember(m.getSelfRecipientId()),
|
||||||
group.isBlocked(),
|
group.isBlocked(),
|
||||||
resolveMembers(m, group.getMembers()),
|
resolveMembers(m, group.getMembers()),
|
||||||
|
@ -103,6 +105,7 @@ public class ListGroupsCommand implements LocalCommand {
|
||||||
|
|
||||||
public String id;
|
public String id;
|
||||||
public String name;
|
public String name;
|
||||||
|
public String description;
|
||||||
public boolean isMember;
|
public boolean isMember;
|
||||||
public boolean isBlocked;
|
public boolean isBlocked;
|
||||||
|
|
||||||
|
@ -114,6 +117,7 @@ public class ListGroupsCommand implements LocalCommand {
|
||||||
public JsonGroup(
|
public JsonGroup(
|
||||||
String id,
|
String id,
|
||||||
String name,
|
String name,
|
||||||
|
String description,
|
||||||
boolean isMember,
|
boolean isMember,
|
||||||
boolean isBlocked,
|
boolean isBlocked,
|
||||||
Set<String> members,
|
Set<String> members,
|
||||||
|
@ -123,6 +127,7 @@ public class ListGroupsCommand implements LocalCommand {
|
||||||
) {
|
) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
this.isMember = isMember;
|
this.isMember = isMember;
|
||||||
this.isBlocked = isBlocked;
|
this.isBlocked = isBlocked;
|
||||||
|
|
||||||
|
|
|
@ -8,17 +8,26 @@ 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;
|
||||||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||||
|
import org.asamk.signal.manager.AttachmentInvalidException;
|
||||||
|
import org.asamk.signal.manager.Manager;
|
||||||
|
import org.asamk.signal.manager.groups.GroupId;
|
||||||
import org.asamk.signal.manager.groups.GroupIdFormatException;
|
import org.asamk.signal.manager.groups.GroupIdFormatException;
|
||||||
|
import org.asamk.signal.manager.groups.GroupNotFoundException;
|
||||||
|
import org.asamk.signal.manager.groups.NotAGroupMemberException;
|
||||||
|
import org.asamk.signal.util.ErrorUtils;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.util.Util;
|
||||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UpdateGroupCommand implements DbusCommand {
|
public class UpdateGroupCommand implements DbusCommand, LocalCommand {
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(UpdateGroupCommand.class);
|
private final static Logger logger = LoggerFactory.getLogger(UpdateGroupCommand.class);
|
||||||
|
|
||||||
|
@ -26,10 +35,56 @@ public class UpdateGroupCommand implements DbusCommand {
|
||||||
public void attachToSubparser(final Subparser subparser) {
|
public void attachToSubparser(final Subparser subparser) {
|
||||||
subparser.addArgument("-g", "--group").help("Specify the recipient group ID.");
|
subparser.addArgument("-g", "--group").help("Specify the recipient group ID.");
|
||||||
subparser.addArgument("-n", "--name").help("Specify the new group name.");
|
subparser.addArgument("-n", "--name").help("Specify the new group name.");
|
||||||
|
subparser.addArgument("-d", "--description").help("Specify the new group description.");
|
||||||
subparser.addArgument("-a", "--avatar").help("Specify a new group avatar image file");
|
subparser.addArgument("-a", "--avatar").help("Specify a new group avatar image file");
|
||||||
subparser.addArgument("-m", "--member").nargs("*").help("Specify one or more members to add to the group");
|
subparser.addArgument("-m", "--member").nargs("*").help("Specify one or more members to add to the group");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
|
||||||
|
final var writer = new PlainTextWriterImpl(System.out);
|
||||||
|
GroupId groupId = null;
|
||||||
|
final var groupIdString = ns.getString("group");
|
||||||
|
if (groupIdString != null) {
|
||||||
|
try {
|
||||||
|
groupId = Util.decodeGroupId(groupIdString);
|
||||||
|
} catch (GroupIdFormatException e) {
|
||||||
|
throw new UserErrorException("Invalid group id:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var groupName = ns.getString("name");
|
||||||
|
|
||||||
|
var groupDescription = ns.getString("description");
|
||||||
|
|
||||||
|
List<String> groupMembers = ns.getList("member");
|
||||||
|
|
||||||
|
var groupAvatar = ns.getString("avatar");
|
||||||
|
|
||||||
|
try {
|
||||||
|
var results = m.updateGroup(groupId,
|
||||||
|
groupName,
|
||||||
|
groupDescription,
|
||||||
|
groupMembers,
|
||||||
|
groupAvatar == null ? null : new File(groupAvatar));
|
||||||
|
ErrorUtils.handleTimestampAndSendMessageResults(writer, 0, results.second());
|
||||||
|
final var newGroupId = results.first();
|
||||||
|
if (groupId == null) {
|
||||||
|
writer.println("Created new group: \"{}\"", newGroupId.toBase64());
|
||||||
|
}
|
||||||
|
} catch (AttachmentInvalidException e) {
|
||||||
|
throw new UserErrorException("Failed to add avatar attachment for group\": " + e.getMessage());
|
||||||
|
} catch (GroupNotFoundException e) {
|
||||||
|
logger.warn("Unknown group id: {}", groupIdString);
|
||||||
|
} catch (NotAGroupMemberException e) {
|
||||||
|
logger.warn("You're not a group member");
|
||||||
|
} catch (InvalidNumberException e) {
|
||||||
|
throw new UserErrorException("Failed to parse member number: " + e.getMessage());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new UnexpectedErrorException("Failed to send message: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCommand(final Namespace ns, final Signal signal) throws CommandException {
|
public void handleCommand(final Namespace ns, final Signal signal) throws CommandException {
|
||||||
final var writer = new PlainTextWriterImpl(System.out);
|
final var writer = new PlainTextWriterImpl(System.out);
|
||||||
|
|
|
@ -337,6 +337,7 @@ public class DbusSignalImpl implements Signal {
|
||||||
}
|
}
|
||||||
final var results = m.updateGroup(groupId == null ? null : GroupId.unknownVersion(groupId),
|
final var results = m.updateGroup(groupId == null ? null : GroupId.unknownVersion(groupId),
|
||||||
name,
|
name,
|
||||||
|
null,
|
||||||
members,
|
members,
|
||||||
avatar == null ? null : new File(avatar));
|
avatar == null ? null : new File(avatar));
|
||||||
checkSendMessageResults(0, results.second());
|
checkSendMessageResults(0, results.second());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue