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
694084e3
Commit
694084e3
authored
Oct 22, 2017
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get the correct hostname as defined on login
parent
14b8833c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
16 deletions
+71
-16
PushManager.kt
app/src/main/java/chat/rocket/android/push/PushManager.kt
+71
-16
No files found.
app/src/main/java/chat/rocket/android/push/PushManager.kt
View file @
694084e3
...
@@ -33,6 +33,7 @@ import chat.rocket.persistence.realm.repositories.RealmUserRepository
...
@@ -33,6 +33,7 @@ import chat.rocket.persistence.realm.repositories.RealmUserRepository
import
io.reactivex.Single
import
io.reactivex.Single
import
io.reactivex.android.schedulers.AndroidSchedulers
import
io.reactivex.android.schedulers.AndroidSchedulers
import
io.reactivex.functions.BiFunction
import
io.reactivex.functions.BiFunction
import
okhttp3.HttpUrl
import
org.json.JSONObject
import
org.json.JSONObject
import
java.io.Serializable
import
java.io.Serializable
import
java.util.*
import
java.util.*
...
@@ -215,16 +216,18 @@ object PushManager {
...
@@ -215,16 +216,18 @@ object PushManager {
val
id
=
notificationId
.
toInt
()
val
id
=
notificationId
.
toInt
()
val
contentIntent
=
getContentIntent
(
context
,
id
,
lastPushMessage
,
singleConversation
=
true
)
val
contentIntent
=
getContentIntent
(
context
,
id
,
lastPushMessage
,
singleConversation
=
true
)
val
deleteIntent
=
getDismissIntent
(
context
,
lastPushMessage
)
val
deleteIntent
=
getDismissIntent
(
context
,
lastPushMessage
)
val
channelGroup
=
NotificationChannel
(
host
,
host
,
NotificationManager
.
IMPORTANCE_DEFAULT
)
val
groupChannel
=
NotificationChannel
(
host
,
host
,
NotificationManager
.
IMPORTANCE_HIGH
)
manager
.
createNotificationChannel
(
channelGroup
)
groupChannel
.
lockscreenVisibility
=
Notification
.
VISIBILITY_PUBLIC
groupChannel
.
enableLights
(
true
)
groupChannel
.
enableVibration
(
true
)
groupChannel
.
setShowBadge
(
true
)
manager
.
createNotificationChannel
(
groupChannel
)
val
builder
=
Notification
.
Builder
(
context
,
host
)
val
builder
=
Notification
.
Builder
(
context
,
host
)
.
setWhen
(
createdAt
)
.
setWhen
(
createdAt
)
.
setContentTitle
(
title
.
fromHtml
())
.
setContentTitle
(
title
.
fromHtml
())
.
setContentText
(
message
.
fromHtml
())
.
setContentText
(
message
.
fromHtml
())
.
setGroup
(
host
)
.
setGroup
(
host
)
.
setGroupSummary
(
true
)
.
setGroupSummary
(
true
)
.
setNumber
(
count
.
toInt
())
.
setCategory
(
Notification
.
CATEGORY_MESSAGE
)
.
setContentIntent
(
contentIntent
)
.
setContentIntent
(
contentIntent
)
.
setDeleteIntent
(
deleteIntent
)
.
setDeleteIntent
(
deleteIntent
)
.
setMessageNotification
(
context
)
.
setMessageNotification
(
context
)
...
@@ -234,16 +237,40 @@ object PushManager {
...
@@ -234,16 +237,40 @@ object PushManager {
builder
.
setSubText
(
subText
)
builder
.
setSubText
(
subText
)
}
}
val
messages
=
messageStack
.
get
(
notificationId
.
toInt
())
if
(
style
==
"inbox"
)
{
val
messageCount
=
messages
.
size
val
pushMessageList
=
hostToPushMessageList
.
get
(
host
)
if
(
messageCount
>
1
)
{
pushMessageList
?.
let
{
val
messageCount
=
pushMessageList
.
size
val
summary
=
summaryText
.
replace
(
"%n%"
,
messageCount
.
toString
())
val
summary
=
summaryText
.
replace
(
"%n%"
,
messageCount
.
toString
())
.
fromHtml
()
builder
.
setNumber
(
messageCount
)
if
(
messageCount
>
1
)
{
val
firstPush
=
pushMessageList
[
0
]
val
singleConversation
=
pushMessageList
.
filter
{
firstPush
.
sender
.
username
!=
it
.
sender
.
username
}.
isEmpty
()
val
inbox
=
Notification
.
InboxStyle
()
val
inbox
=
Notification
.
InboxStyle
()
.
setBigContentTitle
(
title
.
fromHtml
())
.
setBigContentTitle
(
if
(
singleConversation
)
title
else
summary
)
.
setSummaryText
(
summary
)
for
(
push
in
pushMessageList
)
{
if
(
singleConversation
)
{
inbox
.
addLine
(
push
.
message
)
}
else
{
inbox
.
addLine
(
"<font color='black'>${push.title}</font> <font color='gray'>${push.message}</font>"
.
fromHtml
())
}
}
builder
.
setStyle
(
inbox
)
builder
.
setStyle
(
inbox
)
}
else
{
val
bigText
=
Notification
.
BigTextStyle
()
.
bigText
(
pushMessageList
[
0
].
message
.
fromHtml
())
.
setBigContentTitle
(
pushMessageList
[
0
].
title
.
fromHtml
())
builder
.
setStyle
(
bigText
)
}
}
}
else
{
}
else
{
val
bigText
=
Notification
.
BigTextStyle
()
val
bigText
=
Notification
.
BigTextStyle
()
.
bigText
(
message
.
fromHtml
())
.
bigText
(
message
.
fromHtml
())
...
@@ -252,6 +279,24 @@ object PushManager {
...
@@ -252,6 +279,24 @@ object PushManager {
builder
.
setStyle
(
bigText
)
builder
.
setStyle
(
bigText
)
}
}
// val messages = messageStack.get(notificationId.toInt())
// val messageCount = messages.size
//
// if (messageCount > 1) {
// val summary = summaryText.replace("%n%", messageCount.toString())
// val inbox = Notification.InboxStyle()
// .setBigContentTitle(title.fromHtml())
// .setSummaryText(summary)
//
// builder.setStyle(inbox)
// } else {
// val bigText = Notification.BigTextStyle()
// .bigText(message.fromHtml())
// .setBigContentTitle(title.fromHtml())
//
// builder.setStyle(bigText)
// }
return
builder
.
build
()
return
builder
.
build
()
}
}
}
}
...
@@ -305,7 +350,7 @@ object PushManager {
...
@@ -305,7 +350,7 @@ object PushManager {
val
contentIntent
=
getContentIntent
(
context
,
id
,
lastPushMessage
)
val
contentIntent
=
getContentIntent
(
context
,
id
,
lastPushMessage
)
val
deleteIntent
=
getDismissIntent
(
context
,
lastPushMessage
)
val
deleteIntent
=
getDismissIntent
(
context
,
lastPushMessage
)
val
channel
=
NotificationChannel
(
host
,
host
,
NotificationManager
.
IMPORTANCE_
DEFAULT
)
val
channel
=
NotificationChannel
(
host
,
host
,
NotificationManager
.
IMPORTANCE_
HIGH
)
channel
.
lockscreenVisibility
=
Notification
.
VISIBILITY_PUBLIC
channel
.
lockscreenVisibility
=
Notification
.
VISIBILITY_PUBLIC
channel
.
enableLights
(
true
)
channel
.
enableLights
(
true
)
channel
.
enableVibration
(
true
)
channel
.
enableVibration
(
true
)
...
@@ -551,7 +596,10 @@ object PushManager {
...
@@ -551,7 +596,10 @@ object PushManager {
}
}
}
}
message
?.
let
{
message
?.
let
{
sendMessage
(
context
,
message
,
pushMessage
.
rid
)
val
httpUrl
=
HttpUrl
.
parse
(
pushMessage
.
host
)
httpUrl
?.
let
{
sendMessage
(
RocketChatCache
(
context
).
getSiteUrlFor
(
httpUrl
.
host
()),
message
,
pushMessage
.
rid
)
}
}
}
}
}
}
}
...
@@ -564,9 +612,15 @@ object PushManager {
...
@@ -564,9 +612,15 @@ object PushManager {
return
remoteInput
?.
getCharSequence
(
REMOTE_INPUT_REPLY
)
return
remoteInput
?.
getCharSequence
(
REMOTE_INPUT_REPLY
)
}
}
private
fun
inspect
(
variable
:
String
,
value
:
CharSequence
)
{
println
(
"$variable = ${value}"
)
}
// Just kept for reference. We should use this on rewrite with job schedulers
// Just kept for reference. We should use this on rewrite with job schedulers
private
fun
sendMessage
(
ctx
:
Context
,
message
:
CharSequence
,
roomId
:
String
)
{
private
fun
sendMessage
(
hostname
:
String
,
message
:
CharSequence
,
roomId
:
String
)
{
val
hostname
=
RocketChatCache
(
ctx
).
selectedServerHostname
inspect
(
"hostname"
,
hostname
)
inspect
(
"message"
,
message
)
inspect
(
"roomId"
,
roomId
)
val
roomRepository
=
RealmRoomRepository
(
hostname
)
val
roomRepository
=
RealmRoomRepository
(
hostname
)
val
userRepository
=
RealmUserRepository
(
hostname
)
val
userRepository
=
RealmUserRepository
(
hostname
)
val
messageRepository
=
RealmMessageRepository
(
hostname
)
val
messageRepository
=
RealmMessageRepository
(
hostname
)
...
@@ -597,6 +651,7 @@ object PushManager {
...
@@ -597,6 +651,7 @@ object PushManager {
// Empty
// Empty
},
},
{
throwable
->
{
throwable
->
throwable
.
printStackTrace
()
Logger
.
report
(
throwable
)
Logger
.
report
(
throwable
)
})
})
}
}
...
...
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