Commit 694084e3 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Get the correct hostname as defined on login

parent 14b8833c
...@@ -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 summary = summaryText.replace("%n%", messageCount.toString()) val messageCount = pushMessageList.size
val inbox = Notification.InboxStyle() val summary = summaryText.replace("%n%", messageCount.toString())
.setBigContentTitle(title.fromHtml()) .fromHtml()
.setSummaryText(summary) builder.setNumber(messageCount)
if (messageCount > 1) {
val firstPush = pushMessageList[0]
val singleConversation = pushMessageList.filter {
firstPush.sender.username != it.sender.username
}.isEmpty()
builder.setStyle(inbox) val inbox = Notification.InboxStyle()
.setBigContentTitle(if (singleConversation) title else 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)
} 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)
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment