@@ -5,6 +5,7 @@ import com.google.protobuf.kotlin.toByteString
5
5
import kotlinx.coroutines.flow.Flow
6
6
import kotlinx.coroutines.flow.flowOf
7
7
import org.xmtp.android.library.codecs.EncodedContent
8
+ import org.xmtp.android.library.libxmtp.Message
8
9
import org.xmtp.android.library.messages.Envelope
9
10
import org.xmtp.android.library.messages.PagingInfoSortDirection
10
11
import org.xmtp.proto.keystore.api.v1.Keystore.TopicMap.TopicData
@@ -59,6 +60,16 @@ sealed class Conversation {
59
60
}
60
61
}
61
62
63
+ val peerAddresses: List <String >
64
+ get() {
65
+ return when (this ) {
66
+ is V1 -> listOf (conversationV1.peerAddress)
67
+ is V2 -> listOf (conversationV2.peerAddress)
68
+ is Group -> group.memberAddresses()
69
+ }
70
+ }
71
+
72
+
62
73
// This distinctly identifies between two addresses.
63
74
// Note: this will be empty for older v1 conversations.
64
75
val conversationId: String?
@@ -80,12 +91,11 @@ sealed class Conversation {
80
91
}
81
92
82
93
fun consentState (): ConsentState {
83
- val client : Client = when (this ) {
84
- is V1 -> conversationV1.client
85
- is V2 -> conversationV2.client
86
- is Group -> group.client
94
+ return when (this ) {
95
+ is V1 -> conversationV1.client.contacts.consentList.state(address = peerAddress)
96
+ is V2 -> conversationV2.client.contacts.consentList.state(address = peerAddress)
97
+ is Group -> ConsentState . UNKNOWN // No such thing as consent for a group
87
98
}
88
- return client.contacts.consentList.state(address = peerAddress)
89
99
}
90
100
91
101
/* *
@@ -109,15 +119,15 @@ sealed class Conversation {
109
119
),
110
120
).build()
111
121
112
- is Group -> TODO ( )
122
+ is Group -> throw XMTPException ( " Groups do not support topics " )
113
123
}
114
124
}
115
125
116
- fun decode (envelope : Envelope ): DecodedMessage {
126
+ fun decode (envelope : Envelope , message : Message ? = null ): DecodedMessage {
117
127
return when (this ) {
118
128
is V1 -> conversationV1.decode(envelope)
119
129
is V2 -> conversationV2.decodeEnvelope(envelope)
120
- is Group -> TODO ( )
130
+ is Group -> message?.decode() ? : throw XMTPException ( " Groups require message be passed " )
121
131
}
122
132
}
123
133
@@ -140,7 +150,7 @@ sealed class Conversation {
140
150
conversationV2.prepareMessage(content = content, options = options)
141
151
}
142
152
143
- is Group -> TODO ()
153
+ is Group -> throw XMTPException ( " Groups do not support prepared messages " ) // We return a encoded content not a preparedmessage which requires a envelope
144
154
}
145
155
}
146
156
@@ -157,23 +167,23 @@ sealed class Conversation {
157
167
conversationV2.prepareMessage(encodedContent = encodedContent, options = options)
158
168
}
159
169
160
- is Group -> TODO ()
170
+ is Group -> throw XMTPException ( " Groups do not support prepared messages " ) // We return a encoded content not a preparedmessage which requires a envelope
161
171
}
162
172
}
163
173
164
174
fun send (prepared : PreparedMessage ): String {
165
175
return when (this ) {
166
176
is V1 -> conversationV1.send(prepared = prepared)
167
177
is V2 -> conversationV2.send(prepared = prepared)
168
- is Group -> TODO ()
178
+ is Group -> throw XMTPException ( " Groups do not support prepared messages " ) // We return a encoded content not a prepared Message which requires a envelope
169
179
}
170
180
}
171
181
172
182
fun <T > send (content : T , options : SendOptions ? = null): String {
173
183
return when (this ) {
174
184
is V1 -> conversationV1.send(content = content, options = options)
175
185
is V2 -> conversationV2.send(content = content, options = options)
176
- is Group -> TODO ( )
186
+ is Group -> group.send(content = content, options = options )
177
187
}
178
188
}
179
189
@@ -189,7 +199,7 @@ sealed class Conversation {
189
199
return when (this ) {
190
200
is V1 -> conversationV1.send(encodedContent = encodedContent, options = options)
191
201
is V2 -> conversationV2.send(encodedContent = encodedContent, options = options)
192
- is Group -> TODO ( )
202
+ is Group -> group.send(encodedContent = encodedContent )
193
203
}
194
204
}
195
205
@@ -258,17 +268,24 @@ sealed class Conversation {
258
268
return when (this ) {
259
269
is V1 -> conversationV1.decryptedMessages(limit, before, after, direction)
260
270
is V2 -> conversationV2.decryptedMessages(limit, before, after, direction)
261
- is Group -> TODO ( )
271
+ is Group -> group.decryptedMessages(limit, before, after, direction )
262
272
}
263
273
}
264
274
265
275
fun decrypt (
266
276
envelope : Envelope ,
277
+ message : Message ? = null,
267
278
): DecryptedMessage {
268
279
return when (this ) {
269
280
is V1 -> conversationV1.decrypt(envelope)
270
281
is V2 -> conversationV2.decrypt(envelope)
271
- is Group -> TODO ()
282
+ is Group -> {
283
+ if (message == null ) {
284
+ throw XMTPException (" Groups require message be passed" )
285
+ } else {
286
+ group.decrypt(message)
287
+ }
288
+ }
272
289
}
273
290
}
274
291
@@ -298,15 +315,15 @@ sealed class Conversation {
298
315
return when (this ) {
299
316
is V1 -> conversationV1.streamDecryptedMessages()
300
317
is V2 -> conversationV2.streamDecryptedMessages()
301
- is Group -> TODO ()
318
+ is Group -> group.streamDecryptedMessages ()
302
319
}
303
320
}
304
321
305
322
fun streamEphemeral (): Flow <Envelope > {
306
323
return when (this ) {
307
324
is V1 -> return conversationV1.streamEphemeral()
308
325
is V2 -> return conversationV2.streamEphemeral()
309
- is Group -> TODO ( )
326
+ is Group -> throw XMTPException ( " Groups do not support ephemeral messages " )
310
327
}
311
328
}
312
329
}
0 commit comments