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
4d709b6e
Commit
4d709b6e
authored
Jan 09, 2017
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove push interactor.
parent
b6b6ef68
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
67 deletions
+27
-67
PushNotificationHandler.java
...ava/chat/rocket/android/push/PushNotificationHandler.java
+12
-9
GCMIntentService.java
...n/java/chat/rocket/android/push/gcm/GCMIntentService.java
+3
-12
GcmRegistrationIntentService.java
...rocket/android/push/gcm/GcmRegistrationIntentService.java
+8
-15
DefaultPushInteractor.java
...ocket/android/push/interactors/DefaultPushInteractor.java
+0
-19
PushInteractor.java
.../chat/rocket/android/push/interactors/PushInteractor.java
+0
-5
PushSettingsObserver.java
...rocket/android/service/observer/PushSettingsObserver.java
+4
-7
No files found.
app/src/main/java/chat/rocket/android/push/PushNotificationHandler.java
View file @
4d709b6e
...
...
@@ -20,7 +20,6 @@ import android.support.v4.util.SparseArrayCompat;
import
android.text.Html
;
import
android.text.Spanned
;
import
android.util.Log
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -32,7 +31,9 @@ import java.net.URL;
import
java.util.ArrayList
;
import
java.util.Random
;
import
chat.rocket.android.activity.MainActivity
;
import
chat.rocket.android.push.interactors.PushInteractor
;
import
chat.rocket.android.helper.ServerPolicyHelper
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.realm_helper.RealmStore
;
public
class
PushNotificationHandler
implements
PushConstants
{
...
...
@@ -56,8 +57,7 @@ public class PushNotificationHandler implements PushConstants {
}
}
public
void
showNotificationIfPossible
(
Context
context
,
PushInteractor
pushInteractor
,
Bundle
extras
)
{
public
void
showNotificationIfPossible
(
Context
context
,
Bundle
extras
)
{
// Send a notification if there is a message or title, otherwise just send data
String
message
=
extras
.
getString
(
MESSAGE
);
...
...
@@ -79,11 +79,11 @@ public class PushNotificationHandler implements PushConstants {
extras
.
putString
(
TITLE
,
getAppName
(
context
));
}
createNotification
(
context
,
pushInteractor
,
extras
);
createNotification
(
context
,
extras
);
}
}
public
void
createNotification
(
Context
context
,
PushInteractor
pushInteractor
,
Bundle
extras
)
{
public
void
createNotification
(
Context
context
,
Bundle
extras
)
{
NotificationManager
mNotificationManager
=
(
NotificationManager
)
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
String
appName
=
getAppName
(
context
);
...
...
@@ -97,8 +97,11 @@ public class PushNotificationHandler implements PushConstants {
return
;
}
String
serverConfigId
=
pushInteractor
.
getServerConfigId
(
serverUrl
);
if
(
serverConfigId
==
null
)
{
ServerConfig
serverConfig
=
RealmStore
.
getDefault
().
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
)
.
equalTo
(
ServerConfig
.
HOSTNAME
,
ServerPolicyHelper
.
enforceHostname
(
serverUrl
))
.
findFirst
());
if
(
serverConfig
==
null
)
{
return
;
}
...
...
@@ -106,7 +109,7 @@ public class PushNotificationHandler implements PushConstants {
Intent
notificationIntent
=
new
Intent
(
context
,
MainActivity
.
class
);
notificationIntent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_SINGLE_TOP
|
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
);
notificationIntent
.
putExtra
(
PUSH_BUNDLE
,
extras
);
notificationIntent
.
putExtra
(
SERVER_CONFIG_ID
,
serverConfig
Id
);
notificationIntent
.
putExtra
(
SERVER_CONFIG_ID
,
serverConfig
.
getServerConfigId
()
);
notificationIntent
.
putExtra
(
ROOM_ID
,
roomId
);
notificationIntent
.
putExtra
(
NOT_ID
,
notId
);
...
...
app/src/main/java/chat/rocket/android/push/gcm/GCMIntentService.java
View file @
4d709b6e
package
chat
.
rocket
.
android
.
push
.
gcm
;
import
android.annotation.SuppressLint
;
import
com.google.android.gms.gcm.GcmListenerService
;
import
android.content.Context
;
import
android.content.res.Resources
;
import
android.os.Bundle
;
import
android.util.Log
;
import
com.google.android.gms.gcm.GcmListenerService
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -16,10 +14,7 @@ import java.util.ArrayList;
import
java.util.Iterator
;
import
chat.rocket.android.push.PushConstants
;
import
chat.rocket.android.push.PushNotificationHandler
;
import
chat.rocket.android.push.interactors.DefaultPushInteractor
;
import
chat.rocket.android.push.interactors.PushInteractor
;
@SuppressLint
(
"NewApi"
)
public
class
GCMIntentService
extends
GcmListenerService
implements
PushConstants
{
private
static
final
String
LOG_TAG
=
"GCMIntentService"
;
...
...
@@ -34,13 +29,9 @@ public class GCMIntentService extends GcmListenerService implements PushConstant
Context
applicationContext
=
getApplicationContext
();
PushInteractor
pushInteractor
=
new
DefaultPushInteractor
();
extras
=
normalizeExtras
(
applicationContext
,
extras
);
PushNotificationHandler
pushNotificationHandler
=
new
PushNotificationHandler
();
pushNotificationHandler
.
showNotificationIfPossible
(
applicationContext
,
pushInteractor
,
extras
);
new
PushNotificationHandler
().
showNotificationIfPossible
(
applicationContext
,
extras
);
}
/*
...
...
app/src/main/java/chat/rocket/android/push/gcm/GcmRegistrationIntentService.java
View file @
4d709b6e
...
...
@@ -25,22 +25,15 @@ public class GcmRegistrationIntentService extends IntentService {
@Override
protected
void
onHandleIntent
(
Intent
intent
)
{
final
List
<
ServerConfig
>
serverConfigs
=
getServerConfigs
();
final
List
<
ServerConfig
>
serverConfigs
=
RealmStore
.
getDefault
()
.
executeTransactionForReadResults
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
ServerConfig
.
SYNC_PUSH_TOKEN
,
true
).
findAll
());
for
(
ServerConfig
serverConfig
:
serverConfigs
)
{
sendTokenTo
(
serverConfig
);
registerGcmTokenForServer
(
serverConfig
);
}
}
private
List
<
ServerConfig
>
getServerConfigs
()
{
return
RealmStore
.
getDefault
().
executeTransactionForReadResults
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
findAll
());
}
private
void
sendTokenTo
(
final
ServerConfig
serverConfig
)
{
if
(!
serverConfig
.
shouldSyncPushToken
())
{
return
;
}
private
void
registerGcmTokenForServer
(
final
ServerConfig
serverConfig
)
{
final
RealmHelper
realmHelper
=
RealmStore
.
get
(
serverConfig
.
getServerConfigId
());
if
(
realmHelper
==
null
)
{
return
;
...
...
@@ -54,13 +47,13 @@ public class GcmRegistrationIntentService extends IntentService {
}
try
{
final
String
token
=
get
Token
(
senderId
);
final
String
gcmToken
=
getGcm
Token
(
senderId
);
final
User
currentUser
=
realmHelper
.
executeTransactionForRead
(
realm
->
User
.
queryCurrentUser
(
realm
).
findFirst
());
new
PushHelper
(
getBaseContext
(),
serverConfig
.
getServerConfigId
()).
pushUpdate
(
RocketChatCache
.
getPushId
(
this
),
t
oken
,
currentUser
!=
null
?
currentUser
.
getId
()
:
null
)
RocketChatCache
.
getPushId
(
this
),
gcmT
oken
,
currentUser
!=
null
?
currentUser
.
getId
()
:
null
)
.
onSuccess
(
task
->
{
markRefreshAsDone
(
serverConfig
);
return
task
;
...
...
@@ -69,7 +62,7 @@ public class GcmRegistrationIntentService extends IntentService {
}
}
private
String
getToken
(
String
senderId
)
throws
IOException
{
private
String
get
Gcm
Token
(
String
senderId
)
throws
IOException
{
return
InstanceID
.
getInstance
(
this
)
.
getToken
(
senderId
,
GoogleCloudMessaging
.
INSTANCE_ID_SCOPE
,
null
);
}
...
...
app/src/main/java/chat/rocket/android/push/interactors/DefaultPushInteractor.java
deleted
100644 → 0
View file @
b6b6ef68
package
chat
.
rocket
.
android
.
push
.
interactors
;
import
chat.rocket.android.helper.ServerPolicyHelper
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.realm_helper.RealmStore
;
public
class
DefaultPushInteractor
implements
PushInteractor
{
@Override
public
String
getServerConfigId
(
String
hostname
)
{
final
ServerConfig
serverConfig
=
RealmStore
.
getDefault
()
.
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
)
.
equalTo
(
ServerConfig
.
HOSTNAME
,
ServerPolicyHelper
.
enforceHostname
(
hostname
))
.
findFirst
());
return
serverConfig
!=
null
?
serverConfig
.
getServerConfigId
()
:
""
;
}
}
app/src/main/java/chat/rocket/android/push/interactors/PushInteractor.java
deleted
100644 → 0
View file @
b6b6ef68
package
chat
.
rocket
.
android
.
push
.
interactors
;
public
interface
PushInteractor
{
String
getServerConfigId
(
String
hostname
);
}
app/src/main/java/chat/rocket/android/service/observer/PushSettingsObserver.java
View file @
4d709b6e
...
...
@@ -8,12 +8,11 @@ import io.realm.RealmResults;
import
java.util.List
;
import
chat.rocket.android.api.DDPClientWrapper
;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.helper.ServerPolicyHelper
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.model.ddp.PublicSetting
;
import
chat.rocket.android.model.ddp.PublicSettingsConstants
;
import
chat.rocket.android.push.gcm.GcmRegistrationIntentService
;
import
chat.rocket.android.push.interactors.DefaultPushInteractor
;
import
chat.rocket.android.push.interactors.PushInteractor
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.realm_helper.RealmStore
;
...
...
@@ -28,11 +27,9 @@ public class PushSettingsObserver extends AbstractModelObserver<PublicSetting> {
public
void
onUpdateResults
(
List
<
PublicSetting
>
results
)
{
RealmHelper
realmHelper
=
RealmStore
.
getDefault
();
PushInteractor
interactor
=
new
DefaultPushInteractor
();
String
serverConfigId
=
interactor
.
getServerConfigId
(
hostname
);
final
ServerConfig
serverConfig
=
realmHelper
.
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
ServerConfig
.
ID
,
serverConfigId
)
final
ServerConfig
serverConfig
=
realmHelper
.
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
)
.
equalTo
(
ServerConfig
.
HOSTNAME
,
ServerPolicyHelper
.
enforceHostname
(
hostname
))
.
findFirst
());
serverConfig
.
setSyncPushToken
(
isPushEnabled
(
results
));
...
...
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