X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/4f2261e86f493a9c8954c02c52ddaa9a46490d20..591c0fe8a3744608575a6dcb1f6f4f9f818948d2:/src/main/java/org/asamk/signal/manager/GroupUtils.java diff --git a/src/main/java/org/asamk/signal/manager/GroupUtils.java b/src/main/java/org/asamk/signal/manager/GroupUtils.java new file mode 100644 index 00000000..f4398f94 --- /dev/null +++ b/src/main/java/org/asamk/signal/manager/GroupUtils.java @@ -0,0 +1,28 @@ +package org.asamk.signal.manager; + +import org.asamk.signal.storage.groups.GroupInfo; +import org.asamk.signal.storage.groups.GroupInfoV1; +import org.asamk.signal.storage.groups.GroupInfoV2; +import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage; +import org.whispersystems.signalservice.api.messages.SignalServiceGroup; +import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2; + +public class GroupUtils { + + public static void setGroupContext( + final SignalServiceDataMessage.Builder messageBuilder, final GroupInfo groupInfo + ) { + if (groupInfo instanceof GroupInfoV1) { + SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.DELIVER) + .withId(groupInfo.groupId) + .build(); + messageBuilder.asGroupMessage(group); + } else { + final GroupInfoV2 groupInfoV2 = (GroupInfoV2) groupInfo; + SignalServiceGroupV2 group = SignalServiceGroupV2.newBuilder(groupInfoV2.getMasterKey()) + .withRevision(groupInfoV2.getGroup() == null ? 0 : groupInfoV2.getGroup().getRevision()) + .build(); + messageBuilder.asGroupMessage(group); + } + } +}