Commit 1aa9fa86 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Remove dismissed notitications considering also the hostname to avoid...

Remove dismissed notitications considering also the hostname to avoid unintentional removal when in multiserver
parent a8477619
......@@ -73,10 +73,19 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
updateHostnameIfNeeded(rocketChatCache.getSelectedServerHostname());
}
if (intent.hasExtra(PushManager.EXTRA_NOT_ID)) {
if (intent.hasExtra(PushManager.EXTRA_NOT_ID) && intent.hasExtra(PushManager.EXTRA_HOSTNAME)) {
isNotification = true;
int notificationId = intent.getIntExtra(PushManager.EXTRA_NOT_ID, 0);
PushManager.INSTANCE.clearNotificationsByNotificationId(notificationId);
String hostname = intent.getStringExtra(PushManager.EXTRA_HOSTNAME);
HttpUrl url = HttpUrl.parse(hostname);
if (url != null) {
String hostnameFromPush = url.host();
String loginHostname = rocketChatCache.getSiteUrlFor(hostnameFromPush);
PushManager.INSTANCE.clearNotificationsByHostAndNotificationId(loginHostname, notificationId);
} else {
PushManager.INSTANCE.clearNotificationsByNotificationId(notificationId);
}
}
}
......
......@@ -100,6 +100,17 @@ object PushManager {
}
}
fun clearNotificationsByHostAndNotificationId(host: String, notificationId: Int) {
if (hostToPushMessageList.isNotEmpty()) {
val notifications = hostToPushMessageList[host]
notifications?.let {
notifications.removeAll {
it.notificationId.toInt() == notificationId
}
}
}
}
private fun isAndroidVersionAtLeast(minVersion: Int) = Build.VERSION.SDK_INT >= minVersion
private fun getGroupForHost(host: String): TupleGroupIdMessageCount {
......@@ -519,8 +530,9 @@ object PushManager {
class DeleteReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val notId = intent?.extras?.getInt(EXTRA_NOT_ID)
notId?.let {
clearNotificationsByNotificationId(notId)
val host = intent?.extras?.getString(EXTRA_HOSTNAME)
if (host != null && notId != null) {
clearNotificationsByHostAndNotificationId(host, notId)
}
}
}
......
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