Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed missing push token and create method for disable push notification #246

Merged
merged 5 commits into from

2 participants

@snoodlupa
Owner

No description provided.

Matteo and others added some commits
Matteo Merge pull request #40 from baasbox/master
pull request from repository baasbox
f56a529
Matteo Merge pull request #41 from baasbox/master
pull request from repository baasbox
e4c2603
Matteo Merge pull request #42 from baasbox/master
pull request from repository baasbox
468ce05
Matteo Merge pull request #43 from baasbox/master
pull request from repository baasbox
4ecfc56
lupatellimatteo fixed pushToken and insert disablePush method 4b82ba0
@snoodlupa snoodlupa merged commit 9b32797 into from
@giastfader giastfader added this to the 0.7.4 milestone
@giastfader giastfader added the Feature label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 6, 2014
  1. Merge pull request #40 from baasbox/master

    Matteo authored
    pull request from repository baasbox
  2. Merge pull request #41 from baasbox/master

    Matteo authored
    pull request from repository baasbox
Commits on Feb 11, 2014
  1. Merge pull request #42 from baasbox/master

    Matteo authored
    pull request from repository baasbox
Commits on Feb 17, 2014
  1. Merge pull request #43 from baasbox/master

    Matteo authored
    pull request from repository baasbox
  2. fixed pushToken and insert disablePush method

    lupatellimatteo authored
This page is out of date. Refresh to see the latest.
View
10 app/com/baasbox/controllers/Push.java
@@ -93,6 +93,16 @@ public static Result enablePush(String os, String pushToken) throws SqlInjection
return ok();
}
+
+ public static Result disablePush(String pushToken) throws SqlInjectionException{
+ if (Logger.isTraceEnabled()) Logger.trace("Method Start");
+ if(pushToken==null) return badRequest("pushToken value doesn't not null");
+ if (Logger.isDebugEnabled()) Logger.debug("Trying to disable push to pushToken: "+ pushToken);
+ UserService.unregisterDevice(pushToken);
+ if (Logger.isTraceEnabled()) Logger.trace("Method End");
+ return ok();
+
+ }
/*
View
10 app/com/baasbox/service/push/PushService.java
@@ -58,17 +58,17 @@ public void send(String message, String username) throws PushNotInitializedExcep
List<ODocument> loginInfos=userSystemProperties.field(UserDao.USER_LOGIN_INFO);
if (Logger.isDebugEnabled()) Logger.debug("Sending to " + loginInfos.size() + " devices");
for(ODocument loginInfo : loginInfos){
- String deviceId=loginInfo.field(UserDao.USER_PUSH_TOKEN);
+ String pushToken=loginInfo.field(UserDao.USER_PUSH_TOKEN);
String vendor=loginInfo.field(UserDao.USER_DEVICE_OS);
- if (Logger.isDebugEnabled()) Logger.debug ("deviceId: " + deviceId);
- if (Logger.isDebugEnabled()) Logger.debug ("vendor: " + vendor);
- if(!StringUtils.isEmpty(vendor) && !StringUtils.isEmpty(deviceId)){
+ if (Logger.isDebugEnabled()) Logger.debug ("push token: " + pushToken);
+ if (Logger.isDebugEnabled()) Logger.debug ("vendor: " + vendor);
+ if(!StringUtils.isEmpty(vendor) && !StringUtils.isEmpty(pushToken)){
VendorOS vos = VendorOS.getVendorOs(vendor);
if (Logger.isDebugEnabled()) Logger.debug("vos: " + vos);
if (vos!=null){
IPushServer pushServer = Factory.getIstance(vos);
pushServer.setConfiguration(getPushParameters());
- pushServer.send(message, deviceId);
+ pushServer.send(message, pushToken);
} //vos!=null
}//(!StringUtils.isEmpty(vendor) && !StringUtils.isEmpty(deviceId)
View
22 app/com/baasbox/service/user/UserService.java
@@ -138,11 +138,11 @@ public static void registerDevice(HashMap<String,Object> data) throws SqlInjecti
ODocument user=getCurrentUser();
ODocument systemProps=user.field(UserDao.ATTRIBUTES_SYSTEM);
ArrayList<ODocument> loginInfos=systemProps.field(UserDao.USER_LOGIN_INFO);
- String deviceId=(String) data.get(UserDao.USER_PUSH_TOKEN);
+ String pushToken=(String) data.get(UserDao.USER_PUSH_TOKEN);
boolean found=false;
for (ODocument loginInfo : loginInfos){
- if (loginInfo.field(UserDao.USER_PUSH_TOKEN)!=null && loginInfo.field(UserDao.USER_PUSH_TOKEN).equals(deviceId)){
+ if (loginInfo.field(UserDao.USER_PUSH_TOKEN)!=null && loginInfo.field(UserDao.USER_PUSH_TOKEN).equals(pushToken)){
found=true;
break;
}
@@ -152,13 +152,27 @@ public static void registerDevice(HashMap<String,Object> data) throws SqlInjecti
systemProps.save();
}
}
+ public static void unregisterDevice(String pushToken) throws SqlInjectionException{
+ ODocument user=getCurrentUser();
+ ODocument systemProps=user.field(UserDao.ATTRIBUTES_SYSTEM);
+ ArrayList<ODocument> loginInfos=systemProps.field(UserDao.USER_LOGIN_INFO);
+ for (ODocument loginInfo : loginInfos){
+ if (loginInfo.field(UserDao.USER_PUSH_TOKEN)!=null && loginInfo.field(UserDao.USER_PUSH_TOKEN).equals(pushToken)){
+ loginInfos.remove(loginInfo);
+ break;
+ }
+ }
+ systemProps.save();
+ }
+
+
- public static void logout(String deviceId) throws SqlInjectionException {
+ public static void logout(String pushToken) throws SqlInjectionException {
ODocument user=getCurrentUser();
ODocument systemProps=user.field(UserDao.ATTRIBUTES_SYSTEM);
ArrayList<ODocument> loginInfos=systemProps.field(UserDao.USER_LOGIN_INFO);
for (ODocument loginInfo : loginInfos){
- if (loginInfo.field(UserDao.USER_PUSH_TOKEN)!=null && loginInfo.field(UserDao.USER_PUSH_TOKEN).equals(deviceId)){
+ if (loginInfo.field(UserDao.USER_PUSH_TOKEN)!=null && loginInfo.field(UserDao.USER_PUSH_TOKEN).equals(pushToken)){
loginInfos.remove(loginInfo);
break;
}
View
1  conf/routes
@@ -85,6 +85,7 @@ DELETE /admin/follow/:follower/to/:theFollowed com.baasbox.controllers.Admin.r
# Push
POST /push/message/:username com.baasbox.controllers.Push.send(username: String)
PUT /push/enable/:os/:pushToken com.baasbox.controllers.Push.enablePush(os: String, pushToken: String)
+PUT /push/disable/:pushToken com.baasbox.controllers.Push.disablePush(pushToken: String)
#deprecated
PUT /push/device/:os/:deviceId com.baasbox.controllers.Push.enablePush(os: String, deviceId: String)
Something went wrong with that request. Please try again.