Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class ChatCoordinator @Inject constructor(
type = PointerType.READ,
userId = selfId,
value = messageId,
timestamp = Clock.System.now(),
)
memberDataSource.updatePointers(chatId, pointer)
_state.update { state ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ data class MessagePointerSerialized(
val type: String,
val userIdHex: String,
val value: Long,
val timestampEpochSeconds: Long = 0L,
)

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,14 @@ private fun MessagePointer.toSerialized(): MessagePointerSerialized = MessagePoi
type = type.name,
userIdHex = userId.hexEncodedString(),
value = value,
timestampEpochSeconds = timestamp.epochSeconds,
)

private fun MessagePointerSerialized.toDomain(): MessagePointer = MessagePointer(
type = PointerType.entries.firstOrNull { it.name == type } ?: PointerType.UNKNOWN,
userId = userIdHex.hexToIdExt(),
value = value,
timestamp = Instant.fromEpochSeconds(timestampEpochSeconds),
)

private fun UserProfile.toSerialized(): UserProfileSerialized = UserProfileSerialized(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ message Pointer {
// Everything at or before this message ID is considered to have the state
// inferred by the type of pointer.
MessageId value = 3 [(validate.rules).message.required = true];

// Timestamp the pointer was last advanced at
google.protobuf.Timestamp ts = 4 [(validate.rules).timestamp.required = true];
}

message MessageIdBatch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ internal fun MessagingModel.Pointer.toPointer(): MessagePointer {
type = type.toPointerType(),
userId = userId.toId(),
value = value.value,
timestamp = Instant.fromEpochSeconds(ts.seconds, ts.nanos),
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.flipcash.services.models.chat

import com.getcode.opencode.model.core.ID
import kotlin.time.Instant

data class MessagePointer(
val type: PointerType,
val userId: ID,
val value: Long,
val timestamp: Instant,
)

enum class PointerType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DomainModelsTest {
ChatMessage(1, null, listOf(MessageContent.Text("hi")), Instant.fromEpochSeconds(0), 1)
),
pointerUpdates = listOf(
MessagePointer(PointerType.READ, listOf(1.toByte()), 5)
MessagePointer(PointerType.READ, listOf(1.toByte()), 5, Instant.fromEpochSeconds(0))
),
typingNotifications = listOf(
TypingNotification(listOf(1.toByte()), TypingState.STARTED_TYPING)
Expand Down Expand Up @@ -91,7 +91,7 @@ class DomainModelsTest {
val member = ChatMember(
userId = listOf(1.toByte()),
userProfile = UserProfile("Test", emptyList(), null, null),
pointers = listOf(MessagePointer(PointerType.READ, listOf(1.toByte()), 10)),
pointers = listOf(MessagePointer(PointerType.READ, listOf(1.toByte()), 10, Instant.fromEpochSeconds(0))),
)
assertEquals("Test", member.userProfile.displayName)
assertEquals(1, member.pointers.size)
Expand Down
Loading