]> nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/manager/HandleAction.java
Refactor to use GroupId class to wrap the byte array
[signal-cli] / src / main / java / org / asamk / signal / manager / HandleAction.java
1 package org.asamk.signal.manager;
2
3 import org.whispersystems.signalservice.api.push.SignalServiceAddress;
4
5 import java.util.Objects;
6
7 interface HandleAction {
8
9 void execute(Manager m) throws Throwable;
10 }
11
12 class SendReceiptAction implements HandleAction {
13
14 private final SignalServiceAddress address;
15 private final long timestamp;
16
17 public SendReceiptAction(final SignalServiceAddress address, final long timestamp) {
18 this.address = address;
19 this.timestamp = timestamp;
20 }
21
22 @Override
23 public void execute(Manager m) throws Throwable {
24 m.sendReceipt(address, timestamp);
25 }
26
27 @Override
28 public boolean equals(final Object o) {
29 if (this == o) return true;
30 if (o == null || getClass() != o.getClass()) return false;
31 final SendReceiptAction that = (SendReceiptAction) o;
32 return timestamp == that.timestamp && address.equals(that.address);
33 }
34
35 @Override
36 public int hashCode() {
37 return Objects.hash(address, timestamp);
38 }
39 }
40
41 class SendSyncContactsAction implements HandleAction {
42
43 private static final SendSyncContactsAction INSTANCE = new SendSyncContactsAction();
44
45 private SendSyncContactsAction() {
46 }
47
48 public static SendSyncContactsAction create() {
49 return INSTANCE;
50 }
51
52 @Override
53 public void execute(Manager m) throws Throwable {
54 m.sendContacts();
55 }
56 }
57
58 class SendSyncGroupsAction implements HandleAction {
59
60 private static final SendSyncGroupsAction INSTANCE = new SendSyncGroupsAction();
61
62 private SendSyncGroupsAction() {
63 }
64
65 public static SendSyncGroupsAction create() {
66 return INSTANCE;
67 }
68
69 @Override
70 public void execute(Manager m) throws Throwable {
71 m.sendGroups();
72 }
73 }
74
75 class SendSyncBlockedListAction implements HandleAction {
76
77 private static final SendSyncBlockedListAction INSTANCE = new SendSyncBlockedListAction();
78
79 private SendSyncBlockedListAction() {
80 }
81
82 public static SendSyncBlockedListAction create() {
83 return INSTANCE;
84 }
85
86 @Override
87 public void execute(Manager m) throws Throwable {
88 m.sendBlockedList();
89 }
90 }
91
92 class SendGroupInfoRequestAction implements HandleAction {
93
94 private final SignalServiceAddress address;
95 private final GroupIdV1 groupId;
96
97 public SendGroupInfoRequestAction(final SignalServiceAddress address, final GroupIdV1 groupId) {
98 this.address = address;
99 this.groupId = groupId;
100 }
101
102 @Override
103 public void execute(Manager m) throws Throwable {
104 m.sendGroupInfoRequest(groupId, address);
105 }
106
107 @Override
108 public boolean equals(final Object o) {
109 if (this == o) return true;
110 if (o == null || getClass() != o.getClass()) return false;
111
112 final SendGroupInfoRequestAction that = (SendGroupInfoRequestAction) o;
113
114 if (!address.equals(that.address)) return false;
115 return groupId.equals(that.groupId);
116 }
117
118 @Override
119 public int hashCode() {
120 int result = address.hashCode();
121 result = 31 * result + groupId.hashCode();
122 return result;
123 }
124 }
125
126 class SendGroupUpdateAction implements HandleAction {
127
128 private final SignalServiceAddress address;
129 private final GroupIdV1 groupId;
130
131 public SendGroupUpdateAction(final SignalServiceAddress address, final GroupIdV1 groupId) {
132 this.address = address;
133 this.groupId = groupId;
134 }
135
136 @Override
137 public void execute(Manager m) throws Throwable {
138 m.sendUpdateGroupMessage(groupId, address);
139 }
140
141 @Override
142 public boolean equals(final Object o) {
143 if (this == o) return true;
144 if (o == null || getClass() != o.getClass()) return false;
145
146 final SendGroupUpdateAction that = (SendGroupUpdateAction) o;
147
148 if (!address.equals(that.address)) return false;
149 return groupId.equals(that.groupId);
150 }
151
152 @Override
153 public int hashCode() {
154 int result = address.hashCode();
155 result = 31 * result + groupId.hashCode();
156 return result;
157 }
158 }