Add group descriptions

This commit is contained in:
AsamK 2021-05-13 20:05:46 +02:00
parent 8e8eed7b06
commit dd0effc10c
8 changed files with 108 additions and 10 deletions

View file

@ -20,6 +20,7 @@ import org.whispersystems.signalservice.api.messages.shared.SharedContact;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.util.InvalidNumberException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.stream.Collectors;
@ -285,6 +286,14 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
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()) {
String type;
if (syncMessage.getRequest().get().isContactsRequest()) {
@ -643,8 +652,19 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
pointer.getPreview().isPresent() ? " (Preview is available: "
+ pointer.getPreview().get().length
+ " bytes)" : "");
writer.println("Voice note: {}", pointer.getVoiceNote() ? "yes" : "no");
writer.println("Borderless: {}", pointer.isBorderless() ? "yes" : "no");
final var flags = new ArrayList<String>();
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) {
writer.println("Dimensions: {}x{}", pointer.getWidth(), pointer.getHeight());
}

View file

@ -38,9 +38,10 @@ public class ListGroupsCommand implements LocalCommand {
final var groupInviteLink = group.getGroupInviteLink();
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.getTitle(),
group.getDescription(),
group.isMember(m.getSelfRecipientId()),
group.isBlocked(),
resolveMembers(m, group.getMembers()),
@ -81,6 +82,7 @@ public class ListGroupsCommand implements LocalCommand {
jsonGroups.add(new JsonGroup(group.getGroupId().toBase64(),
group.getTitle(),
group.getDescription(),
group.isMember(m.getSelfRecipientId()),
group.isBlocked(),
resolveMembers(m, group.getMembers()),
@ -103,6 +105,7 @@ public class ListGroupsCommand implements LocalCommand {
public String id;
public String name;
public String description;
public boolean isMember;
public boolean isBlocked;
@ -114,6 +117,7 @@ public class ListGroupsCommand implements LocalCommand {
public JsonGroup(
String id,
String name,
String description,
boolean isMember,
boolean isBlocked,
Set<String> members,
@ -123,6 +127,7 @@ public class ListGroupsCommand implements LocalCommand {
) {
this.id = id;
this.name = name;
this.description = description;
this.isMember = isMember;
this.isBlocked = isBlocked;

View file

@ -8,17 +8,26 @@ import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.commands.exceptions.CommandException;
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.groups.GroupId;
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.freedesktop.dbus.exceptions.DBusExecutionException;
import org.slf4j.Logger;
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.Base64;
import java.util.List;
public class UpdateGroupCommand implements DbusCommand {
public class UpdateGroupCommand implements DbusCommand, LocalCommand {
private final static Logger logger = LoggerFactory.getLogger(UpdateGroupCommand.class);
@ -26,10 +35,56 @@ public class UpdateGroupCommand implements DbusCommand {
public void attachToSubparser(final Subparser subparser) {
subparser.addArgument("-g", "--group").help("Specify the recipient group ID.");
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("-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
public void handleCommand(final Namespace ns, final Signal signal) throws CommandException {
final var writer = new PlainTextWriterImpl(System.out);

View file

@ -337,6 +337,7 @@ public class DbusSignalImpl implements Signal {
}
final var results = m.updateGroup(groupId == null ? null : GroupId.unknownVersion(groupId),
name,
null,
members,
avatar == null ? null : new File(avatar));
checkSendMessageResults(0, results.second());