mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Support sending and receiving group info requests
This commit is contained in:
parent
998ec5e7aa
commit
8bfef24ef7
2 changed files with 79 additions and 20 deletions
|
@ -18,7 +18,7 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.github.turasa:signal-service-java:2.4.0_unofficial_1'
|
compile 'com.github.turasa:signal-service-java:2.4.1_unofficial_1'
|
||||||
compile 'org.bouncycastle:bcprov-jdk15on:1.55'
|
compile 'org.bouncycastle:bcprov-jdk15on:1.55'
|
||||||
compile 'net.sourceforge.argparse4j:argparse4j:0.7.0'
|
compile 'net.sourceforge.argparse4j:argparse4j:0.7.0'
|
||||||
compile 'org.freedesktop.dbus:dbus-java:2.7.0'
|
compile 'org.freedesktop.dbus:dbus-java:2.7.0'
|
||||||
|
|
|
@ -663,28 +663,15 @@ class Manager implements Signal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SignalServiceGroup.Builder group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.UPDATE)
|
|
||||||
.withId(g.groupId)
|
|
||||||
.withName(g.name)
|
|
||||||
.withMembers(new ArrayList<>(g.members));
|
|
||||||
|
|
||||||
File aFile = getGroupAvatarFile(g.groupId);
|
|
||||||
if (avatarFile != null) {
|
if (avatarFile != null) {
|
||||||
createPrivateDirectories(avatarsPath);
|
createPrivateDirectories(avatarsPath);
|
||||||
|
File aFile = getGroupAvatarFile(g.groupId);
|
||||||
Files.copy(Paths.get(avatarFile), aFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(Paths.get(avatarFile), aFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
}
|
}
|
||||||
if (aFile.exists()) {
|
|
||||||
try {
|
|
||||||
group.withAvatar(createAttachment(aFile));
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new AttachmentInvalidException(avatarFile, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
groupStore.updateGroup(g);
|
groupStore.updateGroup(g);
|
||||||
|
|
||||||
SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
|
SignalServiceDataMessage.Builder messageBuilder = getGroupUpdateMessageBuilder(g);
|
||||||
.asGroupMessage(group.build());
|
|
||||||
|
|
||||||
// Don't send group message to ourself
|
// Don't send group message to ourself
|
||||||
final List<String> membersSend = new ArrayList<>(g.members);
|
final List<String> membersSend = new ArrayList<>(g.members);
|
||||||
|
@ -693,6 +680,60 @@ class Manager implements Signal {
|
||||||
return g.groupId;
|
return g.groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendUpdateGroupMessage(byte[] groupId, String recipient) throws IOException, EncapsulatedExceptions {
|
||||||
|
if (groupId == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
GroupInfo g = getGroupForSending(groupId);
|
||||||
|
|
||||||
|
if (!g.members.contains(recipient)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SignalServiceDataMessage.Builder messageBuilder = getGroupUpdateMessageBuilder(g);
|
||||||
|
|
||||||
|
// Send group message only to the recipient who requested it
|
||||||
|
final List<String> membersSend = new ArrayList<>();
|
||||||
|
membersSend.add(recipient);
|
||||||
|
sendMessage(messageBuilder, membersSend);
|
||||||
|
}
|
||||||
|
|
||||||
|
private SignalServiceDataMessage.Builder getGroupUpdateMessageBuilder(GroupInfo g) {
|
||||||
|
SignalServiceGroup.Builder group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.UPDATE)
|
||||||
|
.withId(g.groupId)
|
||||||
|
.withName(g.name)
|
||||||
|
.withMembers(new ArrayList<>(g.members));
|
||||||
|
|
||||||
|
File aFile = getGroupAvatarFile(g.groupId);
|
||||||
|
if (aFile.exists()) {
|
||||||
|
try {
|
||||||
|
group.withAvatar(createAttachment(aFile));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new AttachmentInvalidException(aFile.toString(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SignalServiceDataMessage.newBuilder()
|
||||||
|
.asGroupMessage(group.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendGroupInfoRequest(byte[] groupId, String recipient) throws IOException, EncapsulatedExceptions {
|
||||||
|
if (groupId == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SignalServiceGroup.Builder group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.REQUEST_INFO)
|
||||||
|
.withId(groupId);
|
||||||
|
|
||||||
|
SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
|
||||||
|
.asGroupMessage(group.build());
|
||||||
|
|
||||||
|
// Send group info request message to the recipient who sent us a message with this groupId
|
||||||
|
final List<String> membersSend = new ArrayList<>();
|
||||||
|
membersSend.add(recipient);
|
||||||
|
sendMessage(messageBuilder, membersSend);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(String message, List<String> attachments, String recipient)
|
public void sendMessage(String message, List<String> attachments, String recipient)
|
||||||
throws EncapsulatedExceptions, AttachmentInvalidException, IOException {
|
throws EncapsulatedExceptions, AttachmentInvalidException, IOException {
|
||||||
|
@ -847,10 +888,9 @@ class Manager implements Signal {
|
||||||
if (message.getGroupInfo().isPresent()) {
|
if (message.getGroupInfo().isPresent()) {
|
||||||
SignalServiceGroup groupInfo = message.getGroupInfo().get();
|
SignalServiceGroup groupInfo = message.getGroupInfo().get();
|
||||||
threadId = Base64.encodeBytes(groupInfo.getGroupId());
|
threadId = Base64.encodeBytes(groupInfo.getGroupId());
|
||||||
|
GroupInfo group = groupStore.getGroup(groupInfo.getGroupId());
|
||||||
switch (groupInfo.getType()) {
|
switch (groupInfo.getType()) {
|
||||||
case UPDATE:
|
case UPDATE:
|
||||||
GroupInfo group;
|
|
||||||
group = groupStore.getGroup(groupInfo.getGroupId());
|
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
group = new GroupInfo(groupInfo.getGroupId());
|
group = new GroupInfo(groupInfo.getGroupId());
|
||||||
}
|
}
|
||||||
|
@ -877,14 +917,33 @@ class Manager implements Signal {
|
||||||
groupStore.updateGroup(group);
|
groupStore.updateGroup(group);
|
||||||
break;
|
break;
|
||||||
case DELIVER:
|
case DELIVER:
|
||||||
|
if (group == null) {
|
||||||
|
try {
|
||||||
|
sendGroupInfoRequest(groupInfo.getGroupId(), source);
|
||||||
|
} catch (IOException | EncapsulatedExceptions e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case QUIT:
|
case QUIT:
|
||||||
group = groupStore.getGroup(groupInfo.getGroupId());
|
if (group == null) {
|
||||||
if (group != null) {
|
try {
|
||||||
|
sendGroupInfoRequest(groupInfo.getGroupId(), source);
|
||||||
|
} catch (IOException | EncapsulatedExceptions e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
group.members.remove(source);
|
group.members.remove(source);
|
||||||
groupStore.updateGroup(group);
|
groupStore.updateGroup(group);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case REQUEST_INFO:
|
||||||
|
try {
|
||||||
|
sendUpdateGroupMessage(groupInfo.getGroupId(), source);
|
||||||
|
} catch (IOException | EncapsulatedExceptions e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isSync) {
|
if (isSync) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue