mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Refactor receive api
This commit is contained in:
parent
b615a4b04d
commit
9075cc1a30
36 changed files with 1510 additions and 970 deletions
|
@ -1,42 +1,17 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
import org.asamk.signal.manager.groups.GroupUtils;
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2;
|
||||
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
record JsonGroupInfo(
|
||||
String groupId,
|
||||
String type,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) String name,
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) List<String> members
|
||||
) {
|
||||
record JsonGroupInfo(String groupId, String type) {
|
||||
|
||||
static JsonGroupInfo from(SignalServiceGroup groupInfo) {
|
||||
return new JsonGroupInfo(Base64.getEncoder().encodeToString(groupInfo.getGroupId()),
|
||||
groupInfo.getType().toString(),
|
||||
groupInfo.getName().orNull(),
|
||||
groupInfo.getMembers().isPresent() ? groupInfo.getMembers()
|
||||
.get()
|
||||
.stream()
|
||||
.map(Util::getLegacyIdentifier)
|
||||
.collect(Collectors.toList()) : null);
|
||||
}
|
||||
|
||||
static JsonGroupInfo from(SignalServiceGroupV2 groupInfo) {
|
||||
return new JsonGroupInfo(GroupUtils.getGroupIdV2(groupInfo.getMasterKey()).toBase64(),
|
||||
groupInfo.hasSignedGroupChange() ? "UPDATE" : "DELIVER",
|
||||
null,
|
||||
null);
|
||||
static JsonGroupInfo from(MessageEnvelope.Data.GroupContext groupContext) {
|
||||
return new JsonGroupInfo(groupContext.groupId().toBase64(),
|
||||
groupContext.isGroupUpdate() ? "UPDATE" : "DELIVER");
|
||||
}
|
||||
|
||||
static JsonGroupInfo from(byte[] groupId) {
|
||||
return new JsonGroupInfo(Base64.getEncoder().encodeToString(groupId), "DELIVER", null, null);
|
||||
return new JsonGroupInfo(Base64.getEncoder().encodeToString(groupId), "DELIVER");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue