Skip to content

Commit b87b868

Browse files
committed
fix(fc): remove open room by ID deeplink and derive roomNumber from chat_id for notifications
Signed-off-by: Brandon McAnsh <[email protected]>
1 parent bae0180 commit b87b868

File tree

5 files changed

+65
-62
lines changed

5 files changed

+65
-62
lines changed

flipchatApp/src/main/kotlin/xyz/flipchat/app/App.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ fun App(
108108
if (codeNavigator.lastItem !is MainRoot) {
109109
if (deepLink != null) {
110110
val screenSet = router.processDestination(deepLink)
111-
codeNavigator.replaceAll(screenSet)
111+
if (screenSet.isNotEmpty()) {
112+
codeNavigator.replaceAll(screenSet)
113+
}
112114
}
113115
}
114116
}

flipchatApp/src/main/kotlin/xyz/flipchat/app/notifications/FcNotificationService.kt

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import xyz.flipchat.app.auth.AuthManager
3838
import xyz.flipchat.app.theme.FC_Primary
3939
import xyz.flipchat.controllers.ChatsController
4040
import xyz.flipchat.controllers.PushController
41+
import xyz.flipchat.internal.db.FcAppDatabase
4142
import xyz.flipchat.notifications.FcNotificationType
4243
import xyz.flipchat.notifications.parse
4344
import xyz.flipchat.services.user.AuthState
@@ -76,6 +77,9 @@ class FcNotificationService : FirebaseMessagingService(),
7677
@Inject
7778
lateinit var notificationManager: NotificationManagerCompat
7879

80+
private val db: FcAppDatabase
81+
get() = FcAppDatabase.requireInstance()
82+
7983
override fun onMessageReceived(message: RemoteMessage) {
8084
super.onMessageReceived(message)
8185
authenticateIfNeeded { handleMessage(message) }
@@ -92,44 +96,46 @@ class FcNotificationService : FirebaseMessagingService(),
9296
}
9397

9498
private fun handleMessage(remoteMessage: RemoteMessage) {
95-
trace("handling received message", type = TraceType.Silent)
96-
if (remoteMessage.data.isNotEmpty()) {
97-
Timber.d("Message data payload: ${remoteMessage.data}")
98-
val notification = remoteMessage.parse()
99-
100-
if (notification != null) {
101-
val (type, titleKey, messageContent) = notification
102-
if (type.isNotifiable()) {
103-
val title = titleKey.localizedStringByKey(resources) ?: titleKey
104-
val body = messageContent.localizedText(
105-
resources = resources,
106-
currencyUtils = currencyUtils
107-
)
108-
109-
val result = buildNotification(type, title, body)
110-
if (result != null) {
111-
notify(result.first, result.second, type)
99+
launch {
100+
trace("handling received message", type = TraceType.Silent)
101+
if (remoteMessage.data.isNotEmpty()) {
102+
Timber.d("Message data payload: ${remoteMessage.data}")
103+
val notification = remoteMessage.parse()
104+
105+
if (notification != null) {
106+
val (type, titleKey, messageContent) = notification
107+
if (type.isNotifiable()) {
108+
val title = titleKey.localizedStringByKey(resources) ?: titleKey
109+
val body = messageContent.localizedText(
110+
resources = resources,
111+
currencyUtils = currencyUtils
112+
)
113+
114+
val result = buildNotification(type, title, body)
115+
if (result != null) {
116+
notify(result.first, result.second, type)
117+
}
112118
}
113-
}
114119

115-
when (type) {
116-
is FcNotificationType.ChatMessage -> {
117-
val roomId = type.id
118-
if (roomId != null) {
119-
launch { chatsController.updateRoom(roomId) }
120+
when (type) {
121+
is FcNotificationType.ChatMessage -> {
122+
val roomId = type.id
123+
if (roomId != null) {
124+
launch { chatsController.updateRoom(roomId) }
125+
}
120126
}
121-
}
122127

123-
FcNotificationType.Unknown -> Unit
124-
}
125-
} else {
126-
val result = buildNotification(
127-
FcNotificationType.Unknown,
128-
resources.getString(R.string.app_name),
129-
"You have a new message."
130-
)
131-
if (result != null) {
132-
notify(result.first, result.second, FcNotificationType.Unknown)
128+
FcNotificationType.Unknown -> Unit
129+
}
130+
} else {
131+
val result = buildNotification(
132+
FcNotificationType.Unknown,
133+
resources.getString(R.string.app_name),
134+
"You have a new message."
135+
)
136+
if (result != null) {
137+
notify(result.first, result.second, FcNotificationType.Unknown)
138+
}
133139
}
134140
}
135141
}
@@ -143,7 +149,7 @@ class FcNotificationService : FirebaseMessagingService(),
143149
}
144150
}
145151

146-
private fun buildNotification(
152+
private suspend fun buildNotification(
147153
type: FcNotificationType,
148154
title: String,
149155
content: String,
@@ -162,16 +168,21 @@ class FcNotificationService : FirebaseMessagingService(),
162168
return null
163169
}
164170

171+
165172
with(notificationManager) {
166173
val (id, notification) = when (type) {
167-
is FcNotificationType.ChatMessage -> buildChatNotification(
168-
applicationContext,
169-
resources,
170-
type,
171-
title,
172-
content,
173-
userManager.authState is AuthState.LoggedIn
174-
)
174+
is FcNotificationType.ChatMessage -> {
175+
val roomNumber = type.id?.let { db.conversationDao().findConversationRaw(it)?.roomNumber }
176+
buildChatNotification(
177+
applicationContext,
178+
resources,
179+
type,
180+
roomNumber,
181+
title,
182+
content,
183+
userManager.authState is AuthState.LoggedIn
184+
)
185+
}
175186

176187
FcNotificationType.Unknown -> buildMiscNotification(applicationContext, type, title, content)
177188
}

flipchatApp/src/main/kotlin/xyz/flipchat/app/notifications/NotificationHelper.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ internal fun NotificationManagerCompat.buildChatNotification(
2727
context: Context,
2828
resources: ResourceHelper,
2929
type: FcNotificationType.ChatMessage,
30+
roomNumber: Long?,
3031
title: String,
3132
content: String,
3233
canReply: Boolean,
@@ -92,7 +93,7 @@ internal fun NotificationManagerCompat.buildChatNotification(
9293
.setColor(FC_Primary.toArgb())
9394
.setAutoCancel(true)
9495
.setOnlyAlertOnce(true)
95-
.setContentIntent(context.buildContentIntent(type))
96+
.setContentIntent(context.buildContentIntent(type.copy(roomNumber = roomNumber)))
9697

9798
if (replyAction != null) {
9899
notificationBuilder.addAction(replyAction)
@@ -134,10 +135,12 @@ internal fun NotificationManagerCompat.getActiveNotification(notificationId: Int
134135
return null
135136
}
136137

137-
internal fun Context.buildContentIntent(type: FcNotificationType): PendingIntent {
138+
internal fun Context.buildContentIntent(
139+
type: FcNotificationType
140+
): PendingIntent {
138141
val launchIntent = when (type) {
139142
is FcNotificationType.ChatMessage -> Intent(Intent.ACTION_VIEW).apply {
140-
data = Uri.parse("https://app.flipchat.xyz/room/${type.id?.base58}")
143+
data = Uri.parse("https://app.flipchat.xyz/room/${type.roomNumber}")
141144
}
142145

143146
FcNotificationType.Unknown -> Intent(this, MainActivity::class.java).apply {

flipchatApp/src/main/kotlin/xyz/flipchat/app/util/Router.kt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ enum class FcTab {
3939

4040
sealed interface DeeplinkType {
4141
data class Login(val entropy: String) : DeeplinkType
42-
data class OpenRoomById(val roomId: ID) : DeeplinkType
4342
data class OpenRoomByNumber(val number: Long, val messageId: ID? = null) : DeeplinkType
4443
}
4544

@@ -102,10 +101,6 @@ class RouterImpl(
102101
val type = processType(deeplink) ?: return emptyList()
103102
when (type) {
104103
is DeeplinkType.Login -> listOf(ScreenRegistry.get(NavScreenProvider.AppHomeScreen(deeplink)))
105-
is DeeplinkType.OpenRoomById -> listOf(
106-
ScreenRegistry.get(NavScreenProvider.AppHomeScreen()),
107-
ScreenRegistry.get(NavScreenProvider.Room.Messages(chatId = type.roomId))
108-
)
109104

110105
is DeeplinkType.OpenRoomByNumber -> {
111106
val conversation = db.conversationDao().findConversationRaw(type.number)
@@ -165,14 +160,6 @@ class RouterImpl(
165160
DeeplinkType.Login(entropy)
166161
}
167162

168-
room.contains(deeplink.pathSegments[0]) -> {
169-
val id = runCatching {
170-
deeplink.data.toUri().getQueryParameter("r")
171-
}.getOrNull() ?: return null
172-
val roomId = Base58.decode(id).toList()
173-
DeeplinkType.OpenRoomById(roomId = roomId)
174-
}
175-
176163
else -> null
177164
}
178165
}

services/flipchat/sdk/src/main/kotlin/xyz/flipchat/notifications/FcNotification.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ sealed interface FcNotificationType {
2525
override val name: String = "Misc"
2626
}
2727

28-
data class ChatMessage(val id: ID?, val sender: String?): FcNotificationType, Notifiable {
28+
data class ChatMessage(val id: ID?, val roomNumber: Long?, val sender: String?): FcNotificationType, Notifiable {
2929
override val ordinal: Int = 1
3030
override val name: String = "Chat Messages"
3131
}
@@ -49,7 +49,7 @@ sealed interface FcNotificationType {
4949
TypeValue.ChatMessage -> {
5050
val chatId = value[CHAT_ID]?.decodeBase64()?.toList()
5151
val sender = value[SENDER]
52-
ChatMessage(chatId, sender)
52+
ChatMessage(chatId, null, sender)
5353
}
5454
else -> Unknown
5555
}

0 commit comments

Comments
 (0)