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
55a83698
Commit
55a83698
authored
Dec 26, 2017
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add GcmPushHelper class with a few helper functions to get tokens and sendId
parent
6f80a3c4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
+38
-0
GcmPushHelper.kt
...c/main/java/chat/rocket/android/push/gcm/GcmPushHelper.kt
+38
-0
No files found.
app/src/main/java/chat/rocket/android/push/gcm/GcmPushHelper.kt
0 → 100644
View file @
55a83698
package
chat.rocket.android.push.gcm
import
bolts.Task
import
chat.rocket.android.R
import
chat.rocket.android.RocketChatApplication
import
chat.rocket.android.RocketChatCache
import
chat.rocket.android.api.RaixPushHelper
import
chat.rocket.persistence.realm.RealmHelper
import
chat.rocket.persistence.realm.models.ddp.RealmUser
import
com.google.android.gms.gcm.GoogleCloudMessaging
import
com.google.android.gms.iid.InstanceID
import
java.io.IOException
object
GcmPushHelper
{
fun
getGcmToken
():
String
?
=
getGcmToken
(
getSenderId
())
@Throws
(
IOException
::
class
)
private
fun
registerGcmTokenForServer
(
realmHelper
:
RealmHelper
):
Task
<
Void
>
{
val
gcmToken
=
getGcmToken
(
getSenderId
())
val
currentUser
=
realmHelper
.
executeTransactionForRead
({
realm
->
RealmUser
.
queryCurrentUser
(
realm
).
findFirst
()
})
val
userId
=
if
(
currentUser
!=
null
)
currentUser
.
getId
()
else
null
val
pushId
=
RocketChatCache
.
getOrCreatePushId
()
return
RaixPushHelper
(
realmHelper
)
.
pushUpdate
(
pushId
!!
,
gcmToken
,
userId
)
}
@Throws
(
IOException
::
class
)
private
fun
getGcmToken
(
senderId
:
String
):
String
{
return
InstanceID
.
getInstance
(
RocketChatApplication
.
getInstance
())
.
getToken
(
senderId
,
GoogleCloudMessaging
.
INSTANCE_ID_SCOPE
,
null
)
}
private
fun
getSenderId
():
String
{
return
RocketChatApplication
.
getInstance
().
getString
(
R
.
string
.
gcm_sender_id
)
}
}
\ No newline at end of file
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