Skip to content

Commit

Permalink
HMAC push notification updates (#197)
Browse files Browse the repository at this point in the history
* dump the latest push notification protos

* add protos and new subscribe method

* update the example
  • Loading branch information
nplasterer authored Mar 22, 2024
1 parent 80559d7 commit b11feaa
Show file tree
Hide file tree
Showing 4 changed files with 1,742 additions and 459 deletions.
20 changes: 19 additions & 1 deletion example/src/main/java/org/xmtp/android/example/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.xmtp.android.example.extension.stateFlow
import org.xmtp.android.example.pushnotifications.PushNotificationTokenManager
import org.xmtp.android.library.Conversation
import org.xmtp.android.library.DecodedMessage
import org.xmtp.android.library.push.Service

class MainViewModel : ViewModel() {

Expand All @@ -44,7 +45,24 @@ class MainViewModel : ViewModel() {
val listItems = mutableListOf<MainListItem>()
try {
val conversations = ClientManager.client.conversations.list(includeGroups = true)
PushNotificationTokenManager.xmtpPush.subscribe(conversations.map { it.topic })
val subscriptions = conversations.map {
val hmacKeysResult = ClientManager.client.conversations.getHmacKeys()
val hmacKeys = hmacKeysResult.hmacKeysMap
val result = hmacKeys[it.topic]?.valuesList?.map { hmacKey ->
Service.Subscription.HmacKey.newBuilder().also { sub_key ->
sub_key.key = hmacKey.hmacKey
sub_key.thirtyDayPeriodsSinceEpoch = hmacKey.thirtyDayPeriodsSinceEpoch
}.build()
}

Service.Subscription.newBuilder().also { sub ->
sub.addAllHmacKeys(result)
sub.topic = it.topic
sub.isSilent = it.version == Conversation.Version.V1
}.build()
}

PushNotificationTokenManager.xmtpPush.subscribeWithMetadata(subscriptions)
listItems.addAll(
conversations.map { conversation ->
val lastMessage = fetchMostRecentMessage(conversation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
import static io.grpc.MethodDescriptor.generateFullMethodName;

/**
*
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.45.1)",
comments = "Source: service.proto")
comments = "Source: notifications/v1/service.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class NotificationsGrpc {

private NotificationsGrpc() {
}
private NotificationsGrpc() {}

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

Expand Down Expand Up @@ -107,6 +105,36 @@ com.google.protobuf.Empty> getSubscribeMethod() {
return getSubscribeMethod;
}

private static volatile io.grpc.MethodDescriptor<org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest,
com.google.protobuf.Empty> getSubscribeWithMetadataMethod;

@io.grpc.stub.annotations.RpcMethod(
fullMethodName = SERVICE_NAME + '/' + "SubscribeWithMetadata",
requestType = org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest.class,
responseType = com.google.protobuf.Empty.class,
methodType = io.grpc.MethodDescriptor.MethodType.UNARY)
public static io.grpc.MethodDescriptor<org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest,
com.google.protobuf.Empty> getSubscribeWithMetadataMethod() {
io.grpc.MethodDescriptor<org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest, com.google.protobuf.Empty> getSubscribeWithMetadataMethod;
if ((getSubscribeWithMetadataMethod = NotificationsGrpc.getSubscribeWithMetadataMethod) == null) {
synchronized (NotificationsGrpc.class) {
if ((getSubscribeWithMetadataMethod = NotificationsGrpc.getSubscribeWithMetadataMethod) == null) {
NotificationsGrpc.getSubscribeWithMetadataMethod = getSubscribeWithMetadataMethod =
io.grpc.MethodDescriptor.<org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest, com.google.protobuf.Empty>newBuilder()
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
.setFullMethodName(generateFullMethodName(SERVICE_NAME, "SubscribeWithMetadata"))
.setSampledToLocalTracing(true)
.setRequestMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(
org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest.getDefaultInstance()))
.setResponseMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(
com.google.protobuf.Empty.getDefaultInstance()))
.build();
}
}
}
return getSubscribeWithMetadataMethod;
}

private static volatile io.grpc.MethodDescriptor<org.xmtp.android.library.push.Service.UnsubscribeRequest,
com.google.protobuf.Empty> getUnsubscribeMethod;

Expand Down Expand Up @@ -182,44 +210,45 @@ public NotificationsFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOpti
}

/**
*
*/
public static abstract class NotificationsImplBase implements io.grpc.BindableService {

/**
*
*/
public void registerInstallation(org.xmtp.android.library.push.Service.RegisterInstallationRequest request,
io.grpc.stub.StreamObserver<org.xmtp.android.library.push.Service.RegisterInstallationResponse> responseObserver) {
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getRegisterInstallationMethod(), responseObserver);
}

/**
*
*/
public void deleteInstallation(org.xmtp.android.library.push.Service.DeleteInstallationRequest request,
io.grpc.stub.StreamObserver<com.google.protobuf.Empty> responseObserver) {
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getDeleteInstallationMethod(), responseObserver);
}

/**
*
*/
public void subscribe(org.xmtp.android.library.push.Service.SubscribeRequest request,
io.grpc.stub.StreamObserver<com.google.protobuf.Empty> responseObserver) {
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getSubscribeMethod(), responseObserver);
}

/**
*
*/
public void subscribeWithMetadata(org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest request,
io.grpc.stub.StreamObserver<com.google.protobuf.Empty> responseObserver) {
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getSubscribeWithMetadataMethod(), responseObserver);
}

/**
*/
public void unsubscribe(org.xmtp.android.library.push.Service.UnsubscribeRequest request,
io.grpc.stub.StreamObserver<com.google.protobuf.Empty> responseObserver) {
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getUnsubscribeMethod(), responseObserver);
}

@java.lang.Override
public final io.grpc.ServerServiceDefinition bindService() {
@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
.addMethod(
getRegisterInstallationMethod(),
Expand All @@ -242,6 +271,13 @@ public final io.grpc.ServerServiceDefinition bindService() {
org.xmtp.android.library.push.Service.SubscribeRequest,
com.google.protobuf.Empty>(
this, METHODID_SUBSCRIBE)))
.addMethod(
getSubscribeWithMetadataMethod(),
io.grpc.stub.ServerCalls.asyncUnaryCall(
new MethodHandlers<
org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest,
com.google.protobuf.Empty>(
this, METHODID_SUBSCRIBE_WITH_METADATA)))
.addMethod(
getUnsubscribeMethod(),
io.grpc.stub.ServerCalls.asyncUnaryCall(
Expand All @@ -254,7 +290,6 @@ public final io.grpc.ServerServiceDefinition bindService() {
}

/**
*
*/
public static final class NotificationsStub extends io.grpc.stub.AbstractAsyncStub<NotificationsStub> {
private NotificationsStub(
Expand All @@ -269,7 +304,6 @@ protected NotificationsStub build(
}

/**
*
*/
public void registerInstallation(org.xmtp.android.library.push.Service.RegisterInstallationRequest request,
io.grpc.stub.StreamObserver<org.xmtp.android.library.push.Service.RegisterInstallationResponse> responseObserver) {
Expand All @@ -278,7 +312,6 @@ public void registerInstallation(org.xmtp.android.library.push.Service.RegisterI
}

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

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

/**
*
*/
public void subscribeWithMetadata(org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest request,
io.grpc.stub.StreamObserver<com.google.protobuf.Empty> responseObserver) {
io.grpc.stub.ClientCalls.asyncUnaryCall(
getChannel().newCall(getSubscribeWithMetadataMethod(), getCallOptions()), request, responseObserver);
}

/**
*/
public void unsubscribe(org.xmtp.android.library.push.Service.UnsubscribeRequest request,
io.grpc.stub.StreamObserver<com.google.protobuf.Empty> responseObserver) {
Expand All @@ -306,7 +345,6 @@ public void unsubscribe(org.xmtp.android.library.push.Service.UnsubscribeRequest
}

/**
*
*/
public static final class NotificationsBlockingStub extends io.grpc.stub.AbstractBlockingStub<NotificationsBlockingStub> {
private NotificationsBlockingStub(
Expand All @@ -321,31 +359,34 @@ protected NotificationsBlockingStub build(
}

/**
*
*/
public org.xmtp.android.library.push.Service.RegisterInstallationResponse registerInstallation(org.xmtp.android.library.push.Service.RegisterInstallationRequest request) {
return io.grpc.stub.ClientCalls.blockingUnaryCall(
getChannel(), getRegisterInstallationMethod(), getCallOptions(), request);
}

/**
*
*/
public com.google.protobuf.Empty deleteInstallation(org.xmtp.android.library.push.Service.DeleteInstallationRequest request) {
return io.grpc.stub.ClientCalls.blockingUnaryCall(
getChannel(), getDeleteInstallationMethod(), getCallOptions(), request);
}

/**
*
*/
public com.google.protobuf.Empty subscribe(org.xmtp.android.library.push.Service.SubscribeRequest request) {
return io.grpc.stub.ClientCalls.blockingUnaryCall(
getChannel(), getSubscribeMethod(), getCallOptions(), request);
}

/**
*
*/
public com.google.protobuf.Empty subscribeWithMetadata(org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest request) {
return io.grpc.stub.ClientCalls.blockingUnaryCall(
getChannel(), getSubscribeWithMetadataMethod(), getCallOptions(), request);
}

/**
*/
public com.google.protobuf.Empty unsubscribe(org.xmtp.android.library.push.Service.UnsubscribeRequest request) {
return io.grpc.stub.ClientCalls.blockingUnaryCall(
Expand All @@ -354,7 +395,6 @@ public com.google.protobuf.Empty unsubscribe(org.xmtp.android.library.push.Servi
}

/**
*
*/
public static final class NotificationsFutureStub extends io.grpc.stub.AbstractFutureStub<NotificationsFutureStub> {
private NotificationsFutureStub(
Expand All @@ -369,7 +409,6 @@ protected NotificationsFutureStub build(
}

/**
*
*/
public com.google.common.util.concurrent.ListenableFuture<org.xmtp.android.library.push.Service.RegisterInstallationResponse> registerInstallation(
org.xmtp.android.library.push.Service.RegisterInstallationRequest request) {
Expand All @@ -378,7 +417,6 @@ public com.google.common.util.concurrent.ListenableFuture<org.xmtp.android.libra
}

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

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

/**
*
*/
public com.google.common.util.concurrent.ListenableFuture<com.google.protobuf.Empty> subscribeWithMetadata(
org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest request) {
return io.grpc.stub.ClientCalls.futureUnaryCall(
getChannel().newCall(getSubscribeWithMetadataMethod(), getCallOptions()), request);
}

/**
*/
public com.google.common.util.concurrent.ListenableFuture<com.google.protobuf.Empty> unsubscribe(
org.xmtp.android.library.push.Service.UnsubscribeRequest request) {
Expand All @@ -408,7 +452,8 @@ public com.google.common.util.concurrent.ListenableFuture<com.google.protobuf.Em
private static final int METHODID_REGISTER_INSTALLATION = 0;
private static final int METHODID_DELETE_INSTALLATION = 1;
private static final int METHODID_SUBSCRIBE = 2;
private static final int METHODID_UNSUBSCRIBE = 3;
private static final int METHODID_SUBSCRIBE_WITH_METADATA = 3;
private static final int METHODID_UNSUBSCRIBE = 4;

private static final class MethodHandlers<Req, Resp> implements
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
Expand Down Expand Up @@ -439,6 +484,10 @@ public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserv
serviceImpl.subscribe((org.xmtp.android.library.push.Service.SubscribeRequest) request,
(io.grpc.stub.StreamObserver<com.google.protobuf.Empty>) responseObserver);
break;
case METHODID_SUBSCRIBE_WITH_METADATA:
serviceImpl.subscribeWithMetadata((org.xmtp.android.library.push.Service.SubscribeWithMetadataRequest) request,
(io.grpc.stub.StreamObserver<com.google.protobuf.Empty>) responseObserver);
break;
case METHODID_UNSUBSCRIBE:
serviceImpl.unsubscribe((org.xmtp.android.library.push.Service.UnsubscribeRequest) request,
(io.grpc.stub.StreamObserver<com.google.protobuf.Empty>) responseObserver);
Expand Down Expand Up @@ -471,6 +520,7 @@ public static io.grpc.ServiceDescriptor getServiceDescriptor() {
.addMethod(getRegisterInstallationMethod())
.addMethod(getDeleteInstallationMethod())
.addMethod(getSubscribeMethod())
.addMethod(getSubscribeWithMetadataMethod())
.addMethod(getUnsubscribeMethod())
.build();
}
Expand Down
Loading

0 comments on commit b11feaa

Please sign in to comment.