Skip to content

Commit 8a014eb

Browse files
committed
chore(fc): parse sender out of notification payloads; update routing for room by id or number
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 18690d4 commit 8a014eb

7 files changed

Lines changed: 44 additions & 12 deletions

File tree

flipchatApp/src/main/kotlin/xyz/flipchat/app/features/chat/conversation/ConversationScreen.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ import xyz.flipchat.app.features.home.TabbedHomeScreen
7878
@Parcelize
7979
data class ConversationScreen(
8080
val chatId: ID? = null,
81-
val intentId: ID? = null
81+
val roomNumber: Long? = null
8282
) : AppScreen(), Parcelable {
8383
@IgnoredOnParcel
8484
override val key: ScreenKey = uniqueScreenKey
@@ -100,6 +100,14 @@ data class ConversationScreen(
100100
}
101101
}
102102

103+
LaunchedEffect(chatId) {
104+
if (chatId != null) {
105+
vm.dispatchEvent(
106+
ConversationViewModel.Event.OnChatIdChanged(chatId)
107+
)
108+
}
109+
}
110+
103111
LaunchedEffect(vm) {
104112
vm.eventFlow
105113
.filterIsInstance<ConversationViewModel.Event.NeedsAccountCreated>()

flipchatApp/src/main/kotlin/xyz/flipchat/app/features/chat/conversation/ConversationViewModel.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class ConversationViewModel @Inject constructor(
152152
sealed interface Event {
153153
data class OnSelfChanged(val id: ID?, val displayName: String?) : Event
154154
data class OnChatIdChanged(val chatId: ID?) : Event
155+
data class OnRoomNumberChanged(val roomNumber: Long): Event
155156
data class OnConversationChanged(val conversationWithPointers: ConversationWithMembersAndLastPointers) :
156157
Event
157158

@@ -1077,6 +1078,7 @@ class ConversationViewModel @Inject constructor(
10771078
state.copy(isSelfTyping = false)
10781079
}
10791080

1081+
is Event.OnRoomNumberChanged,
10801082
is Event.OnJoinRoom,
10811083
is Event.OnAccountCreated,
10821084
is Event.NeedsAccountCreated,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ internal fun NotificationManagerCompat.buildChatNotification(
3131
content: String,
3232
canReply: Boolean,
3333
): Pair<Int, NotificationCompat.Builder> {
34-
val sender = content.substringBefore(":")
35-
val messageBody = content.substringAfter(":")
34+
val sender = content.substringBefore(":").trim().ifEmpty { type.sender } ?: "Sender"
35+
val messageBody = content.substringAfter(":").trim()
3636
val person = Person.Builder()
3737
.setName(sender)
3838
.build()
@@ -137,7 +137,7 @@ internal fun NotificationManagerCompat.getActiveNotification(notificationId: Int
137137
internal fun Context.buildContentIntent(type: FcNotificationType): PendingIntent {
138138
val launchIntent = when (type) {
139139
is FcNotificationType.ChatMessage -> Intent(Intent.ACTION_VIEW).apply {
140-
data = Uri.parse("https://app.flipchat.xyz/room?r=${type.id?.base58}")
140+
data = Uri.parse("https://app.flipchat.xyz/room/${type.id?.base58}")
141141
}
142142

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

flipchatApp/src/main/kotlin/xyz/flipchat/app/ui/navigation/AppScreenContent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fun AppScreenContent(content: @Composable () -> Unit) {
8686
register<NavScreenProvider.Room.Messages> {
8787
ConversationScreen(
8888
chatId = it.chatId,
89-
intentId = it.intentId,
89+
roomNumber = it.roomNumber,
9090
)
9191
}
9292

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ enum class FcTab {
3434

3535
sealed interface DeeplinkType {
3636
data class Login(val entropy: String) : DeeplinkType
37-
data class OpenRoom(val roomId: ID) : DeeplinkType
37+
data class OpenRoomById(val roomId: ID) : DeeplinkType
38+
data class OpenRoomByNumber(val number: Long) : DeeplinkType
3839
}
3940

4041
class RouterImpl(
@@ -90,9 +91,14 @@ class RouterImpl(
9091
val type = processType(deeplink) ?: return emptyList()
9192
when (type) {
9293
is DeeplinkType.Login -> listOf(ScreenRegistry.get(NavScreenProvider.AppHomeScreen(deeplink)))
93-
is DeeplinkType.OpenRoom -> listOf(
94+
is DeeplinkType.OpenRoomById -> listOf(
9495
ScreenRegistry.get(NavScreenProvider.AppHomeScreen()),
95-
ScreenRegistry.get(NavScreenProvider.Room.Messages(type.roomId))
96+
ScreenRegistry.get(NavScreenProvider.Room.Messages(chatId = type.roomId))
97+
)
98+
99+
is DeeplinkType.OpenRoomByNumber -> listOf(
100+
ScreenRegistry.get(NavScreenProvider.AppHomeScreen()),
101+
ScreenRegistry.get(NavScreenProvider.Room.Messages(roomNumber = type.number))
96102
)
97103
}
98104
} ?: emptyList()
@@ -123,7 +129,20 @@ class RouterImpl(
123129
deeplink.data.toUri().getQueryParameter("r")
124130
}.getOrNull() ?: return null
125131
val roomId = Base58.decode(id).toList()
126-
DeeplinkType.OpenRoom(roomId = roomId)
132+
DeeplinkType.OpenRoomById(roomId = roomId)
133+
}
134+
135+
else -> null
136+
}
137+
}
138+
139+
2 -> {
140+
when {
141+
room.contains(deeplink.pathSegments[0]) -> {
142+
val number = runCatching {
143+
deeplink.pathSegments[1].toLongOrNull()
144+
}.getOrNull() ?: return null
145+
DeeplinkType.OpenRoomByNumber(number = number)
127146
}
128147

129148
else -> null

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

Lines changed: 5 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?): FcNotificationType, Notifiable {
28+
data class ChatMessage(val id: ID?, val sender: String?): FcNotificationType, Notifiable {
2929
override val ordinal: Int = 1
3030
override val name: String = "Chat Messages"
3131
}
@@ -35,6 +35,8 @@ sealed interface FcNotificationType {
3535
companion object {
3636
private const val TYPE = "type"
3737
private const val CHAT_ID = "chat_id"
38+
private const val SENDER = "sender"
39+
3840
fun resolve(value: MutableMap<String, String>): FcNotificationType {
3941
val type = value[TYPE]
4042
var notificationType = runCatching { TypeValue.valueOf(type.orEmpty()) }.getOrNull()
@@ -46,7 +48,8 @@ sealed interface FcNotificationType {
4648
return when (notificationType) {
4749
TypeValue.ChatMessage -> {
4850
val chatId = value[CHAT_ID]?.decodeBase64()?.toList()
49-
ChatMessage(chatId)
51+
val sender = value[SENDER]
52+
ChatMessage(chatId, sender)
5053
}
5154
else -> Unknown
5255
}

ui/navigation/src/main/kotlin/com/getcode/navigation/NavScreenProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ sealed class NavScreenProvider : ScreenProvider {
3838

3939
data class Messages(
4040
val chatId: ID? = null,
41-
val intentId: ID? = null
41+
val roomNumber: Long? = null,
4242
) : NavScreenProvider()
4343

4444
data class Info(

0 commit comments

Comments
 (0)