]> nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/manager/HandleAction.java
Implement accepting and declining group invitations
[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.Arrays;
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 byte[] groupId;
97
98 public SendGroupInfoRequestAction(final SignalServiceAddress address, final byte[] 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 final SendGroupInfoRequestAction that = (SendGroupInfoRequestAction) o;
113 return address.equals(that.address) && Arrays.equals(groupId, that.groupId);
114 }
115
116 @Override
117 public int hashCode() {
118 int result = Objects.hash(address);
119 result = 31 * result + Arrays.hashCode(groupId);
120 return result;
121 }
122 }
123
124 class SendGroupUpdateAction implements HandleAction {
125
126 private final SignalServiceAddress address;
127 private final byte[] groupId;
128
129 public SendGroupUpdateAction(final SignalServiceAddress address, final byte[] groupId) {
130 this.address = address;
131 this.groupId = groupId;
132 }
133
134 @Override
135 public void execute(Manager m) throws Throwable {
136 m.sendUpdateGroupMessage(groupId, address);
137 }
138
139 @Override
140 public boolean equals(final Object o) {
141 if (this == o) return true;
142 if (o == null || getClass() != o.getClass()) return false;
143 final SendGroupUpdateAction that = (SendGroupUpdateAction) o;
144 return address.equals(that.address) && Arrays.equals(groupId, that.groupId);
145 }
146
147 @Override
148 public int hashCode() {
149 int result = Objects.hash(address);
150 result = 31 * result + Arrays.hashCode(groupId);
151 return result;
152 }
153 }