]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/HandleAction.java
Extract AttachmentHelper and SyncHelper
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / HandleAction.java
1 package org.asamk.signal.manager;
2
3 import org.asamk.signal.manager.groups.GroupIdV1;
4 import org.asamk.signal.manager.storage.recipients.RecipientId;
5 import org.whispersystems.signalservice.api.push.SignalServiceAddress;
6
7 import java.util.List;
8 import java.util.Objects;
9
10 interface HandleAction {
11
12 void execute(Manager m) throws Throwable;
13 }
14
15 class SendReceiptAction implements HandleAction {
16
17 private final SignalServiceAddress address;
18 private final long timestamp;
19
20 public SendReceiptAction(final SignalServiceAddress address, final long timestamp) {
21 this.address = address;
22 this.timestamp = timestamp;
23 }
24
25 @Override
26 public void execute(Manager m) throws Throwable {
27 m.sendDeliveryReceipt(address, List.of(timestamp));
28 }
29
30 @Override
31 public boolean equals(final Object o) {
32 if (this == o) return true;
33 if (o == null || getClass() != o.getClass()) return false;
34 final var that = (SendReceiptAction) o;
35 return timestamp == that.timestamp && address.equals(that.address);
36 }
37
38 @Override
39 public int hashCode() {
40 return Objects.hash(address, timestamp);
41 }
42 }
43
44 class SendSyncContactsAction implements HandleAction {
45
46 private static final SendSyncContactsAction INSTANCE = new SendSyncContactsAction();
47
48 private SendSyncContactsAction() {
49 }
50
51 public static SendSyncContactsAction create() {
52 return INSTANCE;
53 }
54
55 @Override
56 public void execute(Manager m) throws Throwable {
57 m.sendContacts();
58 }
59 }
60
61 class SendSyncGroupsAction implements HandleAction {
62
63 private static final SendSyncGroupsAction INSTANCE = new SendSyncGroupsAction();
64
65 private SendSyncGroupsAction() {
66 }
67
68 public static SendSyncGroupsAction create() {
69 return INSTANCE;
70 }
71
72 @Override
73 public void execute(Manager m) throws Throwable {
74 m.sendGroups();
75 }
76 }
77
78 class SendSyncBlockedListAction implements HandleAction {
79
80 private static final SendSyncBlockedListAction INSTANCE = new SendSyncBlockedListAction();
81
82 private SendSyncBlockedListAction() {
83 }
84
85 public static SendSyncBlockedListAction create() {
86 return INSTANCE;
87 }
88
89 @Override
90 public void execute(Manager m) throws Throwable {
91 m.sendBlockedList();
92 }
93 }
94
95 class SendGroupInfoRequestAction implements HandleAction {
96
97 private final SignalServiceAddress address;
98 private final GroupIdV1 groupId;
99
100 public SendGroupInfoRequestAction(final SignalServiceAddress address, final GroupIdV1 groupId) {
101 this.address = address;
102 this.groupId = groupId;
103 }
104
105 @Override
106 public void execute(Manager m) throws Throwable {
107 m.sendGroupInfoRequest(groupId, address);
108 }
109
110 @Override
111 public boolean equals(final Object o) {
112 if (this == o) return true;
113 if (o == null || getClass() != o.getClass()) return false;
114
115 final var that = (SendGroupInfoRequestAction) o;
116
117 if (!address.equals(that.address)) return false;
118 return groupId.equals(that.groupId);
119 }
120
121 @Override
122 public int hashCode() {
123 var result = address.hashCode();
124 result = 31 * result + groupId.hashCode();
125 return result;
126 }
127 }
128
129 class SendGroupInfoAction implements HandleAction {
130
131 private final SignalServiceAddress address;
132 private final GroupIdV1 groupId;
133
134 public SendGroupInfoAction(final SignalServiceAddress address, final GroupIdV1 groupId) {
135 this.address = address;
136 this.groupId = groupId;
137 }
138
139 @Override
140 public void execute(Manager m) throws Throwable {
141 m.sendGroupInfoMessage(groupId, address);
142 }
143
144 @Override
145 public boolean equals(final Object o) {
146 if (this == o) return true;
147 if (o == null || getClass() != o.getClass()) return false;
148
149 final var that = (SendGroupInfoAction) o;
150
151 if (!address.equals(that.address)) return false;
152 return groupId.equals(that.groupId);
153 }
154
155 @Override
156 public int hashCode() {
157 var result = address.hashCode();
158 result = 31 * result + groupId.hashCode();
159 return result;
160 }
161 }
162
163 class RetrieveProfileAction implements HandleAction {
164
165 private final RecipientId recipientId;
166
167 public RetrieveProfileAction(final RecipientId recipientId) {
168 this.recipientId = recipientId;
169 }
170
171 @Override
172 public void execute(Manager m) throws Throwable {
173 m.refreshRecipientProfile(recipientId);
174 }
175
176 @Override
177 public boolean equals(final Object o) {
178 if (this == o) return true;
179 if (o == null || getClass() != o.getClass()) return false;
180
181 final RetrieveProfileAction that = (RetrieveProfileAction) o;
182
183 return recipientId.equals(that.recipientId);
184 }
185
186 @Override
187 public int hashCode() {
188 return recipientId.hashCode();
189 }
190 }
191
192 class RenewSessionAction implements HandleAction {
193
194 private final RecipientId recipientId;
195
196 public RenewSessionAction(final RecipientId recipientId) {
197 this.recipientId = recipientId;
198 }
199
200 @Override
201 public void execute(Manager m) throws Throwable {
202 m.renewSession(recipientId);
203 }
204
205 @Override
206 public boolean equals(final Object o) {
207 if (this == o) return true;
208 if (o == null || getClass() != o.getClass()) return false;
209
210 final RenewSessionAction that = (RenewSessionAction) o;
211
212 return recipientId.equals(that.recipientId);
213 }
214
215 @Override
216 public int hashCode() {
217 return recipientId.hashCode();
218 }
219 }