Fix Android chat updates from push notifications
This commit is contained in:
@@ -37,8 +37,8 @@ android {
|
|||||||
applicationId = "com.seven.ikar.kotlin"
|
applicationId = "com.seven.ikar.kotlin"
|
||||||
minSdk = 24
|
minSdk = 24
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 211
|
versionCode = 212
|
||||||
versionName = "3.98"
|
versionName = "3.99"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
vectorDrawables.useSupportLibrary = true
|
vectorDrawables.useSupportLibrary = true
|
||||||
|
|||||||
+10
@@ -26,6 +26,7 @@ class IkarFirebaseMessagingService : FirebaseMessagingService() {
|
|||||||
runCatching {
|
runCatching {
|
||||||
val data = message.data.orEmpty()
|
val data = message.data.orEmpty()
|
||||||
if (data.isNotEmpty()) {
|
if (data.isNotEmpty()) {
|
||||||
|
notifyChatDataChanged(data)
|
||||||
PushNotificationDisplayService.show(this, data)
|
PushNotificationDisplayService.show(this, data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -42,6 +43,15 @@ class IkarFirebaseMessagingService : FirebaseMessagingService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun notifyChatDataChanged(data: Map<String, String>) {
|
||||||
|
if (!data.changesChatData()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val app = applicationContext as? IkarNativeApp ?: return
|
||||||
|
app.container.realtimeService.notifyChatsChangedLocally()
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val LOG_TAG = "IkarKotlinFcm"
|
private const val LOG_TAG = "IkarKotlinFcm"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,3 +27,7 @@ object PushDataKinds {
|
|||||||
const val VideoCallEnded = "video_call_ended"
|
const val VideoCallEnded = "video_call_ended"
|
||||||
const val AppUpdateAvailable = "app_update_available"
|
const val AppUpdateAvailable = "app_update_available"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun Map<String, String>.changesChatData(): Boolean =
|
||||||
|
this[PushDataKeys.Kind] == PushDataKinds.ChatMessage ||
|
||||||
|
this[PushDataKeys.Kind] == PushDataKinds.MessageReaction
|
||||||
|
|||||||
+21
-2
@@ -18,6 +18,7 @@ import com.seven.ikar.kotlin.core.model.MessageDto
|
|||||||
import com.seven.ikar.kotlin.core.model.MessageReactionDto
|
import com.seven.ikar.kotlin.core.model.MessageReactionDto
|
||||||
import com.seven.ikar.kotlin.core.model.MessageReplyDto
|
import com.seven.ikar.kotlin.core.model.MessageReplyDto
|
||||||
import com.seven.ikar.kotlin.core.model.OutgoingCallDto
|
import com.seven.ikar.kotlin.core.model.OutgoingCallDto
|
||||||
|
import com.seven.ikar.kotlin.core.model.StoryReplyDto
|
||||||
import com.seven.ikar.kotlin.core.model.UserSummaryDto
|
import com.seven.ikar.kotlin.core.model.UserSummaryDto
|
||||||
|
|
||||||
data class RealtimeUserSummaryDto(
|
data class RealtimeUserSummaryDto(
|
||||||
@@ -65,8 +66,10 @@ data class RealtimeMessageDto(
|
|||||||
val postedAsChannel: Boolean = false,
|
val postedAsChannel: Boolean = false,
|
||||||
val displayAuthorName: String? = null,
|
val displayAuthorName: String? = null,
|
||||||
val viewCount: Int? = null,
|
val viewCount: Int? = null,
|
||||||
|
val storyReply: RealtimeStoryReplyDto? = null,
|
||||||
val discussionMessageId: String? = null,
|
val discussionMessageId: String? = null,
|
||||||
val commentCount: Int? = null
|
val commentCount: Int? = null,
|
||||||
|
val clientMessageId: String? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
data class RealtimeMessageReplyDto(
|
data class RealtimeMessageReplyDto(
|
||||||
@@ -82,6 +85,13 @@ data class RealtimeMessageReactionDto(
|
|||||||
val isMine: Boolean
|
val isMine: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class RealtimeStoryReplyDto(
|
||||||
|
val storyId: String,
|
||||||
|
val authorUserId: String,
|
||||||
|
val previewText: String,
|
||||||
|
val attachmentKind: String? = null
|
||||||
|
)
|
||||||
|
|
||||||
data class RealtimeChatSummaryDto(
|
data class RealtimeChatSummaryDto(
|
||||||
val id: String,
|
val id: String,
|
||||||
val title: String,
|
val title: String,
|
||||||
@@ -210,8 +220,10 @@ fun RealtimeMessageDto.toCore(): MessageDto = MessageDto(
|
|||||||
postedAsChannel = postedAsChannel,
|
postedAsChannel = postedAsChannel,
|
||||||
displayAuthorName = displayAuthorName,
|
displayAuthorName = displayAuthorName,
|
||||||
viewCount = viewCount,
|
viewCount = viewCount,
|
||||||
|
storyReply = storyReply?.toCore(),
|
||||||
discussionMessageId = discussionMessageId,
|
discussionMessageId = discussionMessageId,
|
||||||
commentCount = commentCount
|
commentCount = commentCount,
|
||||||
|
clientMessageId = clientMessageId
|
||||||
)
|
)
|
||||||
|
|
||||||
fun RealtimeMessageReplyDto.toCore(): MessageReplyDto = MessageReplyDto(
|
fun RealtimeMessageReplyDto.toCore(): MessageReplyDto = MessageReplyDto(
|
||||||
@@ -227,6 +239,13 @@ fun RealtimeMessageReactionDto.toCore(): MessageReactionDto = MessageReactionDto
|
|||||||
isMine = isMine
|
isMine = isMine
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun RealtimeStoryReplyDto.toCore(): StoryReplyDto = StoryReplyDto(
|
||||||
|
storyId = storyId,
|
||||||
|
authorUserId = authorUserId,
|
||||||
|
previewText = previewText,
|
||||||
|
attachmentKind = attachmentKind
|
||||||
|
)
|
||||||
|
|
||||||
fun RealtimeChatSummaryDto.toCore(): ChatSummaryDto = ChatSummaryDto(
|
fun RealtimeChatSummaryDto.toCore(): ChatSummaryDto = ChatSummaryDto(
|
||||||
id = id,
|
id = id,
|
||||||
title = title,
|
title = title,
|
||||||
|
|||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
package com.seven.ikar.kotlin.core.push
|
||||||
|
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class PushDataTest {
|
||||||
|
@Test
|
||||||
|
fun messagePushesChangeChatData() {
|
||||||
|
assertTrue(mapOf(PushDataKeys.Kind to PushDataKinds.ChatMessage).changesChatData())
|
||||||
|
assertTrue(mapOf(PushDataKeys.Kind to PushDataKinds.MessageReaction).changesChatData())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun unrelatedPushesDoNotChangeChatData() {
|
||||||
|
assertFalse(mapOf(PushDataKeys.Kind to PushDataKinds.AudioCallInvite).changesChatData())
|
||||||
|
assertFalse(mapOf(PushDataKeys.Kind to PushDataKinds.AppUpdateAvailable).changesChatData())
|
||||||
|
assertFalse(emptyMap<String, String>().changesChatData())
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user