Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
circles-android
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Circles
circles-android
Commits
f85a1365
Commit
f85a1365
authored
2 years ago
by
Taras
Browse files
Options
Downloads
Patches
Plain Diff
Create pushers manager
parent
0fa561a9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/main/java/org/futo/circles/feature/notifications/PushersManager.kt
+53
-0
53 additions, 0 deletions
.../org/futo/circles/feature/notifications/PushersManager.kt
with
53 additions
and
0 deletions
app/src/main/java/org/futo/circles/feature/notifications/PushersManager.kt
0 → 100644
+
53
−
0
View file @
f85a1365
package
org.futo.circles.feature.notifications
import
android.content.Context
import
org.futo.circles.BuildConfig
import
org.futo.circles.R
import
org.futo.circles.provider.MatrixSessionProvider
import
org.matrix.android.sdk.api.session.pushers.HttpPusher
import
java.util.*
import
kotlin.math.abs
private
const
val
DEFAULT_PUSHER_FILE_TAG
=
"mobile"
class
PushersManager
(
private
val
context
:
Context
)
{
fun
enqueueRegisterPusherWithFcmKey
(
pushKey
:
String
):
UUID
{
return
enqueueRegisterPusher
(
pushKey
,
context
.
getString
(
R
.
string
.
pusher_http_url
))
}
fun
enqueueRegisterPusher
(
pushKey
:
String
,
gateway
:
String
):
UUID
{
val
currentSession
=
MatrixSessionProvider
.
currentSession
val
pusher
=
createHttpPusher
(
pushKey
,
gateway
)
return
currentSession
?.
pushersService
()
?.
enqueueAddHttpPusher
(
pusher
)
?:
UUID
.
randomUUID
()
}
private
fun
createHttpPusher
(
pushKey
:
String
,
gateway
:
String
)
=
HttpPusher
(
pushKey
,
BuildConfig
.
APPLICATION_ID
,
profileTag
=
DEFAULT_PUSHER_FILE_TAG
+
"_"
+
abs
(
MatrixSessionProvider
.
currentSession
?.
myUserId
.
hashCode
()),
Locale
.
getDefault
().
language
,
context
.
getString
(
R
.
string
.
app_name
),
MatrixSessionProvider
.
currentSession
?.
sessionParams
?.
deviceId
?:
DEFAULT_PUSHER_FILE_TAG
,
gateway
,
enabled
=
true
,
deviceId
=
MatrixSessionProvider
.
currentSession
?.
sessionParams
?.
deviceId
?:
DEFAULT_PUSHER_FILE_TAG
,
append
=
false
,
withEventIdOnly
=
true
)
suspend
fun
unregisterPusher
(
pushKey
:
String
)
{
val
currentSession
=
MatrixSessionProvider
.
currentSession
?:
return
currentSession
.
pushersService
().
removeHttpPusher
(
pushKey
,
BuildConfig
.
APPLICATION_ID
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment