]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/api/Recipient.java
Store profile phone number sharing mode and discoverable state
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / api / Recipient.java
1 package org.asamk.signal.manager.api;
2
3 import org.asamk.signal.manager.storage.recipients.RecipientId;
4 import org.signal.libsignal.zkgroup.profiles.ExpiringProfileKeyCredential;
5 import org.signal.libsignal.zkgroup.profiles.ProfileKey;
6
7 import java.util.Objects;
8
9 public class Recipient {
10
11 private final RecipientId recipientId;
12
13 private final RecipientAddress address;
14
15 private final Contact contact;
16
17 private final ProfileKey profileKey;
18
19 private final ExpiringProfileKeyCredential expiringProfileKeyCredential;
20
21 private final Profile profile;
22
23 private final Boolean discoverable;
24
25 public Recipient(
26 final RecipientId recipientId,
27 final RecipientAddress address,
28 final Contact contact,
29 final ProfileKey profileKey,
30 final ExpiringProfileKeyCredential expiringProfileKeyCredential,
31 final Profile profile,
32 final Boolean discoverable
33 ) {
34 this.recipientId = recipientId;
35 this.address = address;
36 this.contact = contact;
37 this.profileKey = profileKey;
38 this.expiringProfileKeyCredential = expiringProfileKeyCredential;
39 this.profile = profile;
40 this.discoverable = discoverable;
41 }
42
43 private Recipient(final Builder builder) {
44 recipientId = builder.recipientId;
45 address = builder.address;
46 contact = builder.contact;
47 profileKey = builder.profileKey;
48 expiringProfileKeyCredential = builder.expiringProfileKeyCredential;
49 profile = builder.profile;
50 discoverable = builder.discoverable;
51 }
52
53 public static Builder newBuilder() {
54 return new Builder();
55 }
56
57 public static Builder newBuilder(final Recipient copy) {
58 Builder builder = new Builder();
59 builder.recipientId = copy.getRecipientId();
60 builder.address = copy.getAddress();
61 builder.contact = copy.getContact();
62 builder.profileKey = copy.getProfileKey();
63 builder.expiringProfileKeyCredential = copy.getExpiringProfileKeyCredential();
64 builder.profile = copy.getProfile();
65 return builder;
66 }
67
68 public RecipientId getRecipientId() {
69 return recipientId;
70 }
71
72 public RecipientAddress getAddress() {
73 return address;
74 }
75
76 public Contact getContact() {
77 return contact;
78 }
79
80 public ProfileKey getProfileKey() {
81 return profileKey;
82 }
83
84 public ExpiringProfileKeyCredential getExpiringProfileKeyCredential() {
85 return expiringProfileKeyCredential;
86 }
87
88 public Profile getProfile() {
89 return profile;
90 }
91
92 public Boolean getDiscoverable() {
93 return discoverable;
94 }
95
96 @Override
97 public boolean equals(final Object o) {
98 if (this == o) return true;
99 if (o == null || getClass() != o.getClass()) return false;
100 final Recipient recipient = (Recipient) o;
101 return Objects.equals(recipientId, recipient.recipientId)
102 && Objects.equals(address, recipient.address)
103 && Objects.equals(contact, recipient.contact)
104 && Objects.equals(profileKey, recipient.profileKey)
105 && Objects.equals(expiringProfileKeyCredential, recipient.expiringProfileKeyCredential)
106 && Objects.equals(profile, recipient.profile);
107 }
108
109 @Override
110 public int hashCode() {
111 return Objects.hash(recipientId, address, contact, profileKey, expiringProfileKeyCredential, profile);
112 }
113
114 public static final class Builder {
115
116 private RecipientId recipientId;
117 private RecipientAddress address;
118 private Contact contact;
119 private ProfileKey profileKey;
120 private ExpiringProfileKeyCredential expiringProfileKeyCredential;
121 private Profile profile;
122 private Boolean discoverable;
123
124 private Builder() {
125 }
126
127 public Builder withRecipientId(final RecipientId val) {
128 recipientId = val;
129 return this;
130 }
131
132 public Builder withAddress(final RecipientAddress val) {
133 address = val;
134 return this;
135 }
136
137 public Builder withContact(final Contact val) {
138 contact = val;
139 return this;
140 }
141
142 public Builder withProfileKey(final ProfileKey val) {
143 profileKey = val;
144 return this;
145 }
146
147 public Builder withExpiringProfileKeyCredential(final ExpiringProfileKeyCredential val) {
148 expiringProfileKeyCredential = val;
149 return this;
150 }
151
152 public Builder withProfile(final Profile val) {
153 profile = val;
154 return this;
155 }
156
157 public Builder withDiscoverable(final Boolean val) {
158 discoverable = val;
159 return this;
160 }
161
162 public Recipient build() {
163 return new Recipient(this);
164 }
165 }
166 }