From 95a8571b4ccf5c6864f43c20c6e8f2b2ede60607 Mon Sep 17 00:00:00 2001 From: Andrei Mihu Date: Mon, 20 Nov 2017 14:06:11 +0000 Subject: [PATCH] Add friends, groups, notifications. Merge #4 --- CHANGELOG.md | 10 + build.gradle | 5 +- .../com/heroiclabs/nakama/ClientListener.java | 9 + .../com/heroiclabs/nakama/DefaultClient.java | 42 ++++ .../com/heroiclabs/nakama/DefaultFriend.java | 62 ++++++ .../nakama/DefaultFriendsAddMessage.java | 34 ++++ .../nakama/DefaultFriendsBlockMessage.java | 34 ++++ .../nakama/DefaultFriendsListMessage.java | 34 ++++ .../nakama/DefaultFriendsRemoveMessage.java | 34 ++++ .../com/heroiclabs/nakama/DefaultGroup.java | 54 ++++++ .../heroiclabs/nakama/DefaultGroupSelf.java | 59 ++++++ .../heroiclabs/nakama/DefaultGroupUser.java | 63 ++++++ .../nakama/DefaultGroupUsersAddMessage.java | 34 ++++ .../nakama/DefaultGroupUsersKickMessage.java | 34 ++++ .../nakama/DefaultGroupUsersListMessage.java | 34 ++++ .../DefaultGroupUsersPromoteMessage.java | 34 ++++ .../nakama/DefaultGroupsCreateMessage.java | 34 ++++ .../nakama/DefaultGroupsFetchMessage.java | 34 ++++ .../nakama/DefaultGroupsJoinMessage.java | 34 ++++ .../nakama/DefaultGroupsLeaveMessage.java | 34 ++++ .../nakama/DefaultGroupsListMessage.java | 34 ++++ .../nakama/DefaultGroupsRemoveMessage.java | 34 ++++ .../nakama/DefaultGroupsSelfListMessage.java | 34 ++++ .../nakama/DefaultGroupsUpdateMessage.java | 34 ++++ .../heroiclabs/nakama/DefaultLeaderboard.java | 4 +- .../nakama/DefaultNotification.java | 40 ++++ .../DefaultNotificationsListMessage.java | 34 ++++ .../DefaultNotificationsRemoveMessage.java | 34 ++++ .../java/com/heroiclabs/nakama/Friend.java | 61 ++++++ .../heroiclabs/nakama/FriendsAddMessage.java | 57 ++++++ .../nakama/FriendsBlockMessage.java | 48 +++++ .../heroiclabs/nakama/FriendsListMessage.java | 35 ++++ .../nakama/FriendsRemoveMessage.java | 48 +++++ .../java/com/heroiclabs/nakama/Group.java | 122 ++++++++++++ .../java/com/heroiclabs/nakama/GroupSelf.java | 29 +++ .../java/com/heroiclabs/nakama/GroupUser.java | 29 +++ .../nakama/GroupUsersAddMessage.java | 51 +++++ .../nakama/GroupUsersKickMessage.java | 51 +++++ .../nakama/GroupUsersListMessage.java | 38 ++++ .../nakama/GroupUsersPromoteMessage.java | 51 +++++ .../nakama/GroupsCreateMessage.java | 64 +++++++ .../heroiclabs/nakama/GroupsFetchMessage.java | 57 ++++++ .../heroiclabs/nakama/GroupsJoinMessage.java | 48 +++++ .../heroiclabs/nakama/GroupsLeaveMessage.java | 48 +++++ .../heroiclabs/nakama/GroupsListMessage.java | 76 ++++++++ .../nakama/GroupsRemoveMessage.java | 48 +++++ .../nakama/GroupsSelfListMessage.java | 35 ++++ .../nakama/GroupsUpdateMessage.java | 66 +++++++ .../com/heroiclabs/nakama/Leaderboard.java | 28 ++- .../nakama/LeaderboardRecordsListMessage.java | 4 +- .../heroiclabs/nakama/NoopClientListener.java | 3 + .../com/heroiclabs/nakama/Notification.java | 63 ++++++ .../nakama/NotificationsListMessage.java | 49 +++++ .../nakama/NotificationsRemoveMessage.java | 53 ++++++ .../heroiclabs/nakama/TopicLeaveMessage.java | 2 +- .../nakama/FriendsAddMessageTest.java | 170 +++++++++++++++++ .../nakama/FriendsBlockMessageTest.java | 142 ++++++++++++++ .../nakama/FriendsListMessageTest.java | 131 +++++++++++++ .../nakama/FriendsRemoveMessageTest.java | 141 ++++++++++++++ .../nakama/GroupUsersAddMessageTest.java | 180 ++++++++++++++++++ .../nakama/GroupUsersListMessageTest.java | 108 +++++++++++ .../nakama/GroupsCreateMessageTest.java | 76 ++++++++ .../nakama/GroupsFetchMessageTest.java | 4 + .../nakama/GroupsJoinMessageTest.java | 163 ++++++++++++++++ .../nakama/GroupsRemoveMessageTest.java | 101 ++++++++++ .../LeaderboardRecordsListMessageTest.java | 137 +++++++++++++ .../nakama/MatchmakeAddMessageTest.java | 5 +- .../nakama/NotificationsListMessageTest.java | 93 +++++++++ 68 files changed, 3665 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultFriend.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultFriendsAddMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultFriendsBlockMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultFriendsListMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultFriendsRemoveMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultGroup.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultGroupSelf.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultGroupUser.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultGroupUsersAddMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultGroupUsersKickMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultGroupUsersListMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultGroupUsersPromoteMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultGroupsCreateMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultGroupsFetchMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultGroupsJoinMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultGroupsLeaveMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultGroupsListMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultGroupsRemoveMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultGroupsSelfListMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultGroupsUpdateMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultNotification.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultNotificationsListMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/DefaultNotificationsRemoveMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/Friend.java create mode 100644 src/main/java/com/heroiclabs/nakama/FriendsAddMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/FriendsBlockMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/FriendsListMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/FriendsRemoveMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/Group.java create mode 100644 src/main/java/com/heroiclabs/nakama/GroupSelf.java create mode 100644 src/main/java/com/heroiclabs/nakama/GroupUser.java create mode 100644 src/main/java/com/heroiclabs/nakama/GroupUsersAddMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/GroupUsersKickMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/GroupUsersListMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/GroupUsersPromoteMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/GroupsCreateMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/GroupsFetchMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/GroupsJoinMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/GroupsLeaveMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/GroupsListMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/GroupsRemoveMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/GroupsSelfListMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/GroupsUpdateMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/Notification.java create mode 100644 src/main/java/com/heroiclabs/nakama/NotificationsListMessage.java create mode 100644 src/main/java/com/heroiclabs/nakama/NotificationsRemoveMessage.java create mode 100644 src/test/java/com/heroiclabs/nakama/FriendsAddMessageTest.java create mode 100644 src/test/java/com/heroiclabs/nakama/FriendsBlockMessageTest.java create mode 100644 src/test/java/com/heroiclabs/nakama/FriendsListMessageTest.java create mode 100644 src/test/java/com/heroiclabs/nakama/FriendsRemoveMessageTest.java create mode 100644 src/test/java/com/heroiclabs/nakama/GroupUsersAddMessageTest.java create mode 100644 src/test/java/com/heroiclabs/nakama/GroupUsersListMessageTest.java create mode 100644 src/test/java/com/heroiclabs/nakama/GroupsCreateMessageTest.java create mode 100644 src/test/java/com/heroiclabs/nakama/GroupsFetchMessageTest.java create mode 100644 src/test/java/com/heroiclabs/nakama/GroupsJoinMessageTest.java create mode 100644 src/test/java/com/heroiclabs/nakama/GroupsRemoveMessageTest.java create mode 100644 src/test/java/com/heroiclabs/nakama/LeaderboardRecordsListMessageTest.java create mode 100644 src/test/java/com/heroiclabs/nakama/NotificationsListMessageTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index b9866b98..4c589fd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ All notable changes to this project are documented below. The format is based on [keep a changelog](http://keepachangelog.com/) and this project uses [semantic versioning](http://semver.org/). ## [Unreleased] +### Added +- Support for In-App Notifications feature. +- Support for Friends feature. +- Support for Groups feature. + +### Changed +- Leaderboard sort order is now exposed as an enum rather than a number. + +### Fixed +- Use correct name for inconsistently defined topic leave message builder method. ## [0.4.0] - 2017-11-07 ### Changed diff --git a/build.gradle b/build.gradle index 55fb494f..52428ed9 100644 --- a/build.gradle +++ b/build.gradle @@ -83,14 +83,15 @@ bintray { dependencies { compileOnly 'org.projectlombok:lombok:1.16.18' - compile 'com.google.code.gson:gson:2.8.1' + compile 'com.google.code.gson:gson:2.8.2' compile 'com.google.protobuf:protobuf-lite:3.0.1' - compile 'com.squareup.okhttp3:okhttp:3.8.1' + compile 'com.squareup.okhttp3:okhttp:3.9.0' compile 'com.stumbleupon:async:1.4.1' compile ('org.slf4j:slf4j-api:1.7.25') { force = true // don't upgrade to "1.8.0-alpha2" } testCompile 'junit:junit:4.12' + testCompile 'ch.qos.logback:logback-classic:1.2.3' } gitPublish { diff --git a/src/main/java/com/heroiclabs/nakama/ClientListener.java b/src/main/java/com/heroiclabs/nakama/ClientListener.java index d3c21121..ac3c7af1 100644 --- a/src/main/java/com/heroiclabs/nakama/ClientListener.java +++ b/src/main/java/com/heroiclabs/nakama/ClientListener.java @@ -16,6 +16,8 @@ package com.heroiclabs.nakama; +import java.util.List; + /** * A listener for receiving {@code Client} events. */ @@ -59,4 +61,11 @@ public interface ClientListener { * @param matchPresence The {@code MatchPresence} received. */ void onMatchPresence(MatchPresence matchPresence); + + /** + * Called when the client receives new notifications. + * + * @param notifications The list of {@code Notification} received. + */ + void onNotifications(List notifications); } diff --git a/src/main/java/com/heroiclabs/nakama/DefaultClient.java b/src/main/java/com/heroiclabs/nakama/DefaultClient.java index 593b0b29..9d9bcc34 100644 --- a/src/main/java/com/heroiclabs/nakama/DefaultClient.java +++ b/src/main/java/com/heroiclabs/nakama/DefaultClient.java @@ -252,6 +252,13 @@ public void onMessage(WebSocket webSocket, ByteString bytes) { case MATCHMAKE_MATCHED: listener.onMatchmakeMatched(DefaultMatchmakeMatched.fromProto(envelope.getMatchmakeMatched())); break; + case LIVE_NOTIFICATIONS: + final List notifications = new ArrayList<>(); + for (final com.heroiclabs.nakama.Api.Notification notification : envelope.getLiveNotifications().getNotificationsList()) { + notifications.add(DefaultNotification.fromProto(notification)); + } + listener.onNotifications(notifications); + break; default: break; } @@ -281,6 +288,34 @@ public void onMessage(WebSocket webSocket, ByteString bytes) { } def.callback(new DefaultResultSet(null, users)); break; + case FRIENDS: + final List friends = new ArrayList<>(); + for (final com.heroiclabs.nakama.Api.Friend friend : envelope.getFriends().getFriendsList()) { + friends.add(DefaultFriend.fromProto(friend)); + } + def.callback(new DefaultResultSet(null, friends)); + break; + case GROUPS: + final List groups = new ArrayList<>(); + for (final com.heroiclabs.nakama.Api.Group group : envelope.getGroups().getGroupsList()) { + groups.add(DefaultGroup.fromProto(group)); + } + def.callback(new DefaultResultSet(new DefaultCursor(envelope.getGroups().getCursor()), groups)); + break; + case GROUPS_SELF: + final List groupsSelf = new ArrayList<>(); + for (final com.heroiclabs.nakama.Api.TGroupsSelf.GroupSelf groupSelf : envelope.getGroupsSelf().getGroupsSelfList()) { + groupsSelf.add(DefaultGroupSelf.fromProto(groupSelf)); + } + def.callback(new DefaultResultSet(null, groupsSelf)); + break; + case GROUP_USERS: + final List groupUsers = new ArrayList<>(); + for (final com.heroiclabs.nakama.Api.GroupUser groupUser : envelope.getGroupUsers().getUsersList()) { + groupUsers.add(DefaultGroupUser.fromProto(groupUser)); + } + def.callback(new DefaultResultSet(null, groupUsers)); + break; case STORAGE_DATA: final List records = new ArrayList<>(); for (final com.heroiclabs.nakama.Api.TStorageData.StorageData data : envelope.getStorageData().getDataList()) { @@ -346,6 +381,13 @@ public void onMessage(WebSocket webSocket, ByteString bytes) { } def.callback(new DefaultResultSet(new DefaultCursor(envelope.getLeaderboardRecords().getCursor()), leaderboardRecords)); break; + case NOTIFICATIONS: + final List notifications = new ArrayList<>(); + for (final com.heroiclabs.nakama.Api.Notification notification : envelope.getNotifications().getNotificationsList()) { + notifications.add(DefaultNotification.fromProto(notification)); + } + def.callback(new DefaultResultSet(new DefaultCursor(envelope.getNotifications().getResumableCursor()), notifications)); + break; default: def.callback(new DefaultError(envelope.getError().getMessage(), envelope.getError().getCode(), collationId)); break; diff --git a/src/main/java/com/heroiclabs/nakama/DefaultFriend.java b/src/main/java/com/heroiclabs/nakama/DefaultFriend.java new file mode 100644 index 00000000..7512d7d1 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultFriend.java @@ -0,0 +1,62 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.*; + +@Data +@ToString(includeFieldNames = true) +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +public class DefaultFriend implements Friend { + + private final String avatarUrl; + + private final long createdAt; + + private final String fullname; + + private final String handle; + + private final String id; + + private final String lang; + + private final long lastOnlineAt; + + private final String location; + + private final String metadata; + + private final String timezone; + + private final long updatedAt; + + private final FriendType state; + + public T getMetadata(final Class clazz) { + return DefaultClient.GSON.fromJson(metadata, clazz); + } + + static Friend fromProto(final @NonNull com.heroiclabs.nakama.Api.Friend friend) { + return new DefaultFriend(friend.getUser().getAvatarUrl(), friend.getUser().getCreatedAt(), + friend.getUser().getFullname(), friend.getUser().getHandle(), friend.getUser().getId(), + friend.getUser().getLang(), friend.getUser().getLastOnlineAt(), friend.getUser().getLocation(), + friend.getUser().getMetadata(), friend.getUser().getTimezone(), friend.getUser().getUpdatedAt(), + Friend.FriendType.fromLong(friend.getState())); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultFriendsAddMessage.java b/src/main/java/com/heroiclabs/nakama/DefaultFriendsAddMessage.java new file mode 100644 index 00000000..f5334c78 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultFriendsAddMessage.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultFriendsAddMessage implements FriendsAddMessage { + + private final com.heroiclabs.nakama.Api.Envelope.Builder payload; + + public byte[] asBytes(final @NonNull String collationId) { + return payload.clone().setCollationId(collationId).build().toByteArray(); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultFriendsBlockMessage.java b/src/main/java/com/heroiclabs/nakama/DefaultFriendsBlockMessage.java new file mode 100644 index 00000000..369dbbfe --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultFriendsBlockMessage.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultFriendsBlockMessage implements FriendsBlockMessage { + + private final com.heroiclabs.nakama.Api.Envelope.Builder payload; + + public byte[] asBytes(final @NonNull String collationId) { + return payload.clone().setCollationId(collationId).build().toByteArray(); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultFriendsListMessage.java b/src/main/java/com/heroiclabs/nakama/DefaultFriendsListMessage.java new file mode 100644 index 00000000..8d888b8f --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultFriendsListMessage.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultFriendsListMessage implements FriendsListMessage { + + private final com.heroiclabs.nakama.Api.Envelope.Builder payload; + + public byte[] asBytes(final @NonNull String collationId) { + return payload.clone().setCollationId(collationId).build().toByteArray(); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultFriendsRemoveMessage.java b/src/main/java/com/heroiclabs/nakama/DefaultFriendsRemoveMessage.java new file mode 100644 index 00000000..dd575b5d --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultFriendsRemoveMessage.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultFriendsRemoveMessage implements FriendsRemoveMessage { + + private final com.heroiclabs.nakama.Api.Envelope.Builder payload; + + public byte[] asBytes(final @NonNull String collationId) { + return payload.clone().setCollationId(collationId).build().toByteArray(); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultGroup.java b/src/main/java/com/heroiclabs/nakama/DefaultGroup.java new file mode 100644 index 00000000..14fb3511 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultGroup.java @@ -0,0 +1,54 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.*; + +@Data +@ToString(includeFieldNames = true) +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +public class DefaultGroup implements Group { + + private final String id; + @Getter(AccessLevel.PRIVATE) + private final boolean priv; + private final String creatorId; + private final String name; + private final String description; + private final String avatarUrl; + private final String lang; + private final long utcOffsetMs; + private final String metadata; + private final long count; + private final long createdAt; + private final long updatedAt; + + public boolean isPrivate() { + return priv; + } + + public T getMetadata(final Class clazz) { + return DefaultClient.GSON.fromJson(metadata, clazz); + } + + static Group fromProto(final @NonNull com.heroiclabs.nakama.Api.Group group) { + return new DefaultGroup(group.getId(), group.getPrivate(), group.getCreatorId(), group.getName(), + group.getDescription(), group.getAvatarUrl(), group.getLang(), group.getUtcOffsetMs(), + group.getMetadata(), group.getCount(), group.getCreatedAt(), group.getUpdatedAt()); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultGroupSelf.java b/src/main/java/com/heroiclabs/nakama/DefaultGroupSelf.java new file mode 100644 index 00000000..705f0034 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultGroupSelf.java @@ -0,0 +1,59 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.*; + +@Data +@ToString(includeFieldNames = true) +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +public class DefaultGroupSelf implements GroupSelf { + + private final String id; + @Getter(AccessLevel.PRIVATE) + private final boolean priv; + private final String creatorId; + private final String name; + private final String description; + private final String avatarUrl; + private final String lang; + private final long utcOffsetMs; + private final String metadata; + private final long count; + private final long createdAt; + private final long updatedAt; + private final Group.MembershipType state; + + public boolean isPrivate() { + return priv; + } + + public T getMetadata(final Class clazz) { + return DefaultClient.GSON.fromJson(metadata, clazz); + } + + static GroupSelf fromProto(final @NonNull com.heroiclabs.nakama.Api.TGroupsSelf.GroupSelf groupSelf) { + return new DefaultGroupSelf(groupSelf.getGroup().getId(), groupSelf.getGroup().getPrivate(), + groupSelf.getGroup().getCreatorId(), groupSelf.getGroup().getName(), + groupSelf.getGroup().getDescription(), groupSelf.getGroup().getAvatarUrl(), + groupSelf.getGroup().getLang(), groupSelf.getGroup().getUtcOffsetMs(), + groupSelf.getGroup().getMetadata(), groupSelf.getGroup().getCount(), + groupSelf.getGroup().getCreatedAt(), groupSelf.getGroup().getUpdatedAt(), + Group.MembershipType.fromLong(groupSelf.getState())); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultGroupUser.java b/src/main/java/com/heroiclabs/nakama/DefaultGroupUser.java new file mode 100644 index 00000000..80d6434e --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultGroupUser.java @@ -0,0 +1,63 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.*; + +@Data +@ToString(includeFieldNames = true) +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultGroupUser implements GroupUser { + + private final String avatarUrl; + + private final long createdAt; + + private final String fullname; + + private final String handle; + + private final String id; + + private final String lang; + + private final long lastOnlineAt; + + private final String location; + + private final String metadata; + + private final String timezone; + + private final long updatedAt; + + private final Group.MembershipType state; + + public T getMetadata(final Class clazz) { + return DefaultClient.GSON.fromJson(metadata, clazz); + } + + static GroupUser fromProto(final @NonNull com.heroiclabs.nakama.Api.GroupUser groupUser) { + return new DefaultGroupUser(groupUser.getUser().getAvatarUrl(), groupUser.getUser().getCreatedAt(), + groupUser.getUser().getFullname(), groupUser.getUser().getHandle(), groupUser.getUser().getId(), + groupUser.getUser().getLang(), groupUser.getUser().getLastOnlineAt(), + groupUser.getUser().getLocation(), groupUser.getUser().getMetadata(), + groupUser.getUser().getTimezone(), groupUser.getUser().getUpdatedAt(), + Group.MembershipType.fromLong(groupUser.getState())); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultGroupUsersAddMessage.java b/src/main/java/com/heroiclabs/nakama/DefaultGroupUsersAddMessage.java new file mode 100644 index 00000000..a34d0691 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultGroupUsersAddMessage.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultGroupUsersAddMessage implements GroupUsersAddMessage { + + private final com.heroiclabs.nakama.Api.Envelope.Builder payload; + + public byte[] asBytes(final @NonNull String collationId) { + return payload.clone().setCollationId(collationId).build().toByteArray(); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultGroupUsersKickMessage.java b/src/main/java/com/heroiclabs/nakama/DefaultGroupUsersKickMessage.java new file mode 100644 index 00000000..aff655dd --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultGroupUsersKickMessage.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultGroupUsersKickMessage implements GroupUsersKickMessage { + + private final com.heroiclabs.nakama.Api.Envelope.Builder payload; + + public byte[] asBytes(final @NonNull String collationId) { + return payload.clone().setCollationId(collationId).build().toByteArray(); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultGroupUsersListMessage.java b/src/main/java/com/heroiclabs/nakama/DefaultGroupUsersListMessage.java new file mode 100644 index 00000000..535e1795 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultGroupUsersListMessage.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultGroupUsersListMessage implements GroupUsersListMessage { + + private final com.heroiclabs.nakama.Api.Envelope.Builder payload; + + public byte[] asBytes(final @NonNull String collationId) { + return payload.clone().setCollationId(collationId).build().toByteArray(); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultGroupUsersPromoteMessage.java b/src/main/java/com/heroiclabs/nakama/DefaultGroupUsersPromoteMessage.java new file mode 100644 index 00000000..5870ce1e --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultGroupUsersPromoteMessage.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultGroupUsersPromoteMessage implements GroupUsersPromoteMessage { + + private final com.heroiclabs.nakama.Api.Envelope.Builder payload; + + public byte[] asBytes(final @NonNull String collationId) { + return payload.clone().setCollationId(collationId).build().toByteArray(); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultGroupsCreateMessage.java b/src/main/java/com/heroiclabs/nakama/DefaultGroupsCreateMessage.java new file mode 100644 index 00000000..229c46dd --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultGroupsCreateMessage.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultGroupsCreateMessage implements GroupsCreateMessage { + + private final com.heroiclabs.nakama.Api.Envelope.Builder payload; + + public byte[] asBytes(final @NonNull String collationId) { + return payload.clone().setCollationId(collationId).build().toByteArray(); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultGroupsFetchMessage.java b/src/main/java/com/heroiclabs/nakama/DefaultGroupsFetchMessage.java new file mode 100644 index 00000000..1014fdc8 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultGroupsFetchMessage.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultGroupsFetchMessage implements GroupsFetchMessage { + + private final com.heroiclabs.nakama.Api.Envelope.Builder payload; + + public byte[] asBytes(final @NonNull String collationId) { + return payload.clone().setCollationId(collationId).build().toByteArray(); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultGroupsJoinMessage.java b/src/main/java/com/heroiclabs/nakama/DefaultGroupsJoinMessage.java new file mode 100644 index 00000000..b3407a3b --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultGroupsJoinMessage.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultGroupsJoinMessage implements GroupsJoinMessage { + + private final com.heroiclabs.nakama.Api.Envelope.Builder payload; + + public byte[] asBytes(final @NonNull String collationId) { + return payload.clone().setCollationId(collationId).build().toByteArray(); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultGroupsLeaveMessage.java b/src/main/java/com/heroiclabs/nakama/DefaultGroupsLeaveMessage.java new file mode 100644 index 00000000..f0791617 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultGroupsLeaveMessage.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultGroupsLeaveMessage implements GroupsLeaveMessage { + + private final com.heroiclabs.nakama.Api.Envelope.Builder payload; + + public byte[] asBytes(final @NonNull String collationId) { + return payload.clone().setCollationId(collationId).build().toByteArray(); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultGroupsListMessage.java b/src/main/java/com/heroiclabs/nakama/DefaultGroupsListMessage.java new file mode 100644 index 00000000..ab836ea1 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultGroupsListMessage.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultGroupsListMessage implements GroupsListMessage { + + private final com.heroiclabs.nakama.Api.Envelope.Builder payload; + + public byte[] asBytes(final @NonNull String collationId) { + return payload.clone().setCollationId(collationId).build().toByteArray(); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultGroupsRemoveMessage.java b/src/main/java/com/heroiclabs/nakama/DefaultGroupsRemoveMessage.java new file mode 100644 index 00000000..8df6ad86 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultGroupsRemoveMessage.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultGroupsRemoveMessage implements GroupsRemoveMessage { + + private final com.heroiclabs.nakama.Api.Envelope.Builder payload; + + public byte[] asBytes(final @NonNull String collationId) { + return payload.clone().setCollationId(collationId).build().toByteArray(); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultGroupsSelfListMessage.java b/src/main/java/com/heroiclabs/nakama/DefaultGroupsSelfListMessage.java new file mode 100644 index 00000000..e0013ee0 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultGroupsSelfListMessage.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultGroupsSelfListMessage implements GroupsSelfListMessage { + + private final com.heroiclabs.nakama.Api.Envelope.Builder payload; + + public byte[] asBytes(final @NonNull String collationId) { + return payload.clone().setCollationId(collationId).build().toByteArray(); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultGroupsUpdateMessage.java b/src/main/java/com/heroiclabs/nakama/DefaultGroupsUpdateMessage.java new file mode 100644 index 00000000..5f14918d --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultGroupsUpdateMessage.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultGroupsUpdateMessage implements GroupsUpdateMessage { + + private final com.heroiclabs.nakama.Api.Envelope.Builder payload; + + public byte[] asBytes(final @NonNull String collationId) { + return payload.clone().setCollationId(collationId).build().toByteArray(); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultLeaderboard.java b/src/main/java/com/heroiclabs/nakama/DefaultLeaderboard.java index 11835b7f..44384f16 100644 --- a/src/main/java/com/heroiclabs/nakama/DefaultLeaderboard.java +++ b/src/main/java/com/heroiclabs/nakama/DefaultLeaderboard.java @@ -24,7 +24,7 @@ class DefaultLeaderboard implements Leaderboard { private final String id; private final boolean authoritative; - private final long sort; + private final SortOrder sort; private final long count; private final String resetSchedule; private final String metadata; @@ -39,7 +39,7 @@ static Leaderboard fromProto(final @NonNull com.heroiclabs.nakama.Api.Leaderboar return new DefaultLeaderboard( leaderboard.getId(), leaderboard.getAuthoritative(), - leaderboard.getSort(), + Leaderboard.SortOrder.fromLong(leaderboard.getSort()), leaderboard.getCount(), leaderboard.getResetSchedule(), leaderboard.getMetadata(), diff --git a/src/main/java/com/heroiclabs/nakama/DefaultNotification.java b/src/main/java/com/heroiclabs/nakama/DefaultNotification.java new file mode 100644 index 00000000..7aa70a91 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultNotification.java @@ -0,0 +1,40 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.*; + +@Data +@ToString(includeFieldNames = true) +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultNotification implements Notification { + private final String id; + private final String subject; + private final String content; + private final long code; + private final String senderId; + private final long createdAt; + private final long expiresAt; + private final boolean persistent; + + static Notification fromProto(final @NonNull com.heroiclabs.nakama.Api.Notification notification) { + return new DefaultNotification(notification.getId(), notification.getSubject(), notification.getContent(), + notification.getCode(), notification.getSenderId(), notification.getCreatedAt(), + notification.getExpiresAt(), notification.getPersistent()); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultNotificationsListMessage.java b/src/main/java/com/heroiclabs/nakama/DefaultNotificationsListMessage.java new file mode 100644 index 00000000..66b276f6 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultNotificationsListMessage.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultNotificationsListMessage implements NotificationsListMessage { + + private final com.heroiclabs.nakama.Api.Envelope.Builder payload; + + public byte[] asBytes(final @NonNull String collationId) { + return payload.clone().setCollationId(collationId).build().toByteArray(); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/DefaultNotificationsRemoveMessage.java b/src/main/java/com/heroiclabs/nakama/DefaultNotificationsRemoveMessage.java new file mode 100644 index 00000000..250f83c3 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/DefaultNotificationsRemoveMessage.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class DefaultNotificationsRemoveMessage implements NotificationsRemoveMessage { + + private final com.heroiclabs.nakama.Api.Envelope.Builder payload; + + public byte[] asBytes(final @NonNull String collationId) { + return payload.clone().setCollationId(collationId).build().toByteArray(); + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/Friend.java b/src/main/java/com/heroiclabs/nakama/Friend.java new file mode 100644 index 00000000..86e40b65 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/Friend.java @@ -0,0 +1,61 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +public interface Friend extends User { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + enum FriendType { + /** A standard friend relationship. */ + FRIEND(0), + /** An incoming friend request. */ + INVITE(1), + /** A sent friend request. */ + INVITED(2), + /** A blocked user. */ + BLOCKED(3); + + @Getter + private final int code; + + static Friend.FriendType fromLong(final long state) { + switch ((int) state) { + case 0: + return FRIEND; + case 1: + return INVITE; + case 2: + return INVITED; + case 3: + return BLOCKED; + default: + String message = String.format("Unrecognised friend state type: %s", state); + throw new IllegalArgumentException(message); + } + } + } + + /** + * @return An enum representing the type of relationship to this friend. + */ + FriendType getState(); + +} diff --git a/src/main/java/com/heroiclabs/nakama/FriendsAddMessage.java b/src/main/java/com/heroiclabs/nakama/FriendsAddMessage.java new file mode 100644 index 00000000..cfb108a3 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/FriendsAddMessage.java @@ -0,0 +1,57 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +public interface FriendsAddMessage extends CollatedMessage { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class Builder { + + public static FriendsAddMessage.Builder newBuilder() { + return new FriendsAddMessage.Builder(com.heroiclabs.nakama.Api.TFriendsAdd.newBuilder()); + } + + private final @NonNull + com.heroiclabs.nakama.Api.TFriendsAdd.Builder adds; + + public FriendsAddMessage.Builder id(final @NonNull String userId) { + this.adds.addFriends(com.heroiclabs.nakama.Api.TFriendsAdd.FriendsAdd.newBuilder() + .setUserId(userId) + .build()); + return this; + } + + public FriendsAddMessage.Builder handle(final @NonNull String handle) { + this.adds.addFriends(com.heroiclabs.nakama.Api.TFriendsAdd.FriendsAdd.newBuilder() + .setHandle(handle) + .build()); + return this; + } + + public FriendsAddMessage build() { + final com.heroiclabs.nakama.Api.Envelope.Builder payload = + com.heroiclabs.nakama.Api.Envelope.newBuilder() + .setFriendsAdd(adds); + return new DefaultFriendsAddMessage(payload); + } + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/FriendsBlockMessage.java b/src/main/java/com/heroiclabs/nakama/FriendsBlockMessage.java new file mode 100644 index 00000000..31cc6de8 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/FriendsBlockMessage.java @@ -0,0 +1,48 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +public interface FriendsBlockMessage extends CollatedMessage { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class Builder { + + public static FriendsBlockMessage.Builder newBuilder() { + return new FriendsBlockMessage.Builder(com.heroiclabs.nakama.Api.TFriendsBlock.newBuilder()); + } + + private final @NonNull + com.heroiclabs.nakama.Api.TFriendsBlock.Builder blocks; + + public FriendsBlockMessage.Builder id(final @NonNull String userId) { + this.blocks.addUserIds(userId); + return this; + } + + public FriendsBlockMessage build() { + final com.heroiclabs.nakama.Api.Envelope.Builder payload = + com.heroiclabs.nakama.Api.Envelope.newBuilder() + .setFriendsBlock(blocks); + return new DefaultFriendsBlockMessage(payload); + } + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/FriendsListMessage.java b/src/main/java/com/heroiclabs/nakama/FriendsListMessage.java new file mode 100644 index 00000000..019a5cbb --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/FriendsListMessage.java @@ -0,0 +1,35 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; + +public interface FriendsListMessage extends CollatedMessage> { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class Builder { + + public static FriendsListMessage build() { + final com.heroiclabs.nakama.Api.Envelope.Builder payload = + com.heroiclabs.nakama.Api.Envelope.newBuilder() + .setFriendsList(com.heroiclabs.nakama.Api.TFriendsList.newBuilder().build()); + return new DefaultFriendsListMessage(payload); + } + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/FriendsRemoveMessage.java b/src/main/java/com/heroiclabs/nakama/FriendsRemoveMessage.java new file mode 100644 index 00000000..d79e0aa2 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/FriendsRemoveMessage.java @@ -0,0 +1,48 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +public interface FriendsRemoveMessage extends CollatedMessage { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class Builder { + + public static FriendsRemoveMessage.Builder newBuilder() { + return new FriendsRemoveMessage.Builder(com.heroiclabs.nakama.Api.TFriendsRemove.newBuilder()); + } + + private final @NonNull + com.heroiclabs.nakama.Api.TFriendsRemove.Builder removes; + + public FriendsRemoveMessage.Builder id(final @NonNull String userId) { + this.removes.addUserIds(userId); + return this; + } + + public FriendsRemoveMessage build() { + final com.heroiclabs.nakama.Api.Envelope.Builder payload = + com.heroiclabs.nakama.Api.Envelope.newBuilder() + .setFriendsRemove(removes); + return new DefaultFriendsRemoveMessage(payload); + } + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/Group.java b/src/main/java/com/heroiclabs/nakama/Group.java new file mode 100644 index 00000000..84f6bda6 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/Group.java @@ -0,0 +1,122 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +/** + * Represents a group with user members. + */ +public interface Group { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + enum MembershipType { + /** The user is a group administrator. */ + ADMIN(0), + /** The user is a regular group member. */ + MEMBER(1), + /** The user has submitted a request to join the group. */ + JOIN(2); + + @Getter + private final int code; + + static Group.MembershipType fromLong(final long state) { + switch ((int) state) { + case 0: + return ADMIN; + case 1: + return MEMBER; + case 2: + return JOIN; + default: + String message = String.format("Unrecognised group state type: %s", state); + throw new IllegalArgumentException(message); + } + } + } + + /** + * @return The group unique ID. + */ + String getId(); + + /** + * @return true if it's a private group requiring approval to join, false otherwise. + */ + boolean isPrivate(); + + /** + * @return The ID of the user that created the group. + */ + String getCreatorId(); + + /** + * @return The name of the group. + */ + String getName(); + + /** + * @return The group's description. + */ + String getDescription(); + + /** + * @return The group's avatar URL. + */ + String getAvatarUrl(); + + /** + * @return The group's lang tag. + */ + String getLang(); + + /** + * @return The offset in milliseconds representing the group's timezone relative to UTC. + */ + long getUtcOffsetMs(); + + /** + * @return The metadata stored for the group. + */ + String getMetadata(); + + /** + * @param clazz A hint for the type of the class. + * @param A type parameter for the metadata to decode. + * @return The decoded metadata for the group. + */ + T getMetadata(final Class clazz); + + /** + * @return The number of group members. + */ + long getCount(); + + /** + * @return The UTC milliseconds timestamp when the group was created. + */ + long getCreatedAt(); + + /** + * @return The UTC milliseconds timestamp when the group data was last updated. + */ + long getUpdatedAt(); + +} diff --git a/src/main/java/com/heroiclabs/nakama/GroupSelf.java b/src/main/java/com/heroiclabs/nakama/GroupSelf.java new file mode 100644 index 00000000..b02dd66b --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/GroupSelf.java @@ -0,0 +1,29 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +/** + * Represents a group with additional information about the current user's membership type. + */ +public interface GroupSelf extends Group { + + /** + * @return An enum representing the user's relationship to the group. + */ + Group.MembershipType getState(); + +} diff --git a/src/main/java/com/heroiclabs/nakama/GroupUser.java b/src/main/java/com/heroiclabs/nakama/GroupUser.java new file mode 100644 index 00000000..c4998523 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/GroupUser.java @@ -0,0 +1,29 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +/** + * Represents details about a user belonging to a group. + */ +public interface GroupUser extends User { + + /** + * @return An enum representing the user's relationship to the group. + */ + Group.MembershipType getState(); + +} diff --git a/src/main/java/com/heroiclabs/nakama/GroupUsersAddMessage.java b/src/main/java/com/heroiclabs/nakama/GroupUsersAddMessage.java new file mode 100644 index 00000000..d7403e36 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/GroupUsersAddMessage.java @@ -0,0 +1,51 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +public interface GroupUsersAddMessage extends CollatedMessage { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class Builder { + + public static GroupUsersAddMessage.Builder newBuilder() { + return new GroupUsersAddMessage.Builder(com.heroiclabs.nakama.Api.TGroupUsersAdd.newBuilder()); + } + + private final @NonNull + com.heroiclabs.nakama.Api.TGroupUsersAdd.Builder adds; + + public GroupUsersAddMessage.Builder add(final @NonNull String groupId, final @NonNull String userId) { + this.adds.addGroupUsers(com.heroiclabs.nakama.Api.TGroupUsersAdd.GroupUserAdd.newBuilder() + .setGroupId(groupId) + .setUserId(userId) + .build()); + return this; + } + + public GroupUsersAddMessage build() { + final com.heroiclabs.nakama.Api.Envelope.Builder payload = + com.heroiclabs.nakama.Api.Envelope.newBuilder() + .setGroupUsersAdd(adds); + return new DefaultGroupUsersAddMessage(payload); + } + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/GroupUsersKickMessage.java b/src/main/java/com/heroiclabs/nakama/GroupUsersKickMessage.java new file mode 100644 index 00000000..7089f7bd --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/GroupUsersKickMessage.java @@ -0,0 +1,51 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +public interface GroupUsersKickMessage extends CollatedMessage { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class Builder { + + public static GroupUsersKickMessage.Builder newBuilder() { + return new GroupUsersKickMessage.Builder(com.heroiclabs.nakama.Api.TGroupUsersKick.newBuilder()); + } + + private final @NonNull + com.heroiclabs.nakama.Api.TGroupUsersKick.Builder kicks; + + public GroupUsersKickMessage.Builder add(final @NonNull String groupId, final @NonNull String userId) { + this.kicks.addGroupUsers(com.heroiclabs.nakama.Api.TGroupUsersKick.GroupUserKick.newBuilder() + .setGroupId(groupId) + .setUserId(userId) + .build()); + return this; + } + + public GroupUsersKickMessage build() { + final com.heroiclabs.nakama.Api.Envelope.Builder payload = + com.heroiclabs.nakama.Api.Envelope.newBuilder() + .setGroupUsersKick(kicks); + return new DefaultGroupUsersKickMessage(payload); + } + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/GroupUsersListMessage.java b/src/main/java/com/heroiclabs/nakama/GroupUsersListMessage.java new file mode 100644 index 00000000..fca936a6 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/GroupUsersListMessage.java @@ -0,0 +1,38 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +public interface GroupUsersListMessage extends CollatedMessage> { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class Builder { + + public static GroupUsersListMessage build(final @NonNull String groupId) { + final com.heroiclabs.nakama.Api.Envelope.Builder payload = + com.heroiclabs.nakama.Api.Envelope.newBuilder() + .setGroupUsersList(com.heroiclabs.nakama.Api.TGroupUsersList.newBuilder() + .setGroupId(groupId) + .build()); + return new DefaultGroupUsersListMessage(payload); + } + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/GroupUsersPromoteMessage.java b/src/main/java/com/heroiclabs/nakama/GroupUsersPromoteMessage.java new file mode 100644 index 00000000..100689c3 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/GroupUsersPromoteMessage.java @@ -0,0 +1,51 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +public interface GroupUsersPromoteMessage extends CollatedMessage { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class Builder { + + public static GroupUsersPromoteMessage.Builder newBuilder() { + return new GroupUsersPromoteMessage.Builder(com.heroiclabs.nakama.Api.TGroupUsersPromote.newBuilder()); + } + + private final @NonNull + com.heroiclabs.nakama.Api.TGroupUsersPromote.Builder promotes; + + public GroupUsersPromoteMessage.Builder add(final @NonNull String groupId, final @NonNull String userId) { + this.promotes.addGroupUsers(com.heroiclabs.nakama.Api.TGroupUsersPromote.GroupUserPromote.newBuilder() + .setGroupId(groupId) + .setUserId(userId) + .build()); + return this; + } + + public GroupUsersPromoteMessage build() { + final com.heroiclabs.nakama.Api.Envelope.Builder payload = + com.heroiclabs.nakama.Api.Envelope.newBuilder() + .setGroupUsersPromote(promotes); + return new DefaultGroupUsersPromoteMessage(payload); + } + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/GroupsCreateMessage.java b/src/main/java/com/heroiclabs/nakama/GroupsCreateMessage.java new file mode 100644 index 00000000..dd948f2e --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/GroupsCreateMessage.java @@ -0,0 +1,64 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +public interface GroupsCreateMessage extends CollatedMessage> { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class Builder { + + public static GroupsCreateMessage.Builder newBuilder() { + return new GroupsCreateMessage.Builder(com.heroiclabs.nakama.Api.TGroupsCreate.newBuilder()); + } + + private final @NonNull + com.heroiclabs.nakama.Api.TGroupsCreate.Builder creates; + + public GroupsCreateMessage.Builder group(final @NonNull String name, final String description, + final String avatarUrl, final String lang, + final @NonNull String metadata, final boolean isPrivate) { + com.heroiclabs.nakama.Api.TGroupsCreate.GroupCreate.Builder g = + com.heroiclabs.nakama.Api.TGroupsCreate.GroupCreate.newBuilder() + .setName(name) + .setMetadata(metadata) + .setPrivate(isPrivate); + if (description != null) { + g.setDescription(description); + } + if (avatarUrl != null) { + g.setAvatarUrl(avatarUrl); + } + if (lang != null) { + g.setLang(lang); + } + this.creates.addGroups(g.build()); + return this; + } + + public GroupsCreateMessage build() { + final com.heroiclabs.nakama.Api.Envelope.Builder payload = + com.heroiclabs.nakama.Api.Envelope.newBuilder() + .setGroupsCreate(creates); + return new DefaultGroupsCreateMessage(payload); + } + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/GroupsFetchMessage.java b/src/main/java/com/heroiclabs/nakama/GroupsFetchMessage.java new file mode 100644 index 00000000..1513090a --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/GroupsFetchMessage.java @@ -0,0 +1,57 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +public interface GroupsFetchMessage extends CollatedMessage> { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class Builder { + + public static GroupsFetchMessage.Builder newBuilder() { + return new GroupsFetchMessage.Builder(com.heroiclabs.nakama.Api.TGroupsFetch.newBuilder()); + } + + private final @NonNull + com.heroiclabs.nakama.Api.TGroupsFetch.Builder fetches; + + public GroupsFetchMessage.Builder id(final @NonNull String groupId) { + this.fetches.addGroups(com.heroiclabs.nakama.Api.TGroupsFetch.GroupFetch.newBuilder() + .setGroupId(groupId) + .build()); + return this; + } + + public GroupsFetchMessage.Builder name(final @NonNull String name) { + this.fetches.addGroups(com.heroiclabs.nakama.Api.TGroupsFetch.GroupFetch.newBuilder() + .setName(name) + .build()); + return this; + } + + public GroupsFetchMessage build() { + final com.heroiclabs.nakama.Api.Envelope.Builder payload = + com.heroiclabs.nakama.Api.Envelope.newBuilder() + .setGroupsFetch(fetches); + return new DefaultGroupsFetchMessage(payload); + } + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/GroupsJoinMessage.java b/src/main/java/com/heroiclabs/nakama/GroupsJoinMessage.java new file mode 100644 index 00000000..61102fd1 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/GroupsJoinMessage.java @@ -0,0 +1,48 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +public interface GroupsJoinMessage extends CollatedMessage { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class Builder { + + public static GroupsJoinMessage.Builder newBuilder() { + return new GroupsJoinMessage.Builder(com.heroiclabs.nakama.Api.TGroupsJoin.newBuilder()); + } + + private final @NonNull + com.heroiclabs.nakama.Api.TGroupsJoin.Builder joins; + + public GroupsJoinMessage.Builder id(final @NonNull String groupId) { + this.joins.addGroupIds(groupId); + return this; + } + + public GroupsJoinMessage build() { + final com.heroiclabs.nakama.Api.Envelope.Builder payload = + com.heroiclabs.nakama.Api.Envelope.newBuilder() + .setGroupsJoin(joins); + return new DefaultGroupsJoinMessage(payload); + } + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/GroupsLeaveMessage.java b/src/main/java/com/heroiclabs/nakama/GroupsLeaveMessage.java new file mode 100644 index 00000000..56ca0e68 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/GroupsLeaveMessage.java @@ -0,0 +1,48 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +public interface GroupsLeaveMessage extends CollatedMessage { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class Builder { + + public static GroupsLeaveMessage.Builder newBuilder() { + return new GroupsLeaveMessage.Builder(com.heroiclabs.nakama.Api.TGroupsLeave.newBuilder()); + } + + private final @NonNull + com.heroiclabs.nakama.Api.TGroupsLeave.Builder leaves; + + public GroupsLeaveMessage.Builder id(final @NonNull String groupId) { + this.leaves.addGroupIds(groupId); + return this; + } + + public GroupsLeaveMessage build() { + final com.heroiclabs.nakama.Api.Envelope.Builder payload = + com.heroiclabs.nakama.Api.Envelope.newBuilder() + .setGroupsLeave(leaves); + return new DefaultGroupsLeaveMessage(payload); + } + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/GroupsListMessage.java b/src/main/java/com/heroiclabs/nakama/GroupsListMessage.java new file mode 100644 index 00000000..a9c25a01 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/GroupsListMessage.java @@ -0,0 +1,76 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +public interface GroupsListMessage extends CollatedMessage> { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class Builder { + + public static GroupsListMessage.Builder newBuilder() { + return new GroupsListMessage.Builder(com.heroiclabs.nakama.Api.TGroupsList.newBuilder()); + } + + private final @NonNull + com.heroiclabs.nakama.Api.TGroupsList.Builder list; + + public GroupsListMessage.Builder limit(final long limit) { + this.list.setPageLimit(limit); + return this; + } + + public GroupsListMessage.Builder orderAscending(final boolean orderAscending) { + this.list.setOrderByAsc(orderAscending); + return this; + } + + public GroupsListMessage.Builder filterByLang(final @NonNull String lang) { + this.list.clearFilter(); + this.list.setLang(lang); + return this; + } + + public GroupsListMessage.Builder filterByCreatedAt(final long createdAt) { + this.list.clearFilter(); + this.list.setCreatedAt(createdAt); + return this; + } + + public GroupsListMessage.Builder filterByCount(final long count) { + this.list.clearFilter(); + this.list.setCount(count); + return this; + } + + public GroupsListMessage.Builder cursor(final @NonNull Cursor cursor) { + this.list.setCursor(cursor.getValue()); + return this; + } + + public GroupsListMessage build() { + final com.heroiclabs.nakama.Api.Envelope.Builder payload = + com.heroiclabs.nakama.Api.Envelope.newBuilder() + .setGroupsList(list); + return new DefaultGroupsListMessage(payload); + } + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/GroupsRemoveMessage.java b/src/main/java/com/heroiclabs/nakama/GroupsRemoveMessage.java new file mode 100644 index 00000000..82829057 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/GroupsRemoveMessage.java @@ -0,0 +1,48 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +public interface GroupsRemoveMessage extends CollatedMessage { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class Builder { + + public static GroupsRemoveMessage.Builder newBuilder() { + return new GroupsRemoveMessage.Builder(com.heroiclabs.nakama.Api.TGroupsRemove.newBuilder()); + } + + private final @NonNull + com.heroiclabs.nakama.Api.TGroupsRemove.Builder removes; + + public GroupsRemoveMessage.Builder id(final @NonNull String groupId) { + this.removes.addGroupIds(groupId); + return this; + } + + public GroupsRemoveMessage build() { + final com.heroiclabs.nakama.Api.Envelope.Builder payload = + com.heroiclabs.nakama.Api.Envelope.newBuilder() + .setGroupsRemove(removes); + return new DefaultGroupsRemoveMessage(payload); + } + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/GroupsSelfListMessage.java b/src/main/java/com/heroiclabs/nakama/GroupsSelfListMessage.java new file mode 100644 index 00000000..2580ba49 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/GroupsSelfListMessage.java @@ -0,0 +1,35 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; + +public interface GroupsSelfListMessage extends CollatedMessage> { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class Builder { + + public static GroupsSelfListMessage build() { + final com.heroiclabs.nakama.Api.Envelope.Builder payload = + com.heroiclabs.nakama.Api.Envelope.newBuilder() + .setGroupsSelfList(com.heroiclabs.nakama.Api.TGroupsSelfList.newBuilder().build()); + return new DefaultGroupsSelfListMessage(payload); + } + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/GroupsUpdateMessage.java b/src/main/java/com/heroiclabs/nakama/GroupsUpdateMessage.java new file mode 100644 index 00000000..8af8474c --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/GroupsUpdateMessage.java @@ -0,0 +1,66 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +public interface GroupsUpdateMessage extends CollatedMessage { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class Builder { + + public static GroupsUpdateMessage.Builder newBuilder() { + return new GroupsUpdateMessage.Builder(com.heroiclabs.nakama.Api.TGroupsUpdate.newBuilder()); + } + + private final @NonNull + com.heroiclabs.nakama.Api.TGroupsUpdate.Builder updates; + + public GroupsUpdateMessage.Builder group(final @NonNull String groupId, + final @NonNull String name, final String description, + final String avatarUrl, final String lang, + final @NonNull String metadata, final boolean isPrivate) { + com.heroiclabs.nakama.Api.TGroupsUpdate.GroupUpdate.Builder g = + com.heroiclabs.nakama.Api.TGroupsUpdate.GroupUpdate.newBuilder() + .setGroupId(groupId) + .setName(name) + .setMetadata(metadata) + .setPrivate(isPrivate); + if (description != null) { + g.setDescription(description); + } + if (avatarUrl != null) { + g.setAvatarUrl(avatarUrl); + } + if (lang != null) { + g.setLang(lang); + } + this.updates.addGroups(g.build()); + return this; + } + + public GroupsUpdateMessage build() { + final com.heroiclabs.nakama.Api.Envelope.Builder payload = + com.heroiclabs.nakama.Api.Envelope.newBuilder() + .setGroupsUpdate(updates); + return new DefaultGroupsUpdateMessage(payload); + } + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/Leaderboard.java b/src/main/java/com/heroiclabs/nakama/Leaderboard.java index ab186910..091734c0 100644 --- a/src/main/java/com/heroiclabs/nakama/Leaderboard.java +++ b/src/main/java/com/heroiclabs/nakama/Leaderboard.java @@ -16,10 +16,36 @@ package com.heroiclabs.nakama; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + /** * The object which represents a leaderboard object. */ public interface Leaderboard { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + enum SortOrder { + ASCENDING(0), + DESCENDING(1); + + @Getter + private final int code; + + static Leaderboard.SortOrder fromLong(final long sort) { + switch ((int) sort) { + case 0: + return ASCENDING; + case 1: + return DESCENDING; + default: + String message = String.format("Unrecognised leaderboard sort order: %s", sort); + throw new IllegalArgumentException(message); + } + } + } + /** * @return Leaderboard ID. */ @@ -33,7 +59,7 @@ public interface Leaderboard { /** * @return Sort order for the record. */ - long getSort(); + SortOrder getSort(); /** * @return Record count. diff --git a/src/main/java/com/heroiclabs/nakama/LeaderboardRecordsListMessage.java b/src/main/java/com/heroiclabs/nakama/LeaderboardRecordsListMessage.java index f76a7f1b..f2b91b59 100644 --- a/src/main/java/com/heroiclabs/nakama/LeaderboardRecordsListMessage.java +++ b/src/main/java/com/heroiclabs/nakama/LeaderboardRecordsListMessage.java @@ -65,8 +65,8 @@ public LeaderboardRecordsListMessage.Builder limit(final long limit) { return this; } - public LeaderboardRecordsListMessage.Builder cursor(final @NonNull String cursor) { - listing.setCursor(cursor); + public LeaderboardRecordsListMessage.Builder cursor(final @NonNull Cursor cursor) { + listing.setCursor(cursor.getValue()); return this; } diff --git a/src/main/java/com/heroiclabs/nakama/NoopClientListener.java b/src/main/java/com/heroiclabs/nakama/NoopClientListener.java index 7c361d48..fb8411d7 100644 --- a/src/main/java/com/heroiclabs/nakama/NoopClientListener.java +++ b/src/main/java/com/heroiclabs/nakama/NoopClientListener.java @@ -16,6 +16,8 @@ package com.heroiclabs.nakama; +import java.util.List; + /** * Default implementation of client listener, all operations are no-op. */ @@ -26,4 +28,5 @@ public class NoopClientListener implements ClientListener { @Override public void onMatchmakeMatched(MatchmakeMatched matched) {} @Override public void onMatchData(MatchData matchData) {} @Override public void onMatchPresence(MatchPresence matchPresence) {} + @Override public void onNotifications(List notifications) {} } diff --git a/src/main/java/com/heroiclabs/nakama/Notification.java b/src/main/java/com/heroiclabs/nakama/Notification.java new file mode 100644 index 00000000..ae0fc0f5 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/Notification.java @@ -0,0 +1,63 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +/** + * Represents a notification aimed at a particular user. + */ +public interface Notification { + /** + * @return The unique ID of the notification. + */ + String getId(); + + /** + * @return The subject text. + */ + String getSubject(); + + /** + * @return The notification body. + */ + String getContent(); + + /** + * @return The notification code. + */ + long getCode(); + + /** + * @return The user ID of the sender, or an empty string if it's a system notification. + */ + String getSenderId(); + + /** + * @return The UTC milliseconds timestamp when the notification was created. + */ + long getCreatedAt(); + + /** + * @return The UTC milliseconds timestamp when the notification expires. + */ + long getExpiresAt(); + + /** + * @return true if the notification was persisted and may be retrieved later, false if + * the notification was only delivered and not stored. + */ + boolean isPersistent(); +} diff --git a/src/main/java/com/heroiclabs/nakama/NotificationsListMessage.java b/src/main/java/com/heroiclabs/nakama/NotificationsListMessage.java new file mode 100644 index 00000000..820c8929 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/NotificationsListMessage.java @@ -0,0 +1,49 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +public interface NotificationsListMessage extends CollatedMessage> { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class Builder { + + public static NotificationsListMessage.Builder newBuilder(final long limit) { + return new NotificationsListMessage.Builder(com.heroiclabs.nakama.Api.TNotificationsList.newBuilder() + .setLimit(limit)); + } + + private final @NonNull + com.heroiclabs.nakama.Api.TNotificationsList.Builder list; + + public NotificationsListMessage.Builder cursor(final @NonNull Cursor cursor) { + this.list.setResumableCursor(cursor.getValue()); + return this; + } + + public NotificationsListMessage build() { + final com.heroiclabs.nakama.Api.Envelope.Builder payload = + com.heroiclabs.nakama.Api.Envelope.newBuilder() + .setNotificationsList(list); + return new DefaultNotificationsListMessage(payload); + } + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/NotificationsRemoveMessage.java b/src/main/java/com/heroiclabs/nakama/NotificationsRemoveMessage.java new file mode 100644 index 00000000..12418a17 --- /dev/null +++ b/src/main/java/com/heroiclabs/nakama/NotificationsRemoveMessage.java @@ -0,0 +1,53 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import lombok.AccessLevel; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +public interface NotificationsRemoveMessage extends CollatedMessage { + + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class Builder { + + public static NotificationsRemoveMessage.Builder newBuilder() { + return new NotificationsRemoveMessage.Builder(com.heroiclabs.nakama.Api.TNotificationsRemove.newBuilder()); + } + + private final @NonNull + com.heroiclabs.nakama.Api.TNotificationsRemove.Builder removes; + + public NotificationsRemoveMessage.Builder id(final @NonNull String notificationId) { + this.removes.addNotificationIds(notificationId); + return this; + } + + public NotificationsRemoveMessage.Builder ids(final @NonNull Iterable notificationIds) { + this.removes.addAllNotificationIds(notificationIds); + return this; + } + + public NotificationsRemoveMessage build() { + final com.heroiclabs.nakama.Api.Envelope.Builder payload = + com.heroiclabs.nakama.Api.Envelope.newBuilder() + .setNotificationsRemove(removes); + return new DefaultNotificationsRemoveMessage(payload); + } + } + +} diff --git a/src/main/java/com/heroiclabs/nakama/TopicLeaveMessage.java b/src/main/java/com/heroiclabs/nakama/TopicLeaveMessage.java index 794f89b7..c67fb0be 100644 --- a/src/main/java/com/heroiclabs/nakama/TopicLeaveMessage.java +++ b/src/main/java/com/heroiclabs/nakama/TopicLeaveMessage.java @@ -32,7 +32,7 @@ public static TopicLeaveMessage.Builder newBuilder() { private final @NonNull com.heroiclabs.nakama.Api.TTopicsLeave.Builder leaves; - public TopicLeaveMessage.Builder Leave(final @NonNull TopicId topicId) { + public TopicLeaveMessage.Builder leave(final @NonNull TopicId topicId) { com.heroiclabs.nakama.Api.TTopicsLeave.Builder topicLeave = com.heroiclabs.nakama.Api.TTopicsLeave.newBuilder(); com.heroiclabs.nakama.Api.TopicId.Builder topicBuilder = null; switch (topicId.getTopicType()) { diff --git a/src/test/java/com/heroiclabs/nakama/FriendsAddMessageTest.java b/src/test/java/com/heroiclabs/nakama/FriendsAddMessageTest.java new file mode 100644 index 00000000..51aabc2c --- /dev/null +++ b/src/test/java/com/heroiclabs/nakama/FriendsAddMessageTest.java @@ -0,0 +1,170 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import com.stumbleupon.async.Callback; +import com.stumbleupon.async.Deferred; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.UUID; + +public class FriendsAddMessageTest { + + private Client client1; + private Client client2; + + private Session session1; + private Session session2; + + @Before + public void init() throws Exception { + client1 = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client1); + + client2 = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client2); + + AuthenticateMessage auth1 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred1 = client1.register(auth1); + deferred1.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session session) throws Exception { + return client1.connect(session); + } + }).addCallback(new Callback() { + @Override + public Session call(Session session) throws Exception { + session1 = session; + return session; + } + }).join(2000); + + AuthenticateMessage auth2 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred2 = client2.register(auth2); + deferred2.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session session) throws Exception { + return client2.connect(session); + } + }).addCallback(new Callback() { + @Override + public Session call(Session session) throws Exception { + session2 = session; + return session; + } + }).join(2000); + } + + @After + public void teardown() throws Exception { + client1.disconnect().join(2000); + client2.disconnect().join(2000); + } + + @Test(expected = Error.class) + public void friendsAddNotFound() throws Exception { + FriendsAddMessage add = FriendsAddMessage.Builder.newBuilder().id(UUID.randomUUID().toString()).build(); + final Deferred deferred = client1.send(add); + deferred.addCallback(new Callback() { + @Override + public Boolean call(Boolean success) throws Exception { + Assert.fail("Should not reach this point."); + return success; + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.assertEquals(Error.ErrorCode.RUNTIME_EXCEPTION, error.getCode()); + return error; + } + }); + deferred.join(2000); + Assert.fail("Should not reach this point."); + } + + @Test + public void friendsAddIdRequest() throws Exception { + FriendsAddMessage add = FriendsAddMessage.Builder.newBuilder().id(session2.getId()).build(); + final Deferred deferred = client1.send(add); + deferred.addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + + @Test + public void friendsAddHandleRequest() throws Exception { + FriendsAddMessage add = FriendsAddMessage.Builder.newBuilder().handle(session2.getHandle()).build(); + final Deferred deferred = client1.send(add); + deferred.addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + + @Test + public void friendsAddIdMutual() throws Exception { + FriendsAddMessage add1 = FriendsAddMessage.Builder.newBuilder().id(session2.getId()).build(); + final Deferred deferred = client1.send(add1); + deferred.addCallbackDeferring(new Callback, Boolean>() { + @Override + public Deferred call(Boolean success) throws Exception { + FriendsAddMessage add2 = FriendsAddMessage.Builder.newBuilder().id(session1.getId()).build(); + return client2.send(add2); + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + + @Test + public void friendsAddHandleMutual() throws Exception { + FriendsAddMessage add1 = FriendsAddMessage.Builder.newBuilder().handle(session2.getHandle()).build(); + final Deferred deferred = client1.send(add1); + deferred.addCallbackDeferring(new Callback, Boolean>() { + @Override + public Deferred call(Boolean success) throws Exception { + FriendsAddMessage add2 = FriendsAddMessage.Builder.newBuilder().handle(session1.getHandle()).build(); + return client2.send(add2); + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + +} diff --git a/src/test/java/com/heroiclabs/nakama/FriendsBlockMessageTest.java b/src/test/java/com/heroiclabs/nakama/FriendsBlockMessageTest.java new file mode 100644 index 00000000..d92e6763 --- /dev/null +++ b/src/test/java/com/heroiclabs/nakama/FriendsBlockMessageTest.java @@ -0,0 +1,142 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import com.stumbleupon.async.Callback; +import com.stumbleupon.async.Deferred; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.UUID; + +public class FriendsBlockMessageTest { + + private Client client1; + private Client client2; + + private Session session1; + private Session session2; + + @Before + public void init() throws Exception { + client1 = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client1); + + client2 = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client2); + + AuthenticateMessage auth1 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred1 = client1.register(auth1); + deferred1.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session session) throws Exception { + return client1.connect(session); + } + }).addCallback(new Callback() { + @Override + public Session call(Session session) throws Exception { + session1 = session; + return session; + } + }).join(2000); + + AuthenticateMessage auth2 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred2 = client2.register(auth2); + deferred2.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session session) throws Exception { + return client2.connect(session); + } + }).addCallback(new Callback() { + @Override + public Session call(Session session) throws Exception { + session2 = session; + return session; + } + }).join(2000); + } + + @After + public void teardown() throws Exception { + client1.disconnect().join(2000); + client2.disconnect().join(2000); + } + + @Test(expected = Error.class) + public void friendsBlockNotFound() throws Exception { + FriendsBlockMessage block = FriendsBlockMessage.Builder.newBuilder().id(UUID.randomUUID().toString()).build(); + final Deferred deferred = client1.send(block); + deferred.addCallback(new Callback() { + @Override + public Boolean call(Boolean success) throws Exception { + Assert.fail("Should not reach this point."); + return success; + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.assertEquals(Error.ErrorCode.RUNTIME_EXCEPTION, error.getCode()); + return error; + } + }); + deferred.join(2000); + Assert.fail("Should not reach this point."); + } + + @Test + public void friendsBlock() throws Exception { + FriendsBlockMessage block = FriendsBlockMessage.Builder.newBuilder().id(session2.getId()).build(); + final Deferred deferred = client1.send(block); + deferred.addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + + @Test + public void friendsBlockAfterAddMutual() throws Exception { + FriendsAddMessage add1 = FriendsAddMessage.Builder.newBuilder().id(session2.getId()).build(); + final Deferred deferred = client1.send(add1); + deferred.addCallbackDeferring(new Callback, Boolean>() { + @Override + public Deferred call(Boolean success) throws Exception { + FriendsAddMessage add2 = FriendsAddMessage.Builder.newBuilder().id(session1.getId()).build(); + return client2.send(add2); + } + }).addCallbackDeferring(new Callback, Boolean>() { + @Override + public Deferred call(Boolean success) throws Exception { + FriendsBlockMessage block = FriendsBlockMessage.Builder.newBuilder().id(session2.getId()).build(); + return client1.send(block); + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + +} diff --git a/src/test/java/com/heroiclabs/nakama/FriendsListMessageTest.java b/src/test/java/com/heroiclabs/nakama/FriendsListMessageTest.java new file mode 100644 index 00000000..29560fc1 --- /dev/null +++ b/src/test/java/com/heroiclabs/nakama/FriendsListMessageTest.java @@ -0,0 +1,131 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import com.stumbleupon.async.Callback; +import com.stumbleupon.async.Deferred; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.UUID; + +public class FriendsListMessageTest { + + private Client client1; + private Client client2; + + private Session session1; + private Session session2; + + @Before + public void init() throws Exception { + client1 = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client1); + + client2 = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client2); + + AuthenticateMessage auth1 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred1 = client1.register(auth1); + deferred1.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session session) throws Exception { + return client1.connect(session); + } + }).addCallback(new Callback() { + @Override + public Session call(Session session) throws Exception { + session1 = session; + return session; + } + }).join(2000); + + AuthenticateMessage auth2 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred2 = client2.register(auth2); + deferred2.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session session) throws Exception { + return client2.connect(session); + } + }).addCallback(new Callback() { + @Override + public Session call(Session session) throws Exception { + session2 = session; + return session; + } + }).join(2000); + } + + @After + public void teardown() throws Exception { + client1.disconnect().join(2000); + client2.disconnect().join(2000); + } + + @Test + public void friendsListEmpty() throws Exception { + FriendsListMessage list = FriendsListMessage.Builder.build(); + final Deferred> deferred = client1.send(list); + deferred.addCallback(new Callback, ResultSet>() { + @Override + public ResultSet call(ResultSet friends) throws Exception { + Assert.assertEquals(0, friends.getResults().size()); + return friends; + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + + @Test + public void friendsListAfterBlock() throws Exception { + FriendsBlockMessage block = FriendsBlockMessage.Builder.newBuilder().id(session2.getId()).build(); + final Deferred deferred = client1.send(block); + deferred.addCallbackDeferring(new Callback>, Boolean>() { + @Override + public Deferred> call(Boolean success) throws Exception { + Assert.assertTrue(success); + FriendsListMessage list = FriendsListMessage.Builder.build(); + return client1.send(list); + } + }).addCallback(new Callback, ResultSet>() { + @Override + public ResultSet call(ResultSet friends) throws Exception { + Assert.assertEquals(1, friends.getResults().size()); + Assert.assertEquals(Friend.FriendType.BLOCKED, friends.getResults().get(0).getState()); + Assert.assertEquals(session2.getId(), friends.getResults().get(0).getId()); + Assert.assertEquals(session2.getHandle(), friends.getResults().get(0).getHandle()); + return friends; + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + +} diff --git a/src/test/java/com/heroiclabs/nakama/FriendsRemoveMessageTest.java b/src/test/java/com/heroiclabs/nakama/FriendsRemoveMessageTest.java new file mode 100644 index 00000000..7d445fd1 --- /dev/null +++ b/src/test/java/com/heroiclabs/nakama/FriendsRemoveMessageTest.java @@ -0,0 +1,141 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import com.stumbleupon.async.Callback; +import com.stumbleupon.async.Deferred; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.UUID; + +public class FriendsRemoveMessageTest { + + private Client client1; + private Client client2; + + private Session session1; + private Session session2; + + @Before + public void init() throws Exception { + client1 = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client1); + + client2 = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client2); + + AuthenticateMessage auth1 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred1 = client1.register(auth1); + deferred1.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session session) throws Exception { + return client1.connect(session); + } + }).addCallback(new Callback() { + @Override + public Session call(Session session) throws Exception { + session1 = session; + return session; + } + }).join(2000); + + AuthenticateMessage auth2 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred2 = client2.register(auth2); + deferred2.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session session) throws Exception { + return client2.connect(session); + } + }).addCallback(new Callback() { + @Override + public Session call(Session session) throws Exception { + session2 = session; + return session; + } + }).join(2000); + } + + @After + public void teardown() throws Exception { + client1.disconnect().join(2000); + client2.disconnect().join(2000); + } + + @Test + public void friendsRemoveNotFound() throws Exception { + FriendsRemoveMessage remove = FriendsRemoveMessage.Builder.newBuilder().id(UUID.randomUUID().toString()).build(); + final Deferred deferred = client1.send(remove); + deferred.addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + + @Test + public void friendsRemoveRequest() throws Exception { + FriendsAddMessage add = FriendsAddMessage.Builder.newBuilder().id(session2.getId()).build(); + final Deferred deferred = client1.send(add); + deferred.addCallbackDeferring(new Callback, Boolean>() { + @Override + public Deferred call(Boolean success) throws Exception { + FriendsRemoveMessage remove = FriendsRemoveMessage.Builder.newBuilder().id(session2.getId()).build(); + return client1.send(remove); + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + + @Test + public void friendsRemoveMutual() throws Exception { + FriendsAddMessage add1 = FriendsAddMessage.Builder.newBuilder().id(session2.getId()).build(); + final Deferred deferred = client1.send(add1); + deferred.addCallbackDeferring(new Callback, Boolean>() { + @Override + public Deferred call(Boolean success) throws Exception { + FriendsAddMessage add2 = FriendsAddMessage.Builder.newBuilder().id(session1.getId()).build(); + return client2.send(add2); + } + }).addCallbackDeferring(new Callback, Boolean>() { + @Override + public Deferred call(Boolean success) throws Exception { + FriendsRemoveMessage remove = FriendsRemoveMessage.Builder.newBuilder().id(session2.getId()).build(); + return client1.send(remove); + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + +} diff --git a/src/test/java/com/heroiclabs/nakama/GroupUsersAddMessageTest.java b/src/test/java/com/heroiclabs/nakama/GroupUsersAddMessageTest.java new file mode 100644 index 00000000..0c4ae124 --- /dev/null +++ b/src/test/java/com/heroiclabs/nakama/GroupUsersAddMessageTest.java @@ -0,0 +1,180 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import com.stumbleupon.async.Callback; +import com.stumbleupon.async.Deferred; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.UUID; + +public class GroupUsersAddMessageTest { + + private Client client1; + private Client client2; + + private Session session1; + private Session session2; + + @Before + public void init() throws Exception { + client1 = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client1); + + client2 = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client2); + + AuthenticateMessage auth1 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred1 = client1.register(auth1); + deferred1.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session session) throws Exception { + return client1.connect(session); + } + }).addCallback(new Callback() { + @Override + public Session call(Session session) throws Exception { + session1 = session; + return session; + } + }).join(2000); + + AuthenticateMessage auth2 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred2 = client2.register(auth2); + deferred2.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session session) throws Exception { + return client2.connect(session); + } + }).addCallback(new Callback() { + @Override + public Session call(Session session) throws Exception { + session2 = session; + return session; + } + }).join(2000); + } + + @After + public void teardown() throws Exception { + client1.disconnect().join(2000); + client2.disconnect().join(2000); + } + + @Test(expected = Error.class) + public void groupUsersAddPublicGroupNotFound() throws Exception { + final String name = UUID.randomUUID().toString(); + GroupsCreateMessage create = GroupsCreateMessage.Builder.newBuilder() + .group(name, null, null, null, "{}", false) + .build(); + final Deferred> deferred = client1.send(create); + deferred.addCallbackDeferring(new Callback, ResultSet>() { + @Override + public Deferred call(ResultSet groups) throws Exception { + Assert.assertEquals(1, groups.getResults().size()); + Assert.assertEquals(name, groups.getResults().get(0).getName()); + GroupUsersAddMessage add = GroupUsersAddMessage.Builder.newBuilder() + .add(UUID.randomUUID().toString(), session2.getId()) + .build(); + return client1.send(add); + } + }).addCallback(new Callback() { + @Override + public Boolean call(Boolean success) throws Exception { + Assert.fail("Should not reach this point."); + return success; + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.assertEquals(Error.ErrorCode.RUNTIME_EXCEPTION, error.getCode()); + return error; + } + }); + deferred.join(2000); + } + + @Test(expected = Error.class) + public void groupUsersAddPublicUserNotFound() throws Exception { + final String name = UUID.randomUUID().toString(); + GroupsCreateMessage create = GroupsCreateMessage.Builder.newBuilder() + .group(name, null, null, null, "{}", false) + .build(); + final Deferred> deferred = client1.send(create); + deferred.addCallbackDeferring(new Callback, ResultSet>() { + @Override + public Deferred call(ResultSet groups) throws Exception { + Assert.assertEquals(1, groups.getResults().size()); + Assert.assertEquals(name, groups.getResults().get(0).getName()); + GroupUsersAddMessage add = GroupUsersAddMessage.Builder.newBuilder() + .add(groups.getResults().get(0).getId(), UUID.randomUUID().toString()) + .build(); + return client1.send(add); + } + }).addCallback(new Callback() { + @Override + public Boolean call(Boolean success) throws Exception { + Assert.fail("Should not reach this point."); + return success; + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.assertEquals(Error.ErrorCode.RUNTIME_EXCEPTION, error.getCode()); + return error; + } + }); + deferred.join(2000); + } + + @Test + public void groupUsersAddPublic() throws Exception { + final String name = UUID.randomUUID().toString(); + GroupsCreateMessage create = GroupsCreateMessage.Builder.newBuilder() + .group(name, null, null, null, "{}", false) + .build(); + final Deferred> deferred = client1.send(create); + deferred.addCallbackDeferring(new Callback, ResultSet>() { + @Override + public Deferred call(ResultSet groups) throws Exception { + Assert.assertEquals(1, groups.getResults().size()); + Assert.assertEquals(name, groups.getResults().get(0).getName()); + GroupUsersAddMessage add = GroupUsersAddMessage.Builder.newBuilder() + .add(groups.getResults().get(0).getId(), session2.getId()) + .build(); + return client1.send(add); + } + }).addCallback(new Callback() { + @Override + public Boolean call(Boolean success) throws Exception { + Assert.assertTrue(success); + return success; + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + +} diff --git a/src/test/java/com/heroiclabs/nakama/GroupUsersListMessageTest.java b/src/test/java/com/heroiclabs/nakama/GroupUsersListMessageTest.java new file mode 100644 index 00000000..977484b4 --- /dev/null +++ b/src/test/java/com/heroiclabs/nakama/GroupUsersListMessageTest.java @@ -0,0 +1,108 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import com.stumbleupon.async.Callback; +import com.stumbleupon.async.Deferred; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.UUID; + +public class GroupUsersListMessageTest { + + private Client client; + + private Session session; + + @Before + public void init() throws Exception { + client = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client); + + AuthenticateMessage auth = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred = client.register(auth); + deferred.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session s) throws Exception { + session = s; + return client.connect(session); + } + }).join(2000); + } + + @After + public void teardown() throws Exception { + client.disconnect().join(2000); + } + + @Test + public void groupUsersListNotFound() throws Exception { + GroupUsersListMessage list = GroupUsersListMessage.Builder.build(UUID.randomUUID().toString()); + final Deferred> deferred = client.send(list); + deferred.addCallback(new Callback, ResultSet>() { + @Override + public ResultSet call(ResultSet groupUsers) throws Exception { + Assert.assertEquals(0, groupUsers.getResults().size()); + return groupUsers; + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + + @Test + public void groupUsersList() throws Exception { + final String name = UUID.randomUUID().toString(); + GroupsCreateMessage create = GroupsCreateMessage.Builder.newBuilder() + .group(name, null, null, null, "{}", false) + .build(); + final Deferred> deferred = client.send(create); + deferred.addCallbackDeferring(new Callback>, ResultSet>() { + @Override + public Deferred> call(ResultSet groups) throws Exception { + Assert.assertEquals(1, groups.getResults().size()); + Assert.assertEquals(name, groups.getResults().get(0).getName()); + GroupUsersListMessage list = GroupUsersListMessage.Builder.build(groups.getResults().get(0).getId()); + return client.send(list); + } + }).addCallback(new Callback, ResultSet>() { + @Override + public ResultSet call(ResultSet groupUsers) throws Exception { + Assert.assertEquals(1, groupUsers.getResults().size()); + Assert.assertEquals(session.getId(), groupUsers.getResults().get(0).getId()); + Assert.assertEquals(Group.MembershipType.ADMIN, groupUsers.getResults().get(0).getState()); + return groupUsers; + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + +} diff --git a/src/test/java/com/heroiclabs/nakama/GroupsCreateMessageTest.java b/src/test/java/com/heroiclabs/nakama/GroupsCreateMessageTest.java new file mode 100644 index 00000000..71262310 --- /dev/null +++ b/src/test/java/com/heroiclabs/nakama/GroupsCreateMessageTest.java @@ -0,0 +1,76 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import com.stumbleupon.async.Callback; +import com.stumbleupon.async.Deferred; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.UUID; + +public class GroupsCreateMessageTest { + + private Client client; + + @Before + public void init() throws Exception { + client = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client); + + AuthenticateMessage auth = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred = client.register(auth); + deferred.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session session) throws Exception { + return client.connect(session); + } + }).join(2000); + } + + @After + public void teardown() throws Exception { + client.disconnect().join(2000); + } + + @Test + public void groupsCreate() throws Exception { + final String name = UUID.randomUUID().toString(); + GroupsCreateMessage create = GroupsCreateMessage.Builder.newBuilder() + .group(name, null, null, null, "{}", false) + .build(); + final Deferred> deferred = client.send(create); + deferred.addCallback(new Callback, ResultSet>() { + @Override + public ResultSet call(ResultSet groups) throws Exception { + Assert.assertEquals(1, groups.getResults().size()); + Assert.assertEquals(name, groups.getResults().get(0).getName()); + return groups; + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + +} diff --git a/src/test/java/com/heroiclabs/nakama/GroupsFetchMessageTest.java b/src/test/java/com/heroiclabs/nakama/GroupsFetchMessageTest.java new file mode 100644 index 00000000..cbe08cc6 --- /dev/null +++ b/src/test/java/com/heroiclabs/nakama/GroupsFetchMessageTest.java @@ -0,0 +1,4 @@ +package com.heroiclabs.nakama; + +public class GroupsFetchMessageTest { +} diff --git a/src/test/java/com/heroiclabs/nakama/GroupsJoinMessageTest.java b/src/test/java/com/heroiclabs/nakama/GroupsJoinMessageTest.java new file mode 100644 index 00000000..d832d0ea --- /dev/null +++ b/src/test/java/com/heroiclabs/nakama/GroupsJoinMessageTest.java @@ -0,0 +1,163 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import com.stumbleupon.async.Callback; +import com.stumbleupon.async.Deferred; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.UUID; + +public class GroupsJoinMessageTest { + + private Client client1; + private Client client2; + + private Session session1; + private Session session2; + + @Before + public void init() throws Exception { + client1 = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client1); + + client2 = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client2); + + AuthenticateMessage auth1 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred1 = client1.register(auth1); + deferred1.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session session) throws Exception { + return client1.connect(session); + } + }).addCallback(new Callback() { + @Override + public Session call(Session session) throws Exception { + session1 = session; + return session; + } + }).join(2000); + + AuthenticateMessage auth2 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred2 = client2.register(auth2); + deferred2.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session session) throws Exception { + return client2.connect(session); + } + }).addCallback(new Callback() { + @Override + public Session call(Session session) throws Exception { + session2 = session; + return session; + } + }).join(2000); + } + + @After + public void teardown() throws Exception { + client1.disconnect().join(2000); + client2.disconnect().join(2000); + } + + @Test + public void groupsJoinPublic() throws Exception { + final String name = UUID.randomUUID().toString(); + GroupsCreateMessage create = GroupsCreateMessage.Builder.newBuilder() + .group(name, null, null, null, "{}", false) + .build(); + final Deferred> deferred = client1.send(create); + deferred.addCallbackDeferring(new Callback, ResultSet>() { + @Override + public Deferred call(ResultSet groups) throws Exception { + Assert.assertEquals(1, groups.getResults().size()); + Assert.assertEquals(name, groups.getResults().get(0).getName()); + GroupsJoinMessage join = GroupsJoinMessage.Builder.newBuilder() + .id(groups.getResults().get(0).getId()) + .build(); + return client2.send(join); + } + }).addCallbackDeferring(new Callback>, Boolean>() { + @Override + public Deferred> call(Boolean success) throws Exception { + Assert.assertTrue(success); + GroupsSelfListMessage list = GroupsSelfListMessage.Builder.build(); + return client2.send(list); + } + }).addCallback(new Callback, ResultSet>() { + @Override + public ResultSet call(ResultSet groups) throws Exception { + Assert.assertEquals(1, groups.getResults().size()); + Assert.assertEquals(name, groups.getResults().get(0).getName()); + Assert.assertEquals(Group.MembershipType.MEMBER, groups.getResults().get(0).getState()); + return groups; + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + + @Test + public void groupsJoinPrivate() throws Exception { + final String name = UUID.randomUUID().toString(); + GroupsCreateMessage create = GroupsCreateMessage.Builder.newBuilder() + .group(name, null, null, null, "{}", true) + .build(); + final Deferred> deferred = client1.send(create); + deferred.addCallbackDeferring(new Callback, ResultSet>() { + @Override + public Deferred call(ResultSet groups) throws Exception { + Assert.assertEquals(1, groups.getResults().size()); + Assert.assertEquals(name, groups.getResults().get(0).getName()); + GroupsJoinMessage join = GroupsJoinMessage.Builder.newBuilder() + .id(groups.getResults().get(0).getId()) + .build(); + return client2.send(join); + } + }).addCallbackDeferring(new Callback>, Boolean>() { + @Override + public Deferred> call(Boolean success) throws Exception { + Assert.assertTrue(success); + GroupsSelfListMessage list = GroupsSelfListMessage.Builder.build(); + return client2.send(list); + } + }).addCallback(new Callback, ResultSet>() { + @Override + public ResultSet call(ResultSet groups) throws Exception { + Assert.assertEquals(0, groups.getResults().size()); + return groups; + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + +} diff --git a/src/test/java/com/heroiclabs/nakama/GroupsRemoveMessageTest.java b/src/test/java/com/heroiclabs/nakama/GroupsRemoveMessageTest.java new file mode 100644 index 00000000..447c389b --- /dev/null +++ b/src/test/java/com/heroiclabs/nakama/GroupsRemoveMessageTest.java @@ -0,0 +1,101 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import com.stumbleupon.async.Callback; +import com.stumbleupon.async.Deferred; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.UUID; + +public class GroupsRemoveMessageTest { + + private Client client; + + @Before + public void init() throws Exception { + client = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client); + + AuthenticateMessage auth = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred = client.register(auth); + deferred.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session session) throws Exception { + return client.connect(session); + } + }).join(2000); + } + + @After + public void teardown() throws Exception { + client.disconnect().join(2000); + } + + @Test(expected = Error.class) + public void groupsRemoveNotFound() throws Exception { + GroupsRemoveMessage remove = GroupsRemoveMessage.Builder.newBuilder() + .id(UUID.randomUUID().toString()) + .build(); + final Deferred deferred = client.send(remove); + deferred.addCallback(new Callback() { + @Override + public Boolean call(Boolean success) throws Exception { + Assert.fail("Should not reach this point."); + return success; + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.assertEquals(Error.ErrorCode.RUNTIME_EXCEPTION, error.getCode()); + return error; + } + }); + deferred.join(2000); + } + + @Test + public void groupsRemove() throws Exception { + final String name = UUID.randomUUID().toString(); + GroupsCreateMessage create = GroupsCreateMessage.Builder.newBuilder() + .group(name, null, null, null, "{}", false) + .build(); + final Deferred> deferred = client.send(create); + deferred.addCallbackDeferring(new Callback, ResultSet>() { + @Override + public Deferred call(ResultSet groups) throws Exception { + Assert.assertEquals(1, groups.getResults().size()); + Assert.assertEquals(name, groups.getResults().get(0).getName()); + GroupsRemoveMessage remove = GroupsRemoveMessage.Builder.newBuilder() + .id(groups.getResults().get(0).getId()) + .build(); + return client.send(remove); + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + +} diff --git a/src/test/java/com/heroiclabs/nakama/LeaderboardRecordsListMessageTest.java b/src/test/java/com/heroiclabs/nakama/LeaderboardRecordsListMessageTest.java new file mode 100644 index 00000000..cf02f7c0 --- /dev/null +++ b/src/test/java/com/heroiclabs/nakama/LeaderboardRecordsListMessageTest.java @@ -0,0 +1,137 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import com.stumbleupon.async.Callback; +import com.stumbleupon.async.Deferred; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.UUID; + +public class LeaderboardRecordsListMessageTest { + + private Client client; + + private Session session; + + @Before + public void init() throws Exception { + client = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client); + + AuthenticateMessage auth = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred = client.register(auth); + deferred.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session s) throws Exception { + session = s; + return client.connect(session); + } + }).join(2000); + } + + @After + public void teardown() throws Exception { + client.disconnect().join(2000); + } + + @Test + public void leaderboardRecordsList() throws Exception { + final String leaderboardId = UUID.randomUUID().toString(); + RpcMessage rpc = RpcMessage.Builder.newBuilder("generate_leaderboard") + .payload("{\"leaderboard_id\":\"" + leaderboardId +"\"}") + .build(); + final Deferred deferred = client.send(rpc); + deferred.addCallbackDeferring(new Callback>, RpcResult>() { + @Override + public Deferred> call(RpcResult result) throws Exception { + LeaderboardRecordsListMessage list = LeaderboardRecordsListMessage.Builder.newBuilder(leaderboardId).limit(10).build(); + return client.send(list); + } + }).addCallbackDeferring(new Callback>, ResultSet>() { + @Override + public Deferred> call(ResultSet records) throws Exception { + Assert.assertEquals(10, records.getResults().size()); + Assert.assertNotNull(records.getCursor()); + LeaderboardRecordsListMessage list = LeaderboardRecordsListMessage.Builder.newBuilder(leaderboardId) + .cursor(records.getCursor()) + .limit(10) + .build(); + return client.send(list); + } + }).addCallback(new Callback, ResultSet>() { + @Override + public ResultSet call(ResultSet records) throws Exception { + Assert.assertEquals(5, records.getResults().size()); + return records; + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + + @Test + public void leaderboardRecordsListHaystack() throws Exception { + final String leaderboardId = UUID.randomUUID().toString(); + RpcMessage rpc = RpcMessage.Builder.newBuilder("generate_leaderboard") + .payload("{\"leaderboard_id\":\"" + leaderboardId +"\"}") + .build(); + final Deferred deferred = client.send(rpc); + deferred.addCallbackDeferring(new Callback>, RpcResult>() { + @Override + public Deferred> call(RpcResult result) throws Exception { + LeaderboardRecordWriteMessage write = LeaderboardRecordWriteMessage.Builder.newBuilder() + .add(LeaderboardRecordWriteMessage.LeaderboardRecordWrite.newBuilder(leaderboardId) + .set(7)) + .build(); + return client.send(write); + } + }).addCallbackDeferring(new Callback>, ResultSet>() { + @Override + public Deferred> call(ResultSet records) throws Exception { + LeaderboardRecordsListMessage list = LeaderboardRecordsListMessage.Builder.newBuilder(leaderboardId) + .limit(10) + .filterByPagingToOwnerId(session.getId()) + .build(); + return client.send(list); + } + }).addCallback(new Callback, ResultSet>() { + @Override + public ResultSet call(ResultSet records) throws Exception { + Assert.assertEquals(10, records.getResults().size()); + Assert.assertNotNull(records.getCursor()); + return records; + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + +} diff --git a/src/test/java/com/heroiclabs/nakama/MatchmakeAddMessageTest.java b/src/test/java/com/heroiclabs/nakama/MatchmakeAddMessageTest.java index d1a22df9..caa79bd9 100644 --- a/src/test/java/com/heroiclabs/nakama/MatchmakeAddMessageTest.java +++ b/src/test/java/com/heroiclabs/nakama/MatchmakeAddMessageTest.java @@ -25,6 +25,7 @@ import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.UUID; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -61,6 +62,7 @@ public void init() { latch3.countDown(); } @Override public void onMatchPresence(MatchPresence matchPresence) {} + @Override public void onNotifications(List notifications) {} }).build(); Assert.assertNotNull(client1); latch1 = new CountDownLatch(1); @@ -76,6 +78,7 @@ public void init() { } @Override public void onMatchData(MatchData matchData) {} @Override public void onMatchPresence(MatchPresence matchPresence) {} + @Override public void onNotifications(List notifications) {} }).build(); Assert.assertNotNull(client2); latch2 = new CountDownLatch(1); @@ -181,6 +184,4 @@ public Deferred call(ResultSet matches) throws Exception { Assert.assertNotNull(data); } - - } diff --git a/src/test/java/com/heroiclabs/nakama/NotificationsListMessageTest.java b/src/test/java/com/heroiclabs/nakama/NotificationsListMessageTest.java new file mode 100644 index 00000000..ed836221 --- /dev/null +++ b/src/test/java/com/heroiclabs/nakama/NotificationsListMessageTest.java @@ -0,0 +1,93 @@ +/* + * Copyright 2017 The Nakama Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.heroiclabs.nakama; + +import com.stumbleupon.async.Callback; +import com.stumbleupon.async.Deferred; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.UUID; + +public class NotificationsListMessageTest { + + private Client client; + + private Session session; + + @Before + public void init() throws Exception { + client = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client); + + AuthenticateMessage auth = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred = client.register(auth); + deferred.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session s) throws Exception { + session = s; + return client.connect(session); + } + }).join(2000); + } + + @After + public void teardown() throws Exception { + client.disconnect().join(2000); + } + + @Test + public void notificationsList() throws Exception { + final String leaderboardId = UUID.randomUUID().toString(); + RpcMessage rpc = RpcMessage.Builder.newBuilder("generate_notifications") + .build(); + final Deferred deferred = client.send(rpc); + deferred.addCallbackDeferring(new Callback>, RpcResult>() { + @Override + public Deferred> call(RpcResult result) throws Exception { + NotificationsListMessage list = NotificationsListMessage.Builder.newBuilder(10).build(); + return client.send(list); + } + }).addCallbackDeferring(new Callback>, ResultSet>() { + @Override + public Deferred> call(ResultSet notifications) throws Exception { + Assert.assertEquals(10, notifications.getResults().size()); + Assert.assertNotNull(notifications.getCursor()); + NotificationsListMessage list = NotificationsListMessage.Builder.newBuilder(10) + .cursor(notifications.getCursor()) + .build(); + return client.send(list); + } + }).addCallback(new Callback, ResultSet>() { + @Override + public ResultSet call(ResultSet notifications) throws Exception { + Assert.assertEquals(5, notifications.getResults().size()); + return notifications; + } + }).addErrback(new Callback() { + @Override + public Error call(Error error) throws Exception { + Assert.fail("Should not reach this point."); + return error; + } + }); + deferred.join(2000); + } + +}