mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-30 02:50:39 +00:00
Refactor to use GroupId class to wrap the byte array
Helps distinguish between group v1 and v2 ids
This commit is contained in:
parent
67f62947c6
commit
9942d967a4
31 changed files with 358 additions and 228 deletions
|
@ -3,9 +3,10 @@ package org.asamk.signal.commands;
|
|||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.signal.manager.GroupId;
|
||||
import org.asamk.signal.manager.GroupIdFormatException;
|
||||
import org.asamk.signal.manager.GroupNotFoundException;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.util.GroupIdFormatException;
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||
|
||||
|
@ -36,7 +37,7 @@ public class BlockCommand implements LocalCommand {
|
|||
if (ns.<String>getList("group") != null) {
|
||||
for (String groupIdString : ns.<String>getList("group")) {
|
||||
try {
|
||||
byte[] groupId = Util.decodeGroupId(groupIdString);
|
||||
GroupId groupId = Util.decodeGroupId(groupIdString);
|
||||
m.setGroupBlocked(groupId, true);
|
||||
} catch (GroupIdFormatException | GroupNotFoundException e) {
|
||||
System.err.println(e.getMessage());
|
||||
|
|
|
@ -4,6 +4,7 @@ import net.sourceforge.argparse4j.inf.Namespace;
|
|||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.signal.manager.GroupId;
|
||||
import org.asamk.signal.manager.GroupInviteLinkUrl;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
|
@ -11,7 +12,6 @@ import org.whispersystems.libsignal.util.Pair;
|
|||
import org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException;
|
||||
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||
import org.whispersystems.signalservice.internal.push.exceptions.GroupPatchNotAcceptedException;
|
||||
import org.whispersystems.util.Base64;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
@ -52,12 +52,12 @@ public class JoinGroupCommand implements LocalCommand {
|
|||
}
|
||||
|
||||
try {
|
||||
final Pair<byte[], List<SendMessageResult>> results = m.joinGroup(linkUrl);
|
||||
byte[] newGroupId = results.first();
|
||||
final Pair<GroupId, List<SendMessageResult>> results = m.joinGroup(linkUrl);
|
||||
GroupId newGroupId = results.first();
|
||||
if (!m.getGroup(newGroupId).isMember(m.getSelfAddress())) {
|
||||
System.out.println("Requested to join group \"" + Base64.encodeBytes(newGroupId) + "\"");
|
||||
System.out.println("Requested to join group \"" + newGroupId.toBase64() + "\"");
|
||||
} else {
|
||||
System.out.println("Joined group \"" + Base64.encodeBytes(newGroupId) + "\"");
|
||||
System.out.println("Joined group \"" + newGroupId.toBase64() + "\"");
|
||||
}
|
||||
return handleTimestampAndSendMessageResults(0, results.second());
|
||||
} catch (AssertionError e) {
|
||||
|
|
|
@ -8,7 +8,6 @@ import org.asamk.signal.manager.GroupInviteLinkUrl;
|
|||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.storage.groups.GroupInfo;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.util.Base64;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -40,7 +39,7 @@ public class ListGroupsCommand implements LocalCommand {
|
|||
|
||||
System.out.println(String.format(
|
||||
"Id: %s Name: %s Active: %s Blocked: %b Members: %s Pending members: %s Requesting members: %s Link: %s",
|
||||
Base64.encodeBytes(group.groupId),
|
||||
group.getGroupId().toBase64(),
|
||||
group.getTitle(),
|
||||
group.isMember(m.getSelfAddress()),
|
||||
group.isBlocked(),
|
||||
|
@ -50,7 +49,7 @@ public class ListGroupsCommand implements LocalCommand {
|
|||
groupInviteLink == null ? '-' : groupInviteLink.getUrl()));
|
||||
} else {
|
||||
System.out.println(String.format("Id: %s Name: %s Active: %s Blocked: %b",
|
||||
Base64.encodeBytes(group.groupId),
|
||||
group.getGroupId().toBase64(),
|
||||
group.getTitle(),
|
||||
group.isMember(m.getSelfAddress()),
|
||||
group.isBlocked()));
|
||||
|
|
|
@ -3,10 +3,11 @@ package org.asamk.signal.commands;
|
|||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.signal.manager.GroupId;
|
||||
import org.asamk.signal.manager.GroupIdFormatException;
|
||||
import org.asamk.signal.manager.GroupNotFoundException;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.NotAGroupMemberException;
|
||||
import org.asamk.signal.util.GroupIdFormatException;
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.whispersystems.libsignal.util.Pair;
|
||||
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||
|
@ -36,7 +37,7 @@ public class QuitGroupCommand implements LocalCommand {
|
|||
}
|
||||
|
||||
try {
|
||||
final byte[] groupId = Util.decodeGroupId(ns.getString("group"));
|
||||
final GroupId groupId = Util.decodeGroupId(ns.getString("group"));
|
||||
final Pair<Long, List<SendMessageResult>> results = m.sendQuitGroupMessage(groupId);
|
||||
return handleTimestampAndSendMessageResults(results.first(), results.second());
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -5,7 +5,7 @@ import net.sourceforge.argparse4j.inf.Namespace;
|
|||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.signal.util.GroupIdFormatException;
|
||||
import org.asamk.signal.manager.GroupIdFormatException;
|
||||
import org.asamk.signal.util.IOUtils;
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
|
@ -79,7 +79,7 @@ public class SendCommand implements DbusCommand {
|
|||
if (ns.getString("group") != null) {
|
||||
byte[] groupId;
|
||||
try {
|
||||
groupId = Util.decodeGroupId(ns.getString("group"));
|
||||
groupId = Util.decodeGroupId(ns.getString("group")).serialize();
|
||||
} catch (GroupIdFormatException e) {
|
||||
handleGroupIdFormatException(e);
|
||||
return 1;
|
||||
|
|
|
@ -4,10 +4,11 @@ import net.sourceforge.argparse4j.impl.Arguments;
|
|||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.signal.manager.GroupId;
|
||||
import org.asamk.signal.manager.GroupIdFormatException;
|
||||
import org.asamk.signal.manager.GroupNotFoundException;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.NotAGroupMemberException;
|
||||
import org.asamk.signal.util.GroupIdFormatException;
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.whispersystems.libsignal.util.Pair;
|
||||
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||
|
@ -65,7 +66,7 @@ public class SendReactionCommand implements LocalCommand {
|
|||
try {
|
||||
final Pair<Long, List<SendMessageResult>> results;
|
||||
if (ns.getString("group") != null) {
|
||||
byte[] groupId = Util.decodeGroupId(ns.getString("group"));
|
||||
GroupId groupId = Util.decodeGroupId(ns.getString("group"));
|
||||
results = m.sendGroupMessageReaction(emoji, isRemove, targetAuthor, targetTimestamp, groupId);
|
||||
} else {
|
||||
results = m.sendMessageReaction(emoji,
|
||||
|
|
|
@ -3,9 +3,10 @@ package org.asamk.signal.commands;
|
|||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.signal.manager.GroupId;
|
||||
import org.asamk.signal.manager.GroupIdFormatException;
|
||||
import org.asamk.signal.manager.GroupNotFoundException;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.util.GroupIdFormatException;
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||
|
||||
|
@ -36,7 +37,7 @@ public class UnblockCommand implements LocalCommand {
|
|||
if (ns.<String>getList("group") != null) {
|
||||
for (String groupIdString : ns.<String>getList("group")) {
|
||||
try {
|
||||
byte[] groupId = Util.decodeGroupId(groupIdString);
|
||||
GroupId groupId = Util.decodeGroupId(groupIdString);
|
||||
m.setGroupBlocked(groupId, false);
|
||||
} catch (GroupIdFormatException | GroupNotFoundException e) {
|
||||
System.err.println(e.getMessage());
|
||||
|
|
|
@ -4,7 +4,7 @@ import net.sourceforge.argparse4j.inf.Namespace;
|
|||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.signal.util.GroupIdFormatException;
|
||||
import org.asamk.signal.manager.GroupIdFormatException;
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
import org.whispersystems.util.Base64;
|
||||
|
@ -35,7 +35,7 @@ public class UpdateGroupCommand implements DbusCommand {
|
|||
byte[] groupId = null;
|
||||
if (ns.getString("group") != null) {
|
||||
try {
|
||||
groupId = Util.decodeGroupId(ns.getString("group"));
|
||||
groupId = Util.decodeGroupId(ns.getString("group")).serialize();
|
||||
} catch (GroupIdFormatException e) {
|
||||
handleGroupIdFormatException(e);
|
||||
return 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue