Skip to content

Commit

Permalink
feat: add provider fields (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdeme authored Mar 30, 2022
1 parent 6a655fc commit e6e1d44
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 30 deletions.
38 changes: 25 additions & 13 deletions src/main/java/io/getstream/chat/java/models/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ public static class HuaweiConfig {
private Boolean enabled;
}

public enum PushProviderType {
@JsonProperty("firebase")
Firebase,
@JsonProperty("apn")
Apn,
@JsonProperty("xiaomi")
Xiaomi,
@JsonProperty("huawei")
Huawei,
@JsonEnumDefaultValue
UNKNOWN
}

@Data
@NoArgsConstructor
public static class PushNotificationFields {
Expand Down Expand Up @@ -377,6 +390,10 @@ public static class DeviceError {
@JsonProperty("provider")
private String provider;

@NotNull
@JsonProperty("provider_name")
private String providerName;

@NotNull
@JsonProperty("error_message")
private String errorMessage;
Expand Down Expand Up @@ -794,6 +811,14 @@ public static class AppCheckPushRequestData {
@JsonProperty("skip_devices")
private Boolean skipDevices;

@Nullable
@JsonProperty("push_provider_name")
private String pushProviderName;

@Nullable
@JsonProperty("push_provider_type")
private PushProviderType pushProviderType;

@Nullable
@JsonProperty("user_id")
private String userId;
Expand Down Expand Up @@ -888,19 +913,6 @@ public static class PushProvider {
@Nullable
@JsonProperty("updated_at")
private Date updatedAt;

public enum PushProviderType {
@JsonProperty("firebase")
Firebase,
@JsonProperty("apn")
Apn,
@JsonProperty("xiaomi")
Xiaomi,
@JsonProperty("huawei")
Huawei,
@JsonEnumDefaultValue
UNKNOWN
}
}

@Builder(
Expand Down
29 changes: 16 additions & 13 deletions src/main/java/io/getstream/chat/java/models/Device.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.getstream.chat.java.models;

import com.fasterxml.jackson.annotation.JsonEnumDefaultValue;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.getstream.chat.java.models.App.PushProviderType;
import io.getstream.chat.java.models.Device.DeviceCreateRequestData.DeviceCreateRequest;
import io.getstream.chat.java.models.User.UserRequestObject;
import io.getstream.chat.java.models.framework.RequestObjectBuilder;
Expand All @@ -21,12 +21,16 @@
public class Device {
@Nullable
@JsonProperty("push_provider")
private PushProvider pushProvider;
private PushProviderType pushProvider;

@NotNull
@JsonProperty("id")
private String id;

@Nullable
@JsonProperty("push_provider_name")
private String pushProviderName;

@NotNull
@JsonProperty("created_at")
private Date createdAt;
Expand All @@ -43,26 +47,21 @@ public class Device {
@JsonProperty("user_id")
private String userId;

public enum PushProvider {
@JsonProperty("firebase")
FIREBASE,
@JsonProperty("apn")
APN,
@JsonEnumDefaultValue
UNKNOWN
}

@Builder
@Setter
public static class DeviceRequestObject {
@Nullable
@JsonProperty("push_provider")
private PushProvider pushProvider;
private PushProviderType pushProvider;

@Nullable
@JsonProperty("id")
private String id;

@Nullable
@JsonProperty("push_provider_name")
private String pushProviderName;

@Nullable
@JsonProperty("created_at")
private Date createdAt;
Expand Down Expand Up @@ -92,12 +91,16 @@ public static DeviceRequestObject buildFrom(@Nullable Device device) {
public static class DeviceCreateRequestData {
@Nullable
@JsonProperty("push_provider")
private PushProvider pushProvider;
private PushProviderType pushProvider;

@Nullable
@JsonProperty("id")
private String id;

@Nullable
@JsonProperty("push_provider_name")
private String pushProviderName;

@Nullable
@JsonProperty("user_id")
private String userId;
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/io/getstream/chat/java/DeviceTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.getstream.chat.java;

import io.getstream.chat.java.models.App.PushProviderType;
import io.getstream.chat.java.models.Device;
import io.getstream.chat.java.models.Device.PushProvider;
import java.util.List;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.Assertions;
Expand All @@ -18,7 +18,7 @@ void whenCreatingDevice_thenNoException() {
Device.create()
.id(RandomStringUtils.randomAlphabetic(10))
.user(testUserRequestObject)
.pushProvider(PushProvider.APN)
.pushProvider(PushProviderType.Apn)
.request());
}

Expand All @@ -31,7 +31,7 @@ void whenDeletingDevice_thenDeleted() {
Device.create()
.id(deviceId)
.user(testUserRequestObject)
.pushProvider(PushProvider.APN)
.pushProvider(PushProviderType.Apn)
.request());
Assertions.assertDoesNotThrow(
() -> Device.delete(deviceId, testUserRequestObject.getId()).request());
Expand All @@ -51,7 +51,7 @@ void whenListingCommand_thenCanRetrieve() {
Device.create()
.id(deviceId)
.user(testUserRequestObject)
.pushProvider(PushProvider.APN)
.pushProvider(PushProviderType.Apn)
.request());
List<Device> devices =
Assertions.assertDoesNotThrow(() -> Device.list(testUserRequestObject.getId()).request())
Expand Down

0 comments on commit e6e1d44

Please sign in to comment.