]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/HandleAction.java
Extend updateProfile command to set family name
[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.Objects;
8
9 interface HandleAction {
10
11 void execute(Manager m) throws Throwable;
12 }
13
14 class SendReceiptAction implements HandleAction {
15
16 private final SignalServiceAddress address;
17 private final long timestamp;
18
19 public SendReceiptAction(final SignalServiceAddress address, final long timestamp) {
20 this.address = address;
21 this.timestamp = timestamp;
22 }
23
24 @Override
25 public void execute(Manager m) throws Throwable {
26 m.sendReceipt(address, timestamp);
27 }
28
29 @Override
30 public boolean equals(final Object o) {
31 if (this == o) return true;
32 if (o == null || getClass() != o.getClass()) return false;
33 final var that = (SendReceiptAction) o;
34 return timestamp == that.timestamp && address.equals(that.address);
35 }
36
37 @Override
38 public int hashCode() {
39 return Objects.hash(address, timestamp);
40 }
41 }
42
43 class SendSyncContactsAction implements HandleAction {
44
45 private static final SendSyncContactsAction INSTANCE = new SendSyncContactsAction();
46
47 private SendSyncContactsAction() {
48 }
49
50 public static SendSyncContactsAction create() {
51 return INSTANCE;
52 }
53
54 @Override
55 public void execute(Manager m) throws Throwable {
56 m.sendContacts();
57 }
58 }
59
60 class SendSyncGroupsAction implements HandleAction {
61
62 private static final SendSyncGroupsAction INSTANCE = new SendSyncGroupsAction();
63
64 private SendSyncGroupsAction() {
65 }
66
67 public static SendSyncGroupsAction create() {
68 return INSTANCE;
69 }
70
71 @Override
72 public void execute(Manager m) throws Throwable {
73 m.sendGroups();
74 }
75 }
76
77 class SendSyncBlockedListAction implements HandleAction {
78
79 private static final SendSyncBlockedListAction INSTANCE = new SendSyncBlockedListAction();
80
81 private SendSyncBlockedListAction() {
82 }
83
84 public static SendSyncBlockedListAction create() {
85 return INSTANCE;
86 }
87
88 @Override
89 public void execute(Manager m) throws Throwable {
90 m.sendBlockedList();
91 }
92 }
93
94 class SendGroupInfoRequestAction implements HandleAction {
95
96 private final SignalServiceAddress address;
97 private final GroupIdV1 groupId;
98
99 public SendGroupInfoRequestAction(final SignalServiceAddress address, final GroupIdV1 groupId) {
100 this.address = address;
101 this.groupId = groupId;
102 }
103
104 @Override
105 public void execute(Manager m) throws Throwable {
106 m.sendGroupInfoRequest(groupId, address);
107 }
108
109 @Override
110 public boolean equals(final Object o) {
111 if (this == o) return true;
112 if (o == null || getClass() != o.getClass()) return false;
113
114 final var that = (SendGroupInfoRequestAction) o;
115
116 if (!address.equals(that.address)) return false;
117 return groupId.equals(that.groupId);
118 }
119
120 @Override
121 public int hashCode() {
122 var result = address.hashCode();
123 result = 31 * result + groupId.hashCode();
124 return result;
125 }
126 }
127
128 class SendGroupInfoAction implements HandleAction {
129
130 private final SignalServiceAddress address;
131 private final GroupIdV1 groupId;
132
133 public SendGroupInfoAction(final SignalServiceAddress address, final GroupIdV1 groupId) {
134 this.address = address;
135 this.groupId = groupId;
136 }
137
138 @Override
139 public void execute(Manager m) throws Throwable {
140 m.sendGroupInfoMessage(groupId, address);
141 }
142
143 @Override
144 public boolean equals(final Object o) {
145 if (this == o) return true;
146 if (o == null || getClass() != o.getClass()) return false;
147
148 final var that = (SendGroupInfoAction) o;
149
150 if (!address.equals(that.address)) return false;
151 return groupId.equals(that.groupId);
152 }
153
154 @Override
155 public int hashCode() {
156 var result = address.hashCode();
157 result = 31 * result + groupId.hashCode();
158 return result;
159 }
160 }
161
162 class RetrieveProfileAction implements HandleAction {
163
164 private final RecipientId recipientId;
165
166 public RetrieveProfileAction(final RecipientId recipientId) {
167 this.recipientId = recipientId;
168 }
169
170 @Override
171 public void execute(Manager m) throws Throwable {
172 m.getRecipientProfile(recipientId, true);
173 }
174
175 @Override
176 public boolean equals(final Object o) {
177 if (this == o) return true;
178 if (o == null || getClass() != o.getClass()) return false;
179
180 final RetrieveProfileAction that = (RetrieveProfileAction) o;
181
182 return recipientId.equals(that.recipientId);
183 }
184
185 @Override
186 public int hashCode() {
187 return recipientId.hashCode();
188 }
189 }