Commit c50327a8 authored by Yusuke Iwaki's avatar Yusuke Iwaki

rename PushHelper to RaixPushHelper

parent 14ea5777
......@@ -3,28 +3,31 @@ package chat.rocket.android.api;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import bolts.Task;
import chat.rocket.android.realm_helper.RealmHelper;
public class PushHelper extends MethodCallHelper {
public PushHelper(Context context, String serverConfigId) {
public class RaixPushHelper extends MethodCallHelper {
public RaixPushHelper(Context context, String serverConfigId) {
super(context, serverConfigId);
}
public PushHelper(RealmHelper realmHelper,
DDPClientWrapper ddpClient) {
public RaixPushHelper(RealmHelper realmHelper,
DDPClientWrapper ddpClient) {
super(realmHelper, ddpClient);
}
public Task<Void> pushUpdate(@NonNull String pushId, @NonNull String token,
public Task<Void> pushUpdate(@NonNull String pushId, @NonNull String gcmToken,
@Nullable String userId) {
return call("raix:push-update", TIMEOUT_MS,
() -> new JSONArray().put(new Params(pushId, token, userId).toJson()))
return call("raix:push-update", TIMEOUT_MS, () ->
new JSONArray().put(new JSONObject()
.put("id", pushId)
.put("appName", "main")
.put("userId", userId != null ? userId : JSONObject.NULL)
.put("metadata", new JSONObject())
.put("token", new JSONObject().put("gcm", gcmToken))))
.onSuccessTask(task -> Task.forResult(null));
}
......@@ -32,32 +35,4 @@ public class PushHelper extends MethodCallHelper {
return call("raix:push-setuser", TIMEOUT_MS, () -> new JSONArray().put(pushId))
.onSuccessTask(task -> Task.forResult(null));
}
private static class Params {
private String pushId;
private String gcmToken;
private String userId;
public Params(@NonNull String pushId, @NonNull String gcmToken, @Nullable String userId) {
this.pushId = pushId;
this.gcmToken = gcmToken;
this.userId = userId;
}
public JSONObject toJson() throws JSONException {
JSONObject param = new JSONObject();
param.put("id", pushId);
param.put("appName", "main");
param.put("userId", userId != null ? userId : JSONObject.NULL);
param.put("metadata", new JSONObject());
JSONObject tokenParam = new JSONObject();
tokenParam.put("gcm", gcmToken);
param.put("token", tokenParam);
return param;
}
}
}
......@@ -9,7 +9,7 @@ import android.content.Intent;
import java.io.IOException;
import java.util.List;
import chat.rocket.android.RocketChatCache;
import chat.rocket.android.api.PushHelper;
import chat.rocket.android.api.RaixPushHelper;
import chat.rocket.android.model.ServerConfig;
import chat.rocket.android.model.ddp.PublicSetting;
import chat.rocket.android.model.ddp.PublicSettingsConstants;
......@@ -52,7 +52,7 @@ public class GcmRegistrationIntentService extends IntentService {
final User currentUser = realmHelper.executeTransactionForRead(realm ->
User.queryCurrentUser(realm).findFirst());
new PushHelper(getBaseContext(), serverConfig.getServerConfigId()).pushUpdate(
new RaixPushHelper(getBaseContext(), serverConfig.getServerConfigId()).pushUpdate(
RocketChatCache.getPushId(this), gcmToken, currentUser != null ? currentUser.getId() : null)
.onSuccess(task -> {
markRefreshAsDone(serverConfig);
......
......@@ -9,7 +9,7 @@ import java.util.List;
import chat.rocket.android.RocketChatCache;
import chat.rocket.android.api.DDPClientWrapper;
import chat.rocket.android.api.MethodCallHelper;
import chat.rocket.android.api.PushHelper;
import chat.rocket.android.api.RaixPushHelper;
import chat.rocket.android.helper.LogcatIfError;
import chat.rocket.android.model.ddp.User;
import chat.rocket.android.realm_helper.RealmHelper;
......@@ -22,7 +22,7 @@ import hugo.weaving.DebugLog;
*/
public class CurrentUserObserver extends AbstractModelObserver<User> {
private final MethodCallHelper methodCall;
private final PushHelper pushHelper;
private final RaixPushHelper pushHelper;
private boolean currentUserExists;
private ArrayList<Registrable> listeners;
......@@ -30,7 +30,7 @@ public class CurrentUserObserver extends AbstractModelObserver<User> {
RealmHelper realmHelper, DDPClientWrapper ddpClient) {
super(context, hostname, realmHelper, ddpClient);
methodCall = new MethodCallHelper(realmHelper, ddpClient);
pushHelper = new PushHelper(realmHelper, ddpClient);
pushHelper = new RaixPushHelper(realmHelper, ddpClient);
currentUserExists = false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment