Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
dependencies ▾

Modern-Apps.git / communicate-dev / src / main / java / com / vayunmathur / communicate / data / signal / SignalEvent.kt

SignalEvent.kt308 lines · 10.3 KiBRaw
1package com.vayunmathur.communicate.data.signal
2
3/**
4 * communicate-native event surface for the Signal primary client.
5 * Mirrors [com.vayunmathur.communicate.data.whatsapp.WhatsAppEvent] for Signal.
6 */
7sealed interface SignalEvent {
8 val source: SignalSource
9
10 /** Transport/login lifecycle change. */
11 data class StateChanged(
12 override val source: SignalSource = SignalSource.SIGNAL,
13 val state: SignalState,
14 val detail: String? = null,
15 ) : SignalEvent
16
17 /** A conversation-list row changed: latest preview, unread count and peer metadata. */
18 data class ConversationUpdate(
19 override val source: SignalSource = SignalSource.SIGNAL,
20 val conversationId: String,
21 val peerName: String?,
22 val peerPhone: String?,
23 val avatarUrl: String?,
24 val lastPreview: String?,
25 val lastTimestamp: Long,
26 val unreadCount: Int,
27 val isGroup: Boolean = false,
28 val participantCount: Int = 0,
29 val conversationType: String? = null,
30 val outgoingId: String? = null,
31 val serviceData: String? = null,
32 val isMessageRequest: Boolean = false,
33 ) : SignalEvent
34
35 /** A message row changed (new, edited or status-updated) in a conversation. */
36 data class MessageUpdate(
37 override val source: SignalSource = SignalSource.SIGNAL,
38 val conversationId: String,
39 val messageId: String,
40 val body: String,
41 val outgoing: Boolean,
42 val timestamp: Long,
43 val senderName: String?,
44 val senderId: String? = null,
45 val reactionsJson: String? = null,
46 val mediaData: ByteArray? = null,
47 val mediaMime: String? = null,
48 val mediaName: String? = null,
49 val statusType: String? = null,
50 val serviceData: String? = null,
51 val attachments: List<SignalAttachment> = emptyList(),
52 ) : SignalEvent
53
54 /** Inbound message. */
55 data class IncomingMessage(
56 override val source: SignalSource = SignalSource.SIGNAL,
57 val conversationId: String,
58 val messageId: String,
59 val body: String,
60 val peerName: String?,
61 val peerPhone: String?,
62 val timestamp: Long,
63 val senderName: String? = null,
64 val senderId: String? = null,
65 val attachments: List<SignalAttachment> = emptyList(),
66 val serviceData: String? = null,
67 val pollQuestion: String? = null,
68 val pollOptions: List<String> = emptyList(),
69 ) : SignalEvent
70
71 /** Message revoked/deleted. */
72 data class MessageDeleted(
73 override val source: SignalSource = SignalSource.SIGNAL,
74 val messageId: String,
75 val conversationId: String? = null,
76 val timestamp: Long = 0L,
77 ) : SignalEvent
78
79 /** A message was edited; the row now shows the replacement body. */
80 data class MessageEdited(
81 override val source: SignalSource = SignalSource.SIGNAL,
82 val conversationId: String? = null,
83 val messageId: String,
84 val newBody: String,
85 val timestamp: Long = 0L,
86 ) : SignalEvent
87
88 /** A delivery or read receipt for one of our sent messages. */
89 data class ReadReceipt(
90 override val source: SignalSource = SignalSource.SIGNAL,
91 val conversationId: String,
92 val messageId: String? = null,
93 val senderId: String? = null,
94 val timestampMs: Long = 0L,
95 val timestamp: Long = 0L,
96 val isDelivery: Boolean = false,
97 ) : SignalEvent
98
99 /** A conversation was deleted. */
100 data class ConversationDeleted(
101 override val source: SignalSource = SignalSource.SIGNAL,
102 val conversationId: String,
103 ) : SignalEvent
104
105 /** Typing indicator. */
106 data class TypingIndicator(
107 override val source: SignalSource = SignalSource.SIGNAL,
108 val conversationId: String,
109 val senderId: String,
110 val isTyping: Boolean,
111 ) : SignalEvent
112
113 /** An emoji reaction was added to a message. */
114 data class ReactionReceived(
115 override val source: SignalSource = SignalSource.SIGNAL,
116 val conversationId: String,
117 val messageId: String,
118 val senderId: String,
119 val emoji: String,
120 ) : SignalEvent
121
122 /** An emoji reaction was removed from a message. */
123 data class ReactionRemoved(
124 override val source: SignalSource = SignalSource.SIGNAL,
125 val conversationId: String,
126 val messageId: String,
127 val senderId: String,
128 ) : SignalEvent
129
130 /** A vote was cast on a poll message. */
131 data class PollVote(
132 override val source: SignalSource = SignalSource.SIGNAL,
133 val conversationId: String,
134 val pollMessageId: String,
135 val voterId: String,
136 val optionNames: List<String>,
137 ) : SignalEvent
138
139 /** A conversation (group) was renamed. */
140 data class ConversationNameChanged(
141 override val source: SignalSource = SignalSource.SIGNAL,
142 val conversationId: String,
143 val newName: String,
144 ) : SignalEvent
145
146 /** A conversation avatar changed. */
147 data class ConversationAvatarChanged(
148 override val source: SignalSource = SignalSource.SIGNAL,
149 val conversationId: String,
150 val avatarUrl: String?,
151 ) : SignalEvent
152
153 /** A participant joined a group conversation. */
154 data class ParticipantAdded(
155 override val source: SignalSource = SignalSource.SIGNAL,
156 val conversationId: String,
157 val participantId: String,
158 ) : SignalEvent
159
160 /** A participant left or was removed from a group conversation. */
161 data class ParticipantRemoved(
162 override val source: SignalSource = SignalSource.SIGNAL,
163 val conversationId: String,
164 val participantId: String,
165 ) : SignalEvent
166
167 /** A conversation mute setting changed; muteExpireTimeMs is when the mute lapses. */
168 data class MuteSettingChanged(
169 override val source: SignalSource = SignalSource.SIGNAL,
170 val conversationId: String,
171 val muteExpireTimeMs: Long,
172 ) : SignalEvent
173
174 /** A message request arrived from an unknown sender. */
175 data class MessageRequestReceived(
176 override val source: SignalSource = SignalSource.SIGNAL,
177 val conversationId: String,
178 ) : SignalEvent
179
180 /** Sending a message failed. */
181 data class SendFailed(
182 override val source: SignalSource = SignalSource.SIGNAL,
183 val conversationId: String,
184 val messageId: String? = null,
185 val tmpId: String? = null,
186 val errorMessage: String,
187 ) : SignalEvent
188
189 /** An inbound message could not be decrypted (session or identity problem). */
190 data class DecryptionError(
191 override val source: SignalSource = SignalSource.SIGNAL,
192 val conversationId: String,
193 val senderAci: String,
194 val senderDeviceId: Int,
195 val timestamp: Long,
196 val errorMessage: String? = null,
197 ) : SignalEvent
198
199 /**
200 * A peer's identity key no longer matches the one we recorded. Either they reinstalled or changed
201 * devices, or someone is substituting keys — the two are indistinguishable without the user
202 * comparing safety numbers out of band, so this must be surfaced rather than absorbed.
203 */
204 data class IdentityKeyChanged(
205 override val source: SignalSource = SignalSource.SIGNAL,
206 val conversationId: String,
207 val peerAci: String,
208 /** Hex of the identity key now being presented, for a safety-number comparison. */
209 val newIdentityKeyHex: String,
210 val timestamp: Long,
211 ) : SignalEvent
212
213 /** The primary line was logged out server-side. */
214 data class SourceLoggedOut(
215 override val source: SignalSource = SignalSource.SIGNAL,
216 val reason: String? = null,
217 ) : SignalEvent
218
219 /** Presence/last-seen update for a peer. */
220 data class PresenceUpdate(
221 override val source: SignalSource = SignalSource.SIGNAL,
222 val conversationId: String,
223 val isOnline: Boolean,
224 val lastSeen: Long = 0L,
225 ) : SignalEvent
226
227 /** A batch of history from the server's initial sync. */
228 data class HistorySync(
229 override val source: SignalSource = SignalSource.SIGNAL,
230 val conversations: List<SignalHistoryConversation>,
231 ) : SignalEvent
232
233 // ---- Calling ----
234
235 /** An inbound call offer arrived (ringing). */
236 data class CallOffer(
237 override val source: SignalSource = SignalSource.SIGNAL,
238 val callId: String,
239 val from: String,
240 val callCreator: String,
241 val isVideo: Boolean,
242 val peerName: String? = null,
243 val timestamp: Long = System.currentTimeMillis(),
244 ) : SignalEvent
245
246 /** A call's lifecycle phase changed. [phase] is a SignalCallPhase name. */
247 data class CallStateChanged(
248 override val source: SignalSource = SignalSource.SIGNAL,
249 val callId: String,
250 val phase: String,
251 val isVideo: Boolean = false,
252 ) : SignalEvent
253
254 /** A call ended. */
255 data class CallEnded(
256 override val source: SignalSource = SignalSource.SIGNAL,
257 val callId: String,
258 val reason: String,
259 val durationSeconds: Long = 0L,
260 ) : SignalEvent
261}
262
263/** Transport/login lifecycle states for the Signal primary client. */
264enum class SignalState {
265 Disconnected,
266 Connecting,
267 Registering,
268 AwaitingCode,
269 Connected,
270 Syncing,
271 Ready,
272}
273
274/** Which Signal line an event came from. */
275enum class SignalSource { SIGNAL }
276
277/** A media/share attachment carried on a Signal message. Mirrors WhatsApp's MessageAttachment. */
278data class SignalAttachment(
279 val url: String? = null,
280 val previewUrl: String? = null,
281 val mimeType: String? = null,
282 /** image | video | audio | sticker | file | share. */
283 val attachmentType: String = "file",
284 val fileName: String? = null,
285 val title: String? = null,
286 val actionUrl: String? = null,
287 val width: Int = 0,
288 val height: Int = 0,
289)
290
291/** One conversation's worth of history-sync payload. */
292data class SignalHistoryConversation(
293 val conversationId: String,
294 val name: String?,
295 val isGroup: Boolean,
296 val messages: List<SignalHistoryMessage>,
297)
298
299/** One message inside a history-sync conversation payload. */
300data class SignalHistoryMessage(
301 val messageId: String,
302 val body: String,
303 val timestamp: Long,
304 val outgoing: Boolean,
305 val senderId: String?,
306 val senderName: String?,
307 val serviceData: String? = null,
308)