mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Implement JsonRpc command for joinGroup
This commit is contained in:
parent
5d8d0dcad6
commit
7b809c6547
1 changed files with 16 additions and 6 deletions
|
@ -3,6 +3,7 @@ package org.asamk.signal.commands;
|
||||||
import net.sourceforge.argparse4j.inf.Namespace;
|
import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
import net.sourceforge.argparse4j.inf.Subparser;
|
import net.sourceforge.argparse4j.inf.Subparser;
|
||||||
|
|
||||||
|
import org.asamk.signal.JsonWriter;
|
||||||
import org.asamk.signal.OutputWriter;
|
import org.asamk.signal.OutputWriter;
|
||||||
import org.asamk.signal.PlainTextWriter;
|
import org.asamk.signal.PlainTextWriter;
|
||||||
import org.asamk.signal.commands.exceptions.CommandException;
|
import org.asamk.signal.commands.exceptions.CommandException;
|
||||||
|
@ -16,10 +17,11 @@ import org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException
|
||||||
import org.whispersystems.signalservice.internal.push.exceptions.GroupPatchNotAcceptedException;
|
import org.whispersystems.signalservice.internal.push.exceptions.GroupPatchNotAcceptedException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleSendMessageResults;
|
import static org.asamk.signal.util.ErrorUtils.handleSendMessageResults;
|
||||||
|
|
||||||
public class JoinGroupCommand implements LocalCommand {
|
public class JoinGroupCommand implements JsonRpcLocalCommand {
|
||||||
|
|
||||||
private final OutputWriter outputWriter;
|
private final OutputWriter outputWriter;
|
||||||
|
|
||||||
|
@ -49,14 +51,22 @@ public class JoinGroupCommand implements LocalCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final var writer = (PlainTextWriter) outputWriter;
|
|
||||||
|
|
||||||
final var results = m.joinGroup(linkUrl);
|
final var results = m.joinGroup(linkUrl);
|
||||||
var newGroupId = results.first();
|
var newGroupId = results.first();
|
||||||
if (!m.getGroup(newGroupId).isMember(m.getSelfRecipientId())) {
|
if (outputWriter instanceof JsonWriter) {
|
||||||
writer.println("Requested to join group \"{}\"", newGroupId.toBase64());
|
final var writer = (JsonWriter) outputWriter;
|
||||||
|
if (!m.getGroup(newGroupId).isMember(m.getSelfRecipientId())) {
|
||||||
|
writer.write(Map.of("groupId", newGroupId.toBase64(), "onlyRequested", true));
|
||||||
|
} else {
|
||||||
|
writer.write(Map.of("groupId", newGroupId.toBase64()));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
writer.println("Joined group \"{}\"", newGroupId.toBase64());
|
final var writer = (PlainTextWriter) outputWriter;
|
||||||
|
if (!m.getGroup(newGroupId).isMember(m.getSelfRecipientId())) {
|
||||||
|
writer.println("Requested to join group \"{}\"", newGroupId.toBase64());
|
||||||
|
} else {
|
||||||
|
writer.println("Joined group \"{}\"", newGroupId.toBase64());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
handleSendMessageResults(results.second());
|
handleSendMessageResults(results.second());
|
||||||
} catch (GroupPatchNotAcceptedException e) {
|
} catch (GroupPatchNotAcceptedException e) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue