Skip to content

Commit b11feaa

Browse files
authored
HMAC push notification updates (#197)
* dump the latest push notification protos * add protos and new subscribe method * update the example
1 parent 80559d7 commit b11feaa

File tree

4 files changed

+1742
-459
lines changed

4 files changed

+1742
-459
lines changed

example/src/main/java/org/xmtp/android/example/MainViewModel.kt

+19-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import org.xmtp.android.example.extension.stateFlow
2121
import org.xmtp.android.example.pushnotifications.PushNotificationTokenManager
2222
import org.xmtp.android.library.Conversation
2323
import org.xmtp.android.library.DecodedMessage
24+
import org.xmtp.android.library.push.Service
2425

2526
class MainViewModel : ViewModel() {
2627

@@ -44,7 +45,24 @@ class MainViewModel : ViewModel() {
4445
val listItems = mutableListOf<MainListItem>()
4546
try {
4647
val conversations = ClientManager.client.conversations.list(includeGroups = true)
47-
PushNotificationTokenManager.xmtpPush.subscribe(conversations.map { it.topic })
48+
val subscriptions = conversations.map {
49+
val hmacKeysResult = ClientManager.client.conversations.getHmacKeys()
50+
val hmacKeys = hmacKeysResult.hmacKeysMap
51+
val result = hmacKeys[it.topic]?.valuesList?.map { hmacKey ->
52+
Service.Subscription.HmacKey.newBuilder().also { sub_key ->
53+
sub_key.key = hmacKey.hmacKey
54+
sub_key.thirtyDayPeriodsSinceEpoch = hmacKey.thirtyDayPeriodsSinceEpoch
55+
}.build()
56+
}
57+
58+
Service.Subscription.newBuilder().also { sub ->
59+
sub.addAllHmacKeys(result)
60+
sub.topic = it.topic
61+
sub.isSilent = it.version == Conversation.Version.V1
62+
}.build()
63+
}
64+
65+
PushNotificationTokenManager.xmtpPush.subscribeWithMetadata(subscriptions)
4866
listItems.addAll(
4967
conversations.map { conversation ->
5068
val lastMessage = fetchMostRecentMessage(conversation)

library/src/main/java/org/xmtp/android/library/push/NotificationsGrpc.java

+77-27
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
import static io.grpc.MethodDescriptor.generateFullMethodName;
44

55
/**
6-
*
76
*/
87
@javax.annotation.Generated(
98
value = "by gRPC proto compiler (version 1.45.1)",
10-
comments = "Source: service.proto")
9+
comments = "Source: notifications/v1/service.proto")
1110
@io.grpc.stub.annotations.GrpcGenerated
1211
public final class NotificationsGrpc {
1312

14-
private NotificationsGrpc() {
15-
}
13+
private NotificationsGrpc() {}
1614

1715
public static final String SERVICE_NAME = "notifications.v1.Notifications";
1816

@@ -107,6 +105,36 @@ com.google.protobuf.Empty> getSubscribeMethod() {
107105
return getSubscribeMethod;
108106
}
109107

108+
private static volatile io.grpc.MethodDescriptor<org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest,
109+
com.google.protobuf.Empty> getSubscribeWithMetadataMethod;
110+
111+
@io.grpc.stub.annotations.RpcMethod(
112+
fullMethodName = SERVICE_NAME + '/' + "SubscribeWithMetadata",
113+
requestType = org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest.class,
114+
responseType = com.google.protobuf.Empty.class,
115+
methodType = io.grpc.MethodDescriptor.MethodType.UNARY)
116+
public static io.grpc.MethodDescriptor<org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest,
117+
com.google.protobuf.Empty> getSubscribeWithMetadataMethod() {
118+
io.grpc.MethodDescriptor<org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest, com.google.protobuf.Empty> getSubscribeWithMetadataMethod;
119+
if ((getSubscribeWithMetadataMethod = NotificationsGrpc.getSubscribeWithMetadataMethod) == null) {
120+
synchronized (NotificationsGrpc.class) {
121+
if ((getSubscribeWithMetadataMethod = NotificationsGrpc.getSubscribeWithMetadataMethod) == null) {
122+
NotificationsGrpc.getSubscribeWithMetadataMethod = getSubscribeWithMetadataMethod =
123+
io.grpc.MethodDescriptor.<org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest, com.google.protobuf.Empty>newBuilder()
124+
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
125+
.setFullMethodName(generateFullMethodName(SERVICE_NAME, "SubscribeWithMetadata"))
126+
.setSampledToLocalTracing(true)
127+
.setRequestMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(
128+
org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest.getDefaultInstance()))
129+
.setResponseMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(
130+
com.google.protobuf.Empty.getDefaultInstance()))
131+
.build();
132+
}
133+
}
134+
}
135+
return getSubscribeWithMetadataMethod;
136+
}
137+
110138
private static volatile io.grpc.MethodDescriptor<org.xmtp.android.library.push.Service.UnsubscribeRequest,
111139
com.google.protobuf.Empty> getUnsubscribeMethod;
112140

@@ -182,44 +210,45 @@ public NotificationsFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOpti
182210
}
183211

184212
/**
185-
*
186213
*/
187214
public static abstract class NotificationsImplBase implements io.grpc.BindableService {
188215

189216
/**
190-
*
191217
*/
192218
public void registerInstallation(org.xmtp.android.library.push.Service.RegisterInstallationRequest request,
193219
io.grpc.stub.StreamObserver<org.xmtp.android.library.push.Service.RegisterInstallationResponse> responseObserver) {
194220
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getRegisterInstallationMethod(), responseObserver);
195221
}
196222

197223
/**
198-
*
199224
*/
200225
public void deleteInstallation(org.xmtp.android.library.push.Service.DeleteInstallationRequest request,
201226
io.grpc.stub.StreamObserver<com.google.protobuf.Empty> responseObserver) {
202227
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getDeleteInstallationMethod(), responseObserver);
203228
}
204229

205230
/**
206-
*
207231
*/
208232
public void subscribe(org.xmtp.android.library.push.Service.SubscribeRequest request,
209233
io.grpc.stub.StreamObserver<com.google.protobuf.Empty> responseObserver) {
210234
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getSubscribeMethod(), responseObserver);
211235
}
212236

213237
/**
214-
*
238+
*/
239+
public void subscribeWithMetadata(org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest request,
240+
io.grpc.stub.StreamObserver<com.google.protobuf.Empty> responseObserver) {
241+
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getSubscribeWithMetadataMethod(), responseObserver);
242+
}
243+
244+
/**
215245
*/
216246
public void unsubscribe(org.xmtp.android.library.push.Service.UnsubscribeRequest request,
217247
io.grpc.stub.StreamObserver<com.google.protobuf.Empty> responseObserver) {
218248
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getUnsubscribeMethod(), responseObserver);
219249
}
220250

221-
@java.lang.Override
222-
public final io.grpc.ServerServiceDefinition bindService() {
251+
@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
223252
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
224253
.addMethod(
225254
getRegisterInstallationMethod(),
@@ -242,6 +271,13 @@ public final io.grpc.ServerServiceDefinition bindService() {
242271
org.xmtp.android.library.push.Service.SubscribeRequest,
243272
com.google.protobuf.Empty>(
244273
this, METHODID_SUBSCRIBE)))
274+
.addMethod(
275+
getSubscribeWithMetadataMethod(),
276+
io.grpc.stub.ServerCalls.asyncUnaryCall(
277+
new MethodHandlers<
278+
org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest,
279+
com.google.protobuf.Empty>(
280+
this, METHODID_SUBSCRIBE_WITH_METADATA)))
245281
.addMethod(
246282
getUnsubscribeMethod(),
247283
io.grpc.stub.ServerCalls.asyncUnaryCall(
@@ -254,7 +290,6 @@ public final io.grpc.ServerServiceDefinition bindService() {
254290
}
255291

256292
/**
257-
*
258293
*/
259294
public static final class NotificationsStub extends io.grpc.stub.AbstractAsyncStub<NotificationsStub> {
260295
private NotificationsStub(
@@ -269,7 +304,6 @@ protected NotificationsStub build(
269304
}
270305

271306
/**
272-
*
273307
*/
274308
public void registerInstallation(org.xmtp.android.library.push.Service.RegisterInstallationRequest request,
275309
io.grpc.stub.StreamObserver<org.xmtp.android.library.push.Service.RegisterInstallationResponse> responseObserver) {
@@ -278,7 +312,6 @@ public void registerInstallation(org.xmtp.android.library.push.Service.RegisterI
278312
}
279313

280314
/**
281-
*
282315
*/
283316
public void deleteInstallation(org.xmtp.android.library.push.Service.DeleteInstallationRequest request,
284317
io.grpc.stub.StreamObserver<com.google.protobuf.Empty> responseObserver) {
@@ -287,7 +320,6 @@ public void deleteInstallation(org.xmtp.android.library.push.Service.DeleteInsta
287320
}
288321

289322
/**
290-
*
291323
*/
292324
public void subscribe(org.xmtp.android.library.push.Service.SubscribeRequest request,
293325
io.grpc.stub.StreamObserver<com.google.protobuf.Empty> responseObserver) {
@@ -296,7 +328,14 @@ public void subscribe(org.xmtp.android.library.push.Service.SubscribeRequest req
296328
}
297329

298330
/**
299-
*
331+
*/
332+
public void subscribeWithMetadata(org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest request,
333+
io.grpc.stub.StreamObserver<com.google.protobuf.Empty> responseObserver) {
334+
io.grpc.stub.ClientCalls.asyncUnaryCall(
335+
getChannel().newCall(getSubscribeWithMetadataMethod(), getCallOptions()), request, responseObserver);
336+
}
337+
338+
/**
300339
*/
301340
public void unsubscribe(org.xmtp.android.library.push.Service.UnsubscribeRequest request,
302341
io.grpc.stub.StreamObserver<com.google.protobuf.Empty> responseObserver) {
@@ -306,7 +345,6 @@ public void unsubscribe(org.xmtp.android.library.push.Service.UnsubscribeRequest
306345
}
307346

308347
/**
309-
*
310348
*/
311349
public static final class NotificationsBlockingStub extends io.grpc.stub.AbstractBlockingStub<NotificationsBlockingStub> {
312350
private NotificationsBlockingStub(
@@ -321,31 +359,34 @@ protected NotificationsBlockingStub build(
321359
}
322360

323361
/**
324-
*
325362
*/
326363
public org.xmtp.android.library.push.Service.RegisterInstallationResponse registerInstallation(org.xmtp.android.library.push.Service.RegisterInstallationRequest request) {
327364
return io.grpc.stub.ClientCalls.blockingUnaryCall(
328365
getChannel(), getRegisterInstallationMethod(), getCallOptions(), request);
329366
}
330367

331368
/**
332-
*
333369
*/
334370
public com.google.protobuf.Empty deleteInstallation(org.xmtp.android.library.push.Service.DeleteInstallationRequest request) {
335371
return io.grpc.stub.ClientCalls.blockingUnaryCall(
336372
getChannel(), getDeleteInstallationMethod(), getCallOptions(), request);
337373
}
338374

339375
/**
340-
*
341376
*/
342377
public com.google.protobuf.Empty subscribe(org.xmtp.android.library.push.Service.SubscribeRequest request) {
343378
return io.grpc.stub.ClientCalls.blockingUnaryCall(
344379
getChannel(), getSubscribeMethod(), getCallOptions(), request);
345380
}
346381

347382
/**
348-
*
383+
*/
384+
public com.google.protobuf.Empty subscribeWithMetadata(org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest request) {
385+
return io.grpc.stub.ClientCalls.blockingUnaryCall(
386+
getChannel(), getSubscribeWithMetadataMethod(), getCallOptions(), request);
387+
}
388+
389+
/**
349390
*/
350391
public com.google.protobuf.Empty unsubscribe(org.xmtp.android.library.push.Service.UnsubscribeRequest request) {
351392
return io.grpc.stub.ClientCalls.blockingUnaryCall(
@@ -354,7 +395,6 @@ public com.google.protobuf.Empty unsubscribe(org.xmtp.android.library.push.Servi
354395
}
355396

356397
/**
357-
*
358398
*/
359399
public static final class NotificationsFutureStub extends io.grpc.stub.AbstractFutureStub<NotificationsFutureStub> {
360400
private NotificationsFutureStub(
@@ -369,7 +409,6 @@ protected NotificationsFutureStub build(
369409
}
370410

371411
/**
372-
*
373412
*/
374413
public com.google.common.util.concurrent.ListenableFuture<org.xmtp.android.library.push.Service.RegisterInstallationResponse> registerInstallation(
375414
org.xmtp.android.library.push.Service.RegisterInstallationRequest request) {
@@ -378,7 +417,6 @@ public com.google.common.util.concurrent.ListenableFuture<org.xmtp.android.libra
378417
}
379418

380419
/**
381-
*
382420
*/
383421
public com.google.common.util.concurrent.ListenableFuture<com.google.protobuf.Empty> deleteInstallation(
384422
org.xmtp.android.library.push.Service.DeleteInstallationRequest request) {
@@ -387,7 +425,6 @@ public com.google.common.util.concurrent.ListenableFuture<com.google.protobuf.Em
387425
}
388426

389427
/**
390-
*
391428
*/
392429
public com.google.common.util.concurrent.ListenableFuture<com.google.protobuf.Empty> subscribe(
393430
org.xmtp.android.library.push.Service.SubscribeRequest request) {
@@ -396,7 +433,14 @@ public com.google.common.util.concurrent.ListenableFuture<com.google.protobuf.Em
396433
}
397434

398435
/**
399-
*
436+
*/
437+
public com.google.common.util.concurrent.ListenableFuture<com.google.protobuf.Empty> subscribeWithMetadata(
438+
org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest request) {
439+
return io.grpc.stub.ClientCalls.futureUnaryCall(
440+
getChannel().newCall(getSubscribeWithMetadataMethod(), getCallOptions()), request);
441+
}
442+
443+
/**
400444
*/
401445
public com.google.common.util.concurrent.ListenableFuture<com.google.protobuf.Empty> unsubscribe(
402446
org.xmtp.android.library.push.Service.UnsubscribeRequest request) {
@@ -408,7 +452,8 @@ public com.google.common.util.concurrent.ListenableFuture<com.google.protobuf.Em
408452
private static final int METHODID_REGISTER_INSTALLATION = 0;
409453
private static final int METHODID_DELETE_INSTALLATION = 1;
410454
private static final int METHODID_SUBSCRIBE = 2;
411-
private static final int METHODID_UNSUBSCRIBE = 3;
455+
private static final int METHODID_SUBSCRIBE_WITH_METADATA = 3;
456+
private static final int METHODID_UNSUBSCRIBE = 4;
412457

413458
private static final class MethodHandlers<Req, Resp> implements
414459
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
@@ -439,6 +484,10 @@ public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserv
439484
serviceImpl.subscribe((org.xmtp.android.library.push.Service.SubscribeRequest) request,
440485
(io.grpc.stub.StreamObserver<com.google.protobuf.Empty>) responseObserver);
441486
break;
487+
case METHODID_SUBSCRIBE_WITH_METADATA:
488+
serviceImpl.subscribeWithMetadata((org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest) request,
489+
(io.grpc.stub.StreamObserver<com.google.protobuf.Empty>) responseObserver);
490+
break;
442491
case METHODID_UNSUBSCRIBE:
443492
serviceImpl.unsubscribe((org.xmtp.android.library.push.Service.UnsubscribeRequest) request,
444493
(io.grpc.stub.StreamObserver<com.google.protobuf.Empty>) responseObserver);
@@ -471,6 +520,7 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
471520
.addMethod(getRegisterInstallationMethod())
472521
.addMethod(getDeleteInstallationMethod())
473522
.addMethod(getSubscribeMethod())
523+
.addMethod(getSubscribeWithMetadataMethod())
474524
.addMethod(getUnsubscribeMethod())
475525
.build();
476526
}

0 commit comments

Comments
 (0)