Skip to content

Commit c9a6712

Browse files
authored
chore(protos): update flipcash protobuf definitions (#909)
Add `ts` (Timestamp) field to messaging Pointer message and propagate through domain model, mapper, serialization, and test layers. Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent d237455 commit c9a6712

7 files changed

Lines changed: 12 additions & 2 deletions

File tree

apps/flipcash/shared/chat/src/main/kotlin/com/flipcash/shared/chat/ChatCoordinator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ class ChatCoordinator @Inject constructor(
246246
type = PointerType.READ,
247247
userId = selfId,
248248
value = messageId,
249+
timestamp = Clock.System.now(),
249250
)
250251
memberDataSource.updatePointers(chatId, pointer)
251252
_state.update { state ->

apps/flipcash/shared/persistence/db/src/main/kotlin/com/flipcash/app/persistence/converters/ChatTypeConverters.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ data class MessagePointerSerialized(
9090
val type: String,
9191
val userIdHex: String,
9292
val value: Long,
93+
val timestampEpochSeconds: Long = 0L,
9394
)
9495

9596
@Serializable

apps/flipcash/shared/persistence/sources/src/main/kotlin/com/flipcash/app/persistence/sources/mapper/chat/ChatEntityMapper.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,14 @@ private fun MessagePointer.toSerialized(): MessagePointerSerialized = MessagePoi
211211
type = type.name,
212212
userIdHex = userId.hexEncodedString(),
213213
value = value,
214+
timestampEpochSeconds = timestamp.epochSeconds,
214215
)
215216

216217
private fun MessagePointerSerialized.toDomain(): MessagePointer = MessagePointer(
217218
type = PointerType.entries.firstOrNull { it.name == type } ?: PointerType.UNKNOWN,
218219
userId = userIdHex.hexToIdExt(),
219220
value = value,
221+
timestamp = Instant.fromEpochSeconds(timestampEpochSeconds),
220222
)
221223

222224
private fun UserProfile.toSerialized(): UserProfileSerialized = UserProfileSerialized(

definitions/flipcash/protos/src/main/proto/messaging/v1/model.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ message Pointer {
115115
// Everything at or before this message ID is considered to have the state
116116
// inferred by the type of pointer.
117117
MessageId value = 3 [(validate.rules).message.required = true];
118+
119+
// Timestamp the pointer was last advanced at
120+
google.protobuf.Timestamp ts = 4 [(validate.rules).timestamp.required = true];
118121
}
119122

120123
message MessageIdBatch {

services/flipcash/src/main/kotlin/com/flipcash/services/internal/network/extensions/ProtobufToLocal.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ internal fun MessagingModel.Pointer.toPointer(): MessagePointer {
137137
type = type.toPointerType(),
138138
userId = userId.toId(),
139139
value = value.value,
140+
timestamp = Instant.fromEpochSeconds(ts.seconds, ts.nanos),
140141
)
141142
}
142143

services/flipcash/src/main/kotlin/com/flipcash/services/models/chat/MessagePointer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.flipcash.services.models.chat
22

33
import com.getcode.opencode.model.core.ID
4+
import kotlin.time.Instant
45

56
data class MessagePointer(
67
val type: PointerType,
78
val userId: ID,
89
val value: Long,
10+
val timestamp: Instant,
911
)
1012

1113
enum class PointerType {

services/flipcash/src/test/kotlin/com/flipcash/services/models/chat/DomainModelsTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class DomainModelsTest {
5757
ChatMessage(1, null, listOf(MessageContent.Text("hi")), Instant.fromEpochSeconds(0), 1)
5858
),
5959
pointerUpdates = listOf(
60-
MessagePointer(PointerType.READ, listOf(1.toByte()), 5)
60+
MessagePointer(PointerType.READ, listOf(1.toByte()), 5, Instant.fromEpochSeconds(0))
6161
),
6262
typingNotifications = listOf(
6363
TypingNotification(listOf(1.toByte()), TypingState.STARTED_TYPING)
@@ -91,7 +91,7 @@ class DomainModelsTest {
9191
val member = ChatMember(
9292
userId = listOf(1.toByte()),
9393
userProfile = UserProfile("Test", emptyList(), null, null),
94-
pointers = listOf(MessagePointer(PointerType.READ, listOf(1.toByte()), 10)),
94+
pointers = listOf(MessagePointer(PointerType.READ, listOf(1.toByte()), 10, Instant.fromEpochSeconds(0))),
9595
)
9696
assertEquals("Test", member.userProfile.displayName)
9797
assertEquals(1, member.pointers.size)

0 commit comments

Comments
 (0)