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