1 package org
.asamk
.signal
.manager
.storage
.groups
;
3 import org
.asamk
.signal
.manager
.groups
.GroupIdV2
;
4 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
5 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientId
;
6 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientResolver
;
7 import org
.signal
.storageservice
.protos
.groups
.AccessControl
;
8 import org
.signal
.storageservice
.protos
.groups
.Member
;
9 import org
.signal
.storageservice
.protos
.groups
.local
.DecryptedGroup
;
10 import org
.signal
.storageservice
.protos
.groups
.local
.EnabledState
;
11 import org
.signal
.zkgroup
.groups
.GroupMasterKey
;
12 import org
.whispersystems
.signalservice
.api
.util
.UuidUtil
;
15 import java
.util
.stream
.Collectors
;
17 public class GroupInfoV2
extends GroupInfo
{
19 private final GroupIdV2 groupId
;
20 private final GroupMasterKey masterKey
;
22 private boolean blocked
;
23 private DecryptedGroup group
; // stored as a file with hexadecimal groupId as name
24 private RecipientResolver recipientResolver
;
26 public GroupInfoV2(final GroupIdV2 groupId
, final GroupMasterKey masterKey
) {
27 this.groupId
= groupId
;
28 this.masterKey
= masterKey
;
31 public GroupInfoV2(final GroupIdV2 groupId
, final GroupMasterKey masterKey
, final boolean blocked
) {
32 this.groupId
= groupId
;
33 this.masterKey
= masterKey
;
34 this.blocked
= blocked
;
38 public GroupIdV2
getGroupId() {
42 public GroupMasterKey
getMasterKey() {
46 public void setGroup(final DecryptedGroup group
, final RecipientResolver recipientResolver
) {
48 this.recipientResolver
= recipientResolver
;
51 public DecryptedGroup
getGroup() {
56 public String
getTitle() {
57 if (this.group
== null) {
60 return this.group
.getTitle();
64 public String
getDescription() {
65 if (this.group
== null) {
68 return this.group
.getDescription();
72 public GroupInviteLinkUrl
getGroupInviteLink() {
73 if (this.group
== null || this.group
.getInviteLinkPassword().isEmpty() || (
74 this.group
.getAccessControl().getAddFromInviteLink() != AccessControl
.AccessRequired
.ANY
75 && this.group
.getAccessControl().getAddFromInviteLink()
76 != AccessControl
.AccessRequired
.ADMINISTRATOR
81 return GroupInviteLinkUrl
.forGroup(masterKey
, group
);
85 public Set
<RecipientId
> getMembers() {
86 if (this.group
== null) {
89 return group
.getMembersList()
91 .map(m
-> UuidUtil
.parseOrThrow(m
.getUuid().toByteArray()))
92 .map(recipientResolver
::resolveRecipient
)
93 .collect(Collectors
.toSet());
97 public Set
<RecipientId
> getPendingMembers() {
98 if (this.group
== null) {
101 return group
.getPendingMembersList()
103 .map(m
-> UuidUtil
.parseOrThrow(m
.getUuid().toByteArray()))
104 .map(recipientResolver
::resolveRecipient
)
105 .collect(Collectors
.toSet());
109 public Set
<RecipientId
> getRequestingMembers() {
110 if (this.group
== null) {
113 return group
.getRequestingMembersList()
115 .map(m
-> UuidUtil
.parseOrThrow(m
.getUuid().toByteArray()))
116 .map(recipientResolver
::resolveRecipient
)
117 .collect(Collectors
.toSet());
121 public Set
<RecipientId
> getAdminMembers() {
122 if (this.group
== null) {
125 return group
.getMembersList()
127 .filter(m
-> m
.getRole() == Member
.Role
.ADMINISTRATOR
)
128 .map(m
-> UuidUtil
.parseOrThrow(m
.getUuid().toByteArray()))
129 .map(recipientResolver
::resolveRecipient
)
130 .collect(Collectors
.toSet());
134 public boolean isBlocked() {
139 public void setBlocked(final boolean blocked
) {
140 this.blocked
= blocked
;
144 public int getMessageExpirationTime() {
145 return this.group
!= null && this.group
.hasDisappearingMessagesTimer()
146 ?
this.group
.getDisappearingMessagesTimer().getDuration()
151 public boolean isAnnouncementGroup() {
152 return this.group
!= null && this.group
.getIsAnnouncementGroup() == EnabledState
.ENABLED
;