Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
b3cd934f
Commit
b3cd934f
authored
Jan 03, 2017
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PR feedback related stuff
parent
86b87261
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
89 additions
and
66 deletions
+89
-66
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+2
-2
ServerConfigActivity.java
...va/chat/rocket/android/activity/ServerConfigActivity.java
+2
-2
MethodCallHelper.java
...c/main/java/chat/rocket/android/api/MethodCallHelper.java
+0
-16
PushHelper.java
app/src/main/java/chat/rocket/android/api/PushHelper.java
+68
-0
PushUpdate.java
...ain/java/chat/rocket/android/model/params/PushUpdate.java
+0
-34
PushConstants.java
...src/main/java/chat/rocket/android/push/PushConstants.java
+4
-2
GcmInstanceIDListenerService.java
...rocket/android/push/gcm/GcmInstanceIDListenerService.java
+4
-4
GcmRegistrationIntentService.java
...rocket/android/push/gcm/GcmRegistrationIntentService.java
+5
-5
CurrentUserObserver.java
.../rocket/android/service/observer/CurrentUserObserver.java
+4
-1
No files found.
app/src/main/AndroidManifest.xml
View file @
b3cd934f
...
...
@@ -59,14 +59,14 @@
</intent-filter>
</service>
<service
android:name=
".push.gcm.
Push
InstanceIDListenerService"
android:name=
".push.gcm.
Gcm
InstanceIDListenerService"
android:exported=
"false"
>
<intent-filter>
<action
android:name=
"com.google.android.gms.iid.InstanceID"
/>
</intent-filter>
</service>
<service
android:name=
".push.gcm.RegistrationIntentService"
android:name=
".push.gcm.
Gcm
RegistrationIntentService"
android:exported=
"false"
/>
</application>
...
...
app/src/main/java/chat/rocket/android/activity/ServerConfigActivity.java
View file @
b3cd934f
...
...
@@ -18,7 +18,7 @@ import chat.rocket.android.model.ServerConfig;
import
chat.rocket.android.model.ddp.PublicSetting
;
import
chat.rocket.android.model.ddp.PublicSettingsConstants
;
import
chat.rocket.android.model.internal.Session
;
import
chat.rocket.android.push.gcm.RegistrationIntentService
;
import
chat.rocket.android.push.gcm.
Gcm
RegistrationIntentService
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.realm_helper.RealmObjectObserver
;
import
chat.rocket.android.realm_helper.RealmStore
;
...
...
@@ -168,7 +168,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
.
executeTransaction
(
realm
->
realm
.
copyToRealmOrUpdate
(
serverConfig
))
.
continueWith
(
task
->
{
if
(
serverConfig
.
shouldSyncPushToken
())
{
Intent
intent
=
new
Intent
(
this
,
RegistrationIntentService
.
class
);
Intent
intent
=
new
Intent
(
this
,
Gcm
RegistrationIntentService
.
class
);
startService
(
intent
);
}
...
...
app/src/main/java/chat/rocket/android/api/MethodCallHelper.java
View file @
b3cd934f
package
chat
.
rocket
.
android
.
api
;
import
android.content.Context
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.util.Patterns
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
...
...
@@ -19,7 +17,6 @@ import chat.rocket.android.model.ddp.PublicSetting;
import
chat.rocket.android.model.ddp.RoomSubscription
;
import
chat.rocket.android.model.internal.MethodCall
;
import
chat.rocket.android.model.internal.Session
;
import
chat.rocket.android.model.params.PushUpdate
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.realm_helper.RealmStore
;
import
chat.rocket.android_ddp.DDPClientCallback
;
...
...
@@ -307,19 +304,6 @@ public class MethodCallHelper {
.
onSuccessTask
(
task
->
Task
.
forResult
(
null
));
}
public
Task
<
Void
>
pushUpdate
(
@NonNull
String
pushId
,
@NonNull
String
token
,
@Nullable
String
userId
)
{
return
call
(
"raix:push-update"
,
TIMEOUT_MS
,
()
->
{
JSONObject
param
=
new
PushUpdate
(
pushId
,
token
,
userId
).
toJson
();
return
new
JSONArray
().
put
(
param
);
}).
onSuccessTask
(
task
->
Task
.
forResult
(
null
));
}
public
Task
<
Void
>
pushSetUser
(
String
pushId
)
{
return
call
(
"raix:push-setuser"
,
TIMEOUT_MS
,
()
->
new
JSONArray
().
put
(
pushId
))
.
onSuccessTask
(
task
->
Task
.
forResult
(
null
));
}
/**
* send message.
*/
...
...
app/src/main/java/chat/rocket/android/api/PushHelper.java
0 → 100644
View file @
b3cd934f
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
(
String
serverConfigId
)
{
super
(
serverConfigId
);
}
public
PushHelper
(
Context
context
,
String
serverConfigId
)
{
super
(
context
,
serverConfigId
);
}
public
PushHelper
(
RealmHelper
realmHelper
,
DDPClientWrapper
ddpClient
)
{
super
(
realmHelper
,
ddpClient
);
}
public
Task
<
Void
>
pushUpdate
(
@NonNull
String
pushId
,
@NonNull
String
token
,
@Nullable
String
userId
)
{
return
call
(
"raix:push-update"
,
TIMEOUT_MS
,
()
->
{
JSONObject
param
=
new
PushUpdate
(
pushId
,
token
,
userId
).
toJson
();
return
new
JSONArray
().
put
(
param
);
}).
onSuccessTask
(
task
->
Task
.
forResult
(
null
));
}
public
Task
<
Void
>
pushSetUser
(
String
pushId
)
{
return
call
(
"raix:push-setuser"
,
TIMEOUT_MS
,
()
->
new
JSONArray
().
put
(
pushId
))
.
onSuccessTask
(
task
->
Task
.
forResult
(
null
));
}
private
static
class
PushUpdate
{
private
String
pushId
;
private
String
gcmToken
;
private
String
userId
;
PushUpdate
(
@NonNull
String
pushId
,
@NonNull
String
gcmToken
,
@Nullable
String
userId
)
{
this
.
pushId
=
pushId
;
this
.
gcmToken
=
gcmToken
;
this
.
userId
=
userId
;
}
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
;
}
}
}
app/src/main/java/chat/rocket/android/model/params/PushUpdate.java
deleted
100644 → 0
View file @
86b87261
package
chat
.
rocket
.
android
.
model
.
params
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
public
class
PushUpdate
{
private
String
pushId
;
private
String
gcmToken
;
private
String
userId
;
public
PushUpdate
(
@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
;
}
}
app/src/main/java/chat/rocket/android/push/PushConstants.java
View file @
b3cd934f
...
...
@@ -7,8 +7,6 @@ public interface PushConstants {
String
TITLE
=
"title"
;
String
NOT_ID
=
"notId"
;
String
PUSH_BUNDLE
=
"pushBundle"
;
String
SERVER_CONFIG_ID
=
"serverConfigId"
;
String
ROOM_ID
=
"roomId"
;
String
ICON
=
"icon"
;
String
ICON_COLOR
=
"iconColor"
;
String
SOUND
=
"sound"
;
...
...
@@ -70,4 +68,8 @@ public interface PushConstants {
String
TWILIO_SOUND
=
"twi_sound"
;
String
START_IN_BACKGROUND
=
"cdvStartInBackground"
;
String
FORCE_START
=
"force-start"
;
// RC specific constants
String
SERVER_CONFIG_ID
=
"serverConfigId"
;
String
ROOM_ID
=
"roomId"
;
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/push/gcm/
Push
InstanceIDListenerService.java
→
app/src/main/java/chat/rocket/android/push/gcm/
Gcm
InstanceIDListenerService.java
View file @
b3cd934f
...
...
@@ -11,19 +11,19 @@ import chat.rocket.android.model.ddp.PublicSettingsConstants;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.realm_helper.RealmStore
;
public
class
Push
InstanceIDListenerService
extends
InstanceIDListenerService
{
public
class
Gcm
InstanceIDListenerService
extends
InstanceIDListenerService
{
@Override
public
void
onTokenRefresh
()
{
List
<
ServerConfig
>
serverConfigs
=
getServerConfigs
();
flagForRefresh
(
serverConfigs
);
updateSyncPushToken
(
serverConfigs
);
if
(!
shouldRefreshToken
(
serverConfigs
))
{
return
;
}
Intent
intent
=
new
Intent
(
this
,
RegistrationIntentService
.
class
);
Intent
intent
=
new
Intent
(
this
,
Gcm
RegistrationIntentService
.
class
);
startService
(
intent
);
}
...
...
@@ -32,7 +32,7 @@ public class PushInstanceIDListenerService extends InstanceIDListenerService {
realm
->
realm
.
where
(
ServerConfig
.
class
).
findAll
());
}
private
void
flagForRefresh
(
List
<
ServerConfig
>
serverConfigs
)
{
private
void
updateSyncPushToken
(
List
<
ServerConfig
>
serverConfigs
)
{
final
RealmHelper
realmHelper
=
RealmStore
.
getDefault
();
for
(
final
ServerConfig
serverConfig
:
serverConfigs
)
{
...
...
app/src/main/java/chat/rocket/android/push/gcm/RegistrationIntentService.java
→
app/src/main/java/chat/rocket/android/push/gcm/
Gcm
RegistrationIntentService.java
View file @
b3cd934f
...
...
@@ -9,7 +9,7 @@ import com.google.android.gms.iid.InstanceID;
import
java.io.IOException
;
import
java.util.List
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.api.
MethodCall
Helper
;
import
chat.rocket.android.api.
Push
Helper
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.model.ddp.PublicSetting
;
import
chat.rocket.android.model.ddp.PublicSettingsConstants
;
...
...
@@ -17,10 +17,10 @@ import chat.rocket.android.model.ddp.User;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.realm_helper.RealmStore
;
public
class
RegistrationIntentService
extends
IntentService
{
public
class
Gcm
RegistrationIntentService
extends
IntentService
{
public
RegistrationIntentService
()
{
super
(
"RegistrationIntentService"
);
public
Gcm
RegistrationIntentService
()
{
super
(
"
Gcm
RegistrationIntentService"
);
}
@Override
...
...
@@ -59,7 +59,7 @@ public class RegistrationIntentService extends IntentService {
final
User
currentUser
=
realmHelper
.
executeTransactionForRead
(
realm
->
User
.
queryCurrentUser
(
realm
).
findFirst
());
new
MethodCall
Helper
(
serverConfig
.
getServerConfigId
()).
pushUpdate
(
new
Push
Helper
(
serverConfig
.
getServerConfigId
()).
pushUpdate
(
RocketChatCache
.
getPushId
(
this
),
token
,
currentUser
!=
null
?
currentUser
.
getId
()
:
null
)
.
onSuccess
(
task
->
{
markRefreshAsDone
(
serverConfig
);
...
...
app/src/main/java/chat/rocket/android/service/observer/CurrentUserObserver.java
View file @
b3cd934f
...
...
@@ -9,6 +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.helper.LogcatIfError
;
import
chat.rocket.android.model.ddp.User
;
import
chat.rocket.android.realm_helper.RealmHelper
;
...
...
@@ -21,6 +22,7 @@ import hugo.weaving.DebugLog;
*/
public
class
CurrentUserObserver
extends
AbstractModelObserver
<
User
>
{
private
final
MethodCallHelper
methodCall
;
private
final
PushHelper
pushHelper
;
private
boolean
currentUserExists
;
private
ArrayList
<
Registrable
>
listeners
;
...
...
@@ -28,6 +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
);
currentUserExists
=
false
;
}
...
...
@@ -60,7 +63,7 @@ public class CurrentUserObserver extends AbstractModelObserver<User> {
final
String
userId
=
user
.
getId
();
// update push info
methodCall
.
pushSetUser
(
RocketChatCache
.
getPushId
(
context
)).
continueWith
(
new
LogcatIfError
());
pushHelper
.
pushSetUser
(
RocketChatCache
.
getPushId
(
context
)).
continueWith
(
new
LogcatIfError
());
// get and observe Room subscriptions.
methodCall
.
getRoomSubscriptions
().
onSuccess
(
task
->
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment