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