mirror of
https://github.com/heroiclabs/nakama-java.git
synced 2026-11-24 08:55:49 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
113d21a1e1 | ||
|
|
95a8571b4c | ||
|
|
b8de50d4e0 |
No files matched your search
@@ -6,6 +6,18 @@ The format is based on [keep a changelog](http://keepachangelog.com/) and this p
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.5.0] - 2017-11-21
|
||||
### 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
|
||||
- Expose a simpler interface for identifier fields.
|
||||
|
||||
+4
-3
@@ -25,7 +25,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'com.heroiclabs.nakama'
|
||||
version = '0.4.0'
|
||||
version = '0.5.0'
|
||||
def description = 'Android optimized Java client for Nakama server.'
|
||||
|
||||
sourceCompatibility = 1.7
|
||||
@@ -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 {
|
||||
|
||||
+1
-1
Submodule server updated: b6f073bb4e...ca88ea9ce6.
@@ -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<Notification> notifications);
|
||||
}
|
||||
@@ -252,6 +252,13 @@ public class DefaultClient implements Client {
|
||||
case MATCHMAKE_MATCHED:
|
||||
listener.onMatchmakeMatched(DefaultMatchmakeMatched.fromProto(envelope.getMatchmakeMatched()));
|
||||
break;
|
||||
case LIVE_NOTIFICATIONS:
|
||||
final List<Notification> 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 class DefaultClient implements Client {
|
||||
}
|
||||
def.callback(new DefaultResultSet<User>(null, users));
|
||||
break;
|
||||
case FRIENDS:
|
||||
final List<Friend> friends = new ArrayList<>();
|
||||
for (final com.heroiclabs.nakama.Api.Friend friend : envelope.getFriends().getFriendsList()) {
|
||||
friends.add(DefaultFriend.fromProto(friend));
|
||||
}
|
||||
def.callback(new DefaultResultSet<Friend>(null, friends));
|
||||
break;
|
||||
case GROUPS:
|
||||
final List<Group> groups = new ArrayList<>();
|
||||
for (final com.heroiclabs.nakama.Api.Group group : envelope.getGroups().getGroupsList()) {
|
||||
groups.add(DefaultGroup.fromProto(group));
|
||||
}
|
||||
def.callback(new DefaultResultSet<Group>(new DefaultCursor(envelope.getGroups().getCursor()), groups));
|
||||
break;
|
||||
case GROUPS_SELF:
|
||||
final List<GroupSelf> groupsSelf = new ArrayList<>();
|
||||
for (final com.heroiclabs.nakama.Api.TGroupsSelf.GroupSelf groupSelf : envelope.getGroupsSelf().getGroupsSelfList()) {
|
||||
groupsSelf.add(DefaultGroupSelf.fromProto(groupSelf));
|
||||
}
|
||||
def.callback(new DefaultResultSet<GroupSelf>(null, groupsSelf));
|
||||
break;
|
||||
case GROUP_USERS:
|
||||
final List<GroupUser> groupUsers = new ArrayList<>();
|
||||
for (final com.heroiclabs.nakama.Api.GroupUser groupUser : envelope.getGroupUsers().getUsersList()) {
|
||||
groupUsers.add(DefaultGroupUser.fromProto(groupUser));
|
||||
}
|
||||
def.callback(new DefaultResultSet<GroupUser>(null, groupUsers));
|
||||
break;
|
||||
case STORAGE_DATA:
|
||||
final List<StorageRecord> records = new ArrayList<>();
|
||||
for (final com.heroiclabs.nakama.Api.TStorageData.StorageData data : envelope.getStorageData().getDataList()) {
|
||||
@@ -346,6 +381,13 @@ public class DefaultClient implements Client {
|
||||
}
|
||||
def.callback(new DefaultResultSet<LeaderboardRecord>(new DefaultCursor(envelope.getLeaderboardRecords().getCursor()), leaderboardRecords));
|
||||
break;
|
||||
case NOTIFICATIONS:
|
||||
final List<Notification> notifications = new ArrayList<>();
|
||||
for (final com.heroiclabs.nakama.Api.Notification notification : envelope.getNotifications().getNotificationsList()) {
|
||||
notifications.add(DefaultNotification.fromProto(notification));
|
||||
}
|
||||
def.callback(new DefaultResultSet<Notification>(new DefaultCursor(envelope.getNotifications().getResumableCursor()), notifications));
|
||||
break;
|
||||
default:
|
||||
def.callback(new DefaultError(envelope.getError().getMessage(), envelope.getError().getCode(), collationId));
|
||||
break;
|
||||
|
||||
@@ -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> T getMetadata(final Class<T> 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()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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> T getMetadata(final Class<T> 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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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> T getMetadata(final Class<T> 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()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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> T getMetadata(final Class<T> 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()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import lombok.*;
|
||||
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 @@ class DefaultLeaderboard implements Leaderboard {
|
||||
return new DefaultLeaderboard(
|
||||
leaderboard.getId(),
|
||||
leaderboard.getAuthoritative(),
|
||||
leaderboard.getSort(),
|
||||
Leaderboard.SortOrder.fromLong(leaderboard.getSort()),
|
||||
leaderboard.getCount(),
|
||||
leaderboard.getResetSchedule(),
|
||||
leaderboard.getMetadata(),
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
@@ -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<Boolean> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Boolean> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<ResultSet<Friend>> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Boolean> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <T> A type parameter for the metadata to decode.
|
||||
* @return The decoded metadata for the group.
|
||||
*/
|
||||
<T> T getMetadata(final Class<T> 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();
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
@@ -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<Boolean> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Boolean> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<ResultSet<GroupUser>> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Boolean> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<ResultSet<Group>> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<ResultSet<Group>> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Boolean> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Boolean> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<ResultSet<Group>> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Boolean> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<ResultSet<GroupSelf>> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Boolean> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
@@ -65,8 +65,8 @@ public interface LeaderboardRecordsListMessage extends CollatedMessage<ResultSet
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Notification> notifications) {}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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<ResultSet<Notification>> {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Boolean> {
|
||||
|
||||
@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<String> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public interface TopicLeaveMessage extends CollatedMessage<Boolean> {
|
||||
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()) {
|
||||
|
||||
@@ -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<Session> deferred1 = client1.register(auth1);
|
||||
deferred1.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
return client1.connect(session);
|
||||
}
|
||||
}).addCallback(new Callback<Session, Session>() {
|
||||
@Override
|
||||
public Session call(Session session) throws Exception {
|
||||
session1 = session;
|
||||
return session;
|
||||
}
|
||||
}).join(2000);
|
||||
|
||||
AuthenticateMessage auth2 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString());
|
||||
final Deferred<Session> deferred2 = client2.register(auth2);
|
||||
deferred2.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
return client2.connect(session);
|
||||
}
|
||||
}).addCallback(new Callback<Session, Session>() {
|
||||
@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<Boolean> deferred = client1.send(add);
|
||||
deferred.addCallback(new Callback<Boolean, Boolean>() {
|
||||
@Override
|
||||
public Boolean call(Boolean success) throws Exception {
|
||||
Assert.fail("Should not reach this point.");
|
||||
return success;
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@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<Boolean> deferred = client1.send(add);
|
||||
deferred.addErrback(new Callback<Error, Error>() {
|
||||
@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<Boolean> deferred = client1.send(add);
|
||||
deferred.addErrback(new Callback<Error, Error>() {
|
||||
@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<Boolean> deferred = client1.send(add1);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Boolean>, Boolean>() {
|
||||
@Override
|
||||
public Deferred<Boolean> call(Boolean success) throws Exception {
|
||||
FriendsAddMessage add2 = FriendsAddMessage.Builder.newBuilder().id(session1.getId()).build();
|
||||
return client2.send(add2);
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@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<Boolean> deferred = client1.send(add1);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Boolean>, Boolean>() {
|
||||
@Override
|
||||
public Deferred<Boolean> call(Boolean success) throws Exception {
|
||||
FriendsAddMessage add2 = FriendsAddMessage.Builder.newBuilder().handle(session1.getHandle()).build();
|
||||
return client2.send(add2);
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@Override
|
||||
public Error call(Error error) throws Exception {
|
||||
Assert.fail("Should not reach this point.");
|
||||
return error;
|
||||
}
|
||||
});
|
||||
deferred.join(2000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Session> deferred1 = client1.register(auth1);
|
||||
deferred1.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
return client1.connect(session);
|
||||
}
|
||||
}).addCallback(new Callback<Session, Session>() {
|
||||
@Override
|
||||
public Session call(Session session) throws Exception {
|
||||
session1 = session;
|
||||
return session;
|
||||
}
|
||||
}).join(2000);
|
||||
|
||||
AuthenticateMessage auth2 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString());
|
||||
final Deferred<Session> deferred2 = client2.register(auth2);
|
||||
deferred2.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
return client2.connect(session);
|
||||
}
|
||||
}).addCallback(new Callback<Session, Session>() {
|
||||
@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<Boolean> deferred = client1.send(block);
|
||||
deferred.addCallback(new Callback<Boolean, Boolean>() {
|
||||
@Override
|
||||
public Boolean call(Boolean success) throws Exception {
|
||||
Assert.fail("Should not reach this point.");
|
||||
return success;
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@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<Boolean> deferred = client1.send(block);
|
||||
deferred.addErrback(new Callback<Error, Error>() {
|
||||
@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<Boolean> deferred = client1.send(add1);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Boolean>, Boolean>() {
|
||||
@Override
|
||||
public Deferred<Boolean> call(Boolean success) throws Exception {
|
||||
FriendsAddMessage add2 = FriendsAddMessage.Builder.newBuilder().id(session1.getId()).build();
|
||||
return client2.send(add2);
|
||||
}
|
||||
}).addCallbackDeferring(new Callback<Deferred<Boolean>, Boolean>() {
|
||||
@Override
|
||||
public Deferred<Boolean> call(Boolean success) throws Exception {
|
||||
FriendsBlockMessage block = FriendsBlockMessage.Builder.newBuilder().id(session2.getId()).build();
|
||||
return client1.send(block);
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@Override
|
||||
public Error call(Error error) throws Exception {
|
||||
Assert.fail("Should not reach this point.");
|
||||
return error;
|
||||
}
|
||||
});
|
||||
deferred.join(2000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Session> deferred1 = client1.register(auth1);
|
||||
deferred1.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
return client1.connect(session);
|
||||
}
|
||||
}).addCallback(new Callback<Session, Session>() {
|
||||
@Override
|
||||
public Session call(Session session) throws Exception {
|
||||
session1 = session;
|
||||
return session;
|
||||
}
|
||||
}).join(2000);
|
||||
|
||||
AuthenticateMessage auth2 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString());
|
||||
final Deferred<Session> deferred2 = client2.register(auth2);
|
||||
deferred2.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
return client2.connect(session);
|
||||
}
|
||||
}).addCallback(new Callback<Session, Session>() {
|
||||
@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<ResultSet<Friend>> deferred = client1.send(list);
|
||||
deferred.addCallback(new Callback<ResultSet<Friend>, ResultSet<Friend>>() {
|
||||
@Override
|
||||
public ResultSet<Friend> call(ResultSet<Friend> friends) throws Exception {
|
||||
Assert.assertEquals(0, friends.getResults().size());
|
||||
return friends;
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@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<Boolean> deferred = client1.send(block);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<ResultSet<Friend>>, Boolean>() {
|
||||
@Override
|
||||
public Deferred<ResultSet<Friend>> call(Boolean success) throws Exception {
|
||||
Assert.assertTrue(success);
|
||||
FriendsListMessage list = FriendsListMessage.Builder.build();
|
||||
return client1.send(list);
|
||||
}
|
||||
}).addCallback(new Callback<ResultSet<Friend>, ResultSet<Friend>>() {
|
||||
@Override
|
||||
public ResultSet<Friend> call(ResultSet<Friend> 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<Error, Error>() {
|
||||
@Override
|
||||
public Error call(Error error) throws Exception {
|
||||
Assert.fail("Should not reach this point.");
|
||||
return error;
|
||||
}
|
||||
});
|
||||
deferred.join(2000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Session> deferred1 = client1.register(auth1);
|
||||
deferred1.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
return client1.connect(session);
|
||||
}
|
||||
}).addCallback(new Callback<Session, Session>() {
|
||||
@Override
|
||||
public Session call(Session session) throws Exception {
|
||||
session1 = session;
|
||||
return session;
|
||||
}
|
||||
}).join(2000);
|
||||
|
||||
AuthenticateMessage auth2 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString());
|
||||
final Deferred<Session> deferred2 = client2.register(auth2);
|
||||
deferred2.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
return client2.connect(session);
|
||||
}
|
||||
}).addCallback(new Callback<Session, Session>() {
|
||||
@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<Boolean> deferred = client1.send(remove);
|
||||
deferred.addErrback(new Callback<Error, Error>() {
|
||||
@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<Boolean> deferred = client1.send(add);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Boolean>, Boolean>() {
|
||||
@Override
|
||||
public Deferred<Boolean> call(Boolean success) throws Exception {
|
||||
FriendsRemoveMessage remove = FriendsRemoveMessage.Builder.newBuilder().id(session2.getId()).build();
|
||||
return client1.send(remove);
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@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<Boolean> deferred = client1.send(add1);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Boolean>, Boolean>() {
|
||||
@Override
|
||||
public Deferred<Boolean> call(Boolean success) throws Exception {
|
||||
FriendsAddMessage add2 = FriendsAddMessage.Builder.newBuilder().id(session1.getId()).build();
|
||||
return client2.send(add2);
|
||||
}
|
||||
}).addCallbackDeferring(new Callback<Deferred<Boolean>, Boolean>() {
|
||||
@Override
|
||||
public Deferred<Boolean> call(Boolean success) throws Exception {
|
||||
FriendsRemoveMessage remove = FriendsRemoveMessage.Builder.newBuilder().id(session2.getId()).build();
|
||||
return client1.send(remove);
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@Override
|
||||
public Error call(Error error) throws Exception {
|
||||
Assert.fail("Should not reach this point.");
|
||||
return error;
|
||||
}
|
||||
});
|
||||
deferred.join(2000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Session> deferred1 = client1.register(auth1);
|
||||
deferred1.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
return client1.connect(session);
|
||||
}
|
||||
}).addCallback(new Callback<Session, Session>() {
|
||||
@Override
|
||||
public Session call(Session session) throws Exception {
|
||||
session1 = session;
|
||||
return session;
|
||||
}
|
||||
}).join(2000);
|
||||
|
||||
AuthenticateMessage auth2 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString());
|
||||
final Deferred<Session> deferred2 = client2.register(auth2);
|
||||
deferred2.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
return client2.connect(session);
|
||||
}
|
||||
}).addCallback(new Callback<Session, Session>() {
|
||||
@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<ResultSet<Group>> deferred = client1.send(create);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Boolean>, ResultSet<Group>>() {
|
||||
@Override
|
||||
public Deferred<Boolean> call(ResultSet<Group> 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<Boolean, Boolean>() {
|
||||
@Override
|
||||
public Boolean call(Boolean success) throws Exception {
|
||||
Assert.fail("Should not reach this point.");
|
||||
return success;
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@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<ResultSet<Group>> deferred = client1.send(create);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Boolean>, ResultSet<Group>>() {
|
||||
@Override
|
||||
public Deferred<Boolean> call(ResultSet<Group> 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<Boolean, Boolean>() {
|
||||
@Override
|
||||
public Boolean call(Boolean success) throws Exception {
|
||||
Assert.fail("Should not reach this point.");
|
||||
return success;
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@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<ResultSet<Group>> deferred = client1.send(create);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Boolean>, ResultSet<Group>>() {
|
||||
@Override
|
||||
public Deferred<Boolean> call(ResultSet<Group> 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<Boolean, Boolean>() {
|
||||
@Override
|
||||
public Boolean call(Boolean success) throws Exception {
|
||||
Assert.assertTrue(success);
|
||||
return success;
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@Override
|
||||
public Error call(Error error) throws Exception {
|
||||
Assert.fail("Should not reach this point.");
|
||||
return error;
|
||||
}
|
||||
});
|
||||
deferred.join(2000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Session> deferred = client.register(auth);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> 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<ResultSet<GroupUser>> deferred = client.send(list);
|
||||
deferred.addCallback(new Callback<ResultSet<GroupUser>, ResultSet<GroupUser>>() {
|
||||
@Override
|
||||
public ResultSet<GroupUser> call(ResultSet<GroupUser> groupUsers) throws Exception {
|
||||
Assert.assertEquals(0, groupUsers.getResults().size());
|
||||
return groupUsers;
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@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<ResultSet<Group>> deferred = client.send(create);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<ResultSet<GroupUser>>, ResultSet<Group>>() {
|
||||
@Override
|
||||
public Deferred<ResultSet<GroupUser>> call(ResultSet<Group> 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<GroupUser>, ResultSet<GroupUser>>() {
|
||||
@Override
|
||||
public ResultSet<GroupUser> call(ResultSet<GroupUser> 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<Error, Error>() {
|
||||
@Override
|
||||
public Error call(Error error) throws Exception {
|
||||
Assert.fail("Should not reach this point.");
|
||||
return error;
|
||||
}
|
||||
});
|
||||
deferred.join(2000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Session> deferred = client.register(auth);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> 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<ResultSet<Group>> deferred = client.send(create);
|
||||
deferred.addCallback(new Callback<ResultSet<Group>, ResultSet<Group>>() {
|
||||
@Override
|
||||
public ResultSet<Group> call(ResultSet<Group> groups) throws Exception {
|
||||
Assert.assertEquals(1, groups.getResults().size());
|
||||
Assert.assertEquals(name, groups.getResults().get(0).getName());
|
||||
return groups;
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@Override
|
||||
public Error call(Error error) throws Exception {
|
||||
Assert.fail("Should not reach this point.");
|
||||
return error;
|
||||
}
|
||||
});
|
||||
deferred.join(2000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Session> deferred1 = client1.register(auth1);
|
||||
deferred1.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
return client1.connect(session);
|
||||
}
|
||||
}).addCallback(new Callback<Session, Session>() {
|
||||
@Override
|
||||
public Session call(Session session) throws Exception {
|
||||
session1 = session;
|
||||
return session;
|
||||
}
|
||||
}).join(2000);
|
||||
|
||||
AuthenticateMessage auth2 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString());
|
||||
final Deferred<Session> deferred2 = client2.register(auth2);
|
||||
deferred2.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
return client2.connect(session);
|
||||
}
|
||||
}).addCallback(new Callback<Session, Session>() {
|
||||
@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<ResultSet<Group>> deferred = client1.send(create);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Boolean>, ResultSet<Group>>() {
|
||||
@Override
|
||||
public Deferred<Boolean> call(ResultSet<Group> 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<Deferred<ResultSet<GroupSelf>>, Boolean>() {
|
||||
@Override
|
||||
public Deferred<ResultSet<GroupSelf>> call(Boolean success) throws Exception {
|
||||
Assert.assertTrue(success);
|
||||
GroupsSelfListMessage list = GroupsSelfListMessage.Builder.build();
|
||||
return client2.send(list);
|
||||
}
|
||||
}).addCallback(new Callback<ResultSet<GroupSelf>, ResultSet<GroupSelf>>() {
|
||||
@Override
|
||||
public ResultSet<GroupSelf> call(ResultSet<GroupSelf> 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<Error, Error>() {
|
||||
@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<ResultSet<Group>> deferred = client1.send(create);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Boolean>, ResultSet<Group>>() {
|
||||
@Override
|
||||
public Deferred<Boolean> call(ResultSet<Group> 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<Deferred<ResultSet<GroupSelf>>, Boolean>() {
|
||||
@Override
|
||||
public Deferred<ResultSet<GroupSelf>> call(Boolean success) throws Exception {
|
||||
Assert.assertTrue(success);
|
||||
GroupsSelfListMessage list = GroupsSelfListMessage.Builder.build();
|
||||
return client2.send(list);
|
||||
}
|
||||
}).addCallback(new Callback<ResultSet<GroupSelf>, ResultSet<GroupSelf>>() {
|
||||
@Override
|
||||
public ResultSet<GroupSelf> call(ResultSet<GroupSelf> groups) throws Exception {
|
||||
Assert.assertEquals(0, groups.getResults().size());
|
||||
return groups;
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@Override
|
||||
public Error call(Error error) throws Exception {
|
||||
Assert.fail("Should not reach this point.");
|
||||
return error;
|
||||
}
|
||||
});
|
||||
deferred.join(2000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Session> deferred = client.register(auth);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> 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<Boolean> deferred = client.send(remove);
|
||||
deferred.addCallback(new Callback<Boolean, Boolean>() {
|
||||
@Override
|
||||
public Boolean call(Boolean success) throws Exception {
|
||||
Assert.fail("Should not reach this point.");
|
||||
return success;
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@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<ResultSet<Group>> deferred = client.send(create);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Boolean>, ResultSet<Group>>() {
|
||||
@Override
|
||||
public Deferred<Boolean> call(ResultSet<Group> 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<Error, Error>() {
|
||||
@Override
|
||||
public Error call(Error error) throws Exception {
|
||||
Assert.fail("Should not reach this point.");
|
||||
return error;
|
||||
}
|
||||
});
|
||||
deferred.join(2000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Session> deferred = client.register(auth);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> 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<RpcResult> deferred = client.send(rpc);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<ResultSet<LeaderboardRecord>>, RpcResult>() {
|
||||
@Override
|
||||
public Deferred<ResultSet<LeaderboardRecord>> call(RpcResult result) throws Exception {
|
||||
LeaderboardRecordsListMessage list = LeaderboardRecordsListMessage.Builder.newBuilder(leaderboardId).limit(10).build();
|
||||
return client.send(list);
|
||||
}
|
||||
}).addCallbackDeferring(new Callback<Deferred<ResultSet<LeaderboardRecord>>, ResultSet<LeaderboardRecord>>() {
|
||||
@Override
|
||||
public Deferred<ResultSet<LeaderboardRecord>> call(ResultSet<LeaderboardRecord> 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<LeaderboardRecord>, ResultSet<LeaderboardRecord>>() {
|
||||
@Override
|
||||
public ResultSet<LeaderboardRecord> call(ResultSet<LeaderboardRecord> records) throws Exception {
|
||||
Assert.assertEquals(5, records.getResults().size());
|
||||
return records;
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@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<RpcResult> deferred = client.send(rpc);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<ResultSet<LeaderboardRecord>>, RpcResult>() {
|
||||
@Override
|
||||
public Deferred<ResultSet<LeaderboardRecord>> 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<Deferred<ResultSet<LeaderboardRecord>>, ResultSet<LeaderboardRecord>>() {
|
||||
@Override
|
||||
public Deferred<ResultSet<LeaderboardRecord>> call(ResultSet<LeaderboardRecord> records) throws Exception {
|
||||
LeaderboardRecordsListMessage list = LeaderboardRecordsListMessage.Builder.newBuilder(leaderboardId)
|
||||
.limit(10)
|
||||
.filterByPagingToOwnerId(session.getId())
|
||||
.build();
|
||||
return client.send(list);
|
||||
}
|
||||
}).addCallback(new Callback<ResultSet<LeaderboardRecord>, ResultSet<LeaderboardRecord>>() {
|
||||
@Override
|
||||
public ResultSet<LeaderboardRecord> call(ResultSet<LeaderboardRecord> records) throws Exception {
|
||||
Assert.assertEquals(10, records.getResults().size());
|
||||
Assert.assertNotNull(records.getCursor());
|
||||
return records;
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@Override
|
||||
public Error call(Error error) throws Exception {
|
||||
Assert.fail("Should not reach this point.");
|
||||
return error;
|
||||
}
|
||||
});
|
||||
deferred.join(2000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import org.junit.Test;
|
||||
|
||||
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 class MatchmakeAddMessageTest {
|
||||
latch3.countDown();
|
||||
}
|
||||
@Override public void onMatchPresence(MatchPresence matchPresence) {}
|
||||
@Override public void onNotifications(List<Notification> notifications) {}
|
||||
}).build();
|
||||
Assert.assertNotNull(client1);
|
||||
latch1 = new CountDownLatch(1);
|
||||
@@ -76,6 +78,7 @@ public class MatchmakeAddMessageTest {
|
||||
}
|
||||
@Override public void onMatchData(MatchData matchData) {}
|
||||
@Override public void onMatchPresence(MatchPresence matchPresence) {}
|
||||
@Override public void onNotifications(List<Notification> notifications) {}
|
||||
}).build();
|
||||
Assert.assertNotNull(client2);
|
||||
latch2 = new CountDownLatch(1);
|
||||
@@ -181,6 +184,4 @@ public class MatchmakeAddMessageTest {
|
||||
Assert.assertNotNull(data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -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<Session> deferred = client.register(auth);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> 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<RpcResult> deferred = client.send(rpc);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<ResultSet<Notification>>, RpcResult>() {
|
||||
@Override
|
||||
public Deferred<ResultSet<Notification>> call(RpcResult result) throws Exception {
|
||||
NotificationsListMessage list = NotificationsListMessage.Builder.newBuilder(10).build();
|
||||
return client.send(list);
|
||||
}
|
||||
}).addCallbackDeferring(new Callback<Deferred<ResultSet<Notification>>, ResultSet<Notification>>() {
|
||||
@Override
|
||||
public Deferred<ResultSet<Notification>> call(ResultSet<Notification> 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<Notification>, ResultSet<Notification>>() {
|
||||
@Override
|
||||
public ResultSet<Notification> call(ResultSet<Notification> notifications) throws Exception {
|
||||
Assert.assertEquals(5, notifications.getResults().size());
|
||||
return notifications;
|
||||
}
|
||||
}).addErrback(new Callback<Error, Error>() {
|
||||
@Override
|
||||
public Error call(Error error) throws Exception {
|
||||
Assert.fail("Should not reach this point.");
|
||||
return error;
|
||||
}
|
||||
});
|
||||
deferred.join(2000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,41 +24,66 @@ import java.util.UUID;
|
||||
|
||||
public class StorageListMessageTest {
|
||||
|
||||
private Client client;
|
||||
private String userId;
|
||||
private Client client1;
|
||||
private Client client2;
|
||||
|
||||
private Session session1;
|
||||
private Session session2;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
client = DefaultClient.builder("defaultkey").build();
|
||||
Assert.assertNotNull(client);
|
||||
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<Session> deferred1 = client1.register(auth1);
|
||||
deferred1.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
return client1.connect(session);
|
||||
}
|
||||
}).addCallback(new Callback<Session, Session>() {
|
||||
@Override
|
||||
public Session call(Session session) throws Exception {
|
||||
session1 = session;
|
||||
return session;
|
||||
}
|
||||
}).join(2000);
|
||||
|
||||
AuthenticateMessage auth2 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString());
|
||||
final Deferred<Session> deferred2 = client2.register(auth2);
|
||||
deferred2.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
return client2.connect(session);
|
||||
}
|
||||
}).addCallback(new Callback<Session, Session>() {
|
||||
@Override
|
||||
public Session call(Session session) throws Exception {
|
||||
session2 = session;
|
||||
return session;
|
||||
}
|
||||
}).join(2000);
|
||||
}
|
||||
|
||||
@After
|
||||
public void teardown() throws Exception {
|
||||
client.disconnect().join(2000);
|
||||
client1.disconnect().join(2000);
|
||||
client2.disconnect().join(2000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListNoRecords() throws Exception {
|
||||
final String deviceId = UUID.randomUUID().toString();
|
||||
final AuthenticateMessage auth = AuthenticateMessage.Builder.device(deviceId);
|
||||
final String bucket = UUID.randomUUID().toString();
|
||||
|
||||
final Deferred<Session> deferred = client.register(auth);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
return client.connect(session);
|
||||
}
|
||||
}).addCallbackDeferring(new Callback<Deferred<ResultSet<StorageRecord>>, Session>() {
|
||||
@Override
|
||||
public Deferred<ResultSet<StorageRecord>> call(Session session) throws Exception {
|
||||
final CollatedMessage<ResultSet<StorageRecord>> list = StorageListMessage.Builder.newBuilderBucket(bucket)
|
||||
final CollatedMessage<ResultSet<StorageRecord>> list = StorageListMessage.Builder.newBuilderBucket(bucket)
|
||||
.collection("collection")
|
||||
.build();
|
||||
return client.send(list);
|
||||
}
|
||||
}).addCallback(new Callback<ResultSet<StorageRecord>, ResultSet<StorageRecord>>() {
|
||||
final Deferred<ResultSet<StorageRecord>> deferred = client1.send(list);
|
||||
deferred.addCallback(new Callback<ResultSet<StorageRecord>, ResultSet<StorageRecord>>() {
|
||||
@Override
|
||||
public ResultSet<StorageRecord> call(ResultSet<StorageRecord> results) throws Exception {
|
||||
Assert.assertEquals(0, results.getResults().size());
|
||||
@@ -71,23 +96,10 @@ public class StorageListMessageTest {
|
||||
|
||||
@Test
|
||||
public void testList() throws Exception {
|
||||
final String deviceId = UUID.randomUUID().toString();
|
||||
final AuthenticateMessage auth = AuthenticateMessage.Builder.device(deviceId);
|
||||
|
||||
final String bucket = UUID.randomUUID().toString();
|
||||
final String value = "{\"foo\":\"bar\"}";
|
||||
|
||||
final Deferred<Session> deferred = client.register(auth);
|
||||
deferred.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
|
||||
@Override
|
||||
public Deferred<Session> call(Session session) throws Exception {
|
||||
userId = session.getId();
|
||||
return client.connect(session);
|
||||
}
|
||||
}).addCallbackDeferring(new Callback<Deferred<ResultSet<RecordId>>, Session>() {
|
||||
@Override
|
||||
public Deferred<ResultSet<RecordId>> call(Session session) throws Exception {
|
||||
final CollatedMessage<ResultSet<RecordId>> write = StorageWriteMessage.Builder.newBuilder()
|
||||
final CollatedMessage<ResultSet<RecordId>> write = StorageWriteMessage.Builder.newBuilder()
|
||||
.record(bucket, "collection", "record2", value,
|
||||
StorageRecord.PermissionRead.OWNER_READ, StorageRecord.PermissionWrite.OWNER_WRITE)
|
||||
.record(bucket, "collection", "record1", value,
|
||||
@@ -95,9 +107,8 @@ public class StorageListMessageTest {
|
||||
.record(bucket, "collection", "record3", value,
|
||||
StorageRecord.PermissionRead.OWNER_READ, StorageRecord.PermissionWrite.OWNER_WRITE)
|
||||
.build();
|
||||
return client.send(write);
|
||||
}
|
||||
}).addCallback(new Callback<ResultSet<RecordId>, ResultSet<RecordId>>() {
|
||||
final Deferred<ResultSet<RecordId>> deferred = client1.send(write);
|
||||
deferred.addCallback(new Callback<ResultSet<RecordId>, ResultSet<RecordId>>() {
|
||||
@Override
|
||||
public ResultSet<RecordId> call(ResultSet<RecordId> records) throws Exception {
|
||||
Assert.assertEquals(3, records.getResults().size());
|
||||
@@ -106,11 +117,11 @@ public class StorageListMessageTest {
|
||||
}).addCallbackDeferring(new Callback<Deferred<ResultSet<StorageRecord>>, ResultSet<RecordId>>() {
|
||||
@Override
|
||||
public Deferred<ResultSet<StorageRecord>> call(ResultSet<RecordId> records) throws Exception {
|
||||
final CollatedMessage<ResultSet<StorageRecord>> list = StorageListMessage.Builder.newBuilderUserId(userId)
|
||||
final CollatedMessage<ResultSet<StorageRecord>> list = StorageListMessage.Builder.newBuilderUserId(session1.getId())
|
||||
.bucket(bucket)
|
||||
.collection("collection")
|
||||
.build();
|
||||
return client.send(list);
|
||||
return client1.send(list);
|
||||
}
|
||||
}).addCallback(new Callback<ResultSet<StorageRecord>, ResultSet<StorageRecord>>() {
|
||||
@Override
|
||||
@@ -122,7 +133,53 @@ public class StorageListMessageTest {
|
||||
for (StorageRecord record : results.getResults()) {
|
||||
Assert.assertEquals(bucket, record.getBucket());
|
||||
Assert.assertEquals("collection", record.getCollection());
|
||||
Assert.assertEquals(userId, record.getUserId());
|
||||
Assert.assertEquals(session1.getId(), record.getUserId());
|
||||
Assert.assertEquals(value, record.getValue());
|
||||
}
|
||||
Assert.assertNull(results.getCursor());
|
||||
return results;
|
||||
}
|
||||
});
|
||||
deferred.join(2000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListOtherUser() throws Exception {
|
||||
final String bucket = UUID.randomUUID().toString();
|
||||
final String value = "{\"foo\":\"bar\"}";
|
||||
|
||||
final CollatedMessage<ResultSet<RecordId>> write = StorageWriteMessage.Builder.newBuilder()
|
||||
.record(bucket, "collection", "record2", value,
|
||||
StorageRecord.PermissionRead.OWNER_READ, StorageRecord.PermissionWrite.OWNER_WRITE)
|
||||
.record(bucket, "collection", "record1", value,
|
||||
StorageRecord.PermissionRead.OWNER_READ, StorageRecord.PermissionWrite.OWNER_WRITE)
|
||||
.record(bucket, "collection", "record3", value,
|
||||
StorageRecord.PermissionRead.PUBLIC_READ, StorageRecord.PermissionWrite.OWNER_WRITE)
|
||||
.build();
|
||||
final Deferred<ResultSet<RecordId>> deferred = client1.send(write);
|
||||
deferred.addCallback(new Callback<ResultSet<RecordId>, ResultSet<RecordId>>() {
|
||||
@Override
|
||||
public ResultSet<RecordId> call(ResultSet<RecordId> records) throws Exception {
|
||||
Assert.assertEquals(3, records.getResults().size());
|
||||
return records;
|
||||
}
|
||||
}).addCallbackDeferring(new Callback<Deferred<ResultSet<StorageRecord>>, ResultSet<RecordId>>() {
|
||||
@Override
|
||||
public Deferred<ResultSet<StorageRecord>> call(ResultSet<RecordId> records) throws Exception {
|
||||
final CollatedMessage<ResultSet<StorageRecord>> list = StorageListMessage.Builder.newBuilderBucket(bucket)
|
||||
.collection("collection")
|
||||
.build();
|
||||
return client2.send(list);
|
||||
}
|
||||
}).addCallback(new Callback<ResultSet<StorageRecord>, ResultSet<StorageRecord>>() {
|
||||
@Override
|
||||
public ResultSet<StorageRecord> call(ResultSet<StorageRecord> results) throws Exception {
|
||||
Assert.assertEquals(1, results.getResults().size());
|
||||
Assert.assertEquals("record3", results.getResults().get(0).getKey());
|
||||
for (StorageRecord record : results.getResults()) {
|
||||
Assert.assertEquals(bucket, record.getBucket());
|
||||
Assert.assertEquals("collection", record.getCollection());
|
||||
Assert.assertEquals(session1.getId(), record.getUserId());
|
||||
Assert.assertEquals(value, record.getValue());
|
||||
}
|
||||
Assert.assertNull(results.getCursor());
|
||||
|
||||
Reference in new issue
Block a user