PacketRepository

Repository interface for managing mesh packets and message history.

This component provides methods for persisting received packets, querying message history, tracking unread counts, and managing contact-specific settings. It supports both reactive (Flow) and one-shot (suspend) queries.

Functions

Link copied to clipboard
abstract suspend fun applyOutgoingQueueStatus(packet: MeshPacket, status: MessageStatus): PersistedPacket?

Atomically resolves and conditionally applies a queue-stage packet status, returning the pre-update row. Returns null when the row is not persisted yet or when the mesh identity matches more than one row.

Link copied to clipboard
abstract suspend fun applyOutgoingReactionQueueStatus(packetId: Int, status: MessageStatus): PersistedReaction?

Atomic reaction equivalent of applyOutgoingQueueStatus. Returns null when no non-received reaction row carries packetId or when packetId matches more than one such row.

Link copied to clipboard

Atomically claims a stable row for sending. A returned packet with QUEUED status is owned by this caller and has already been persisted as ENROUTE; another status means the row was already handled.

Link copied to clipboard
abstract suspend fun claimQueuedPacketByPacketIdIfUnique(packetId: Int): PersistedPacket?

Legacy equivalent of claimQueuedPacket, available only when the mesh packet ID identifies exactly one row.

Link copied to clipboard
abstract suspend fun clearAllUnreadCounts()

Clears the unread status for all messages across all conversations.

Link copied to clipboard
abstract suspend fun clearPacketDB()

Clears all packet and message history from the database.

Link copied to clipboard
abstract suspend fun clearUnreadCount(contact: String, timestamp: Long)

Clears the unread status for messages in a conversation up to the given timestamp.

Link copied to clipboard
abstract suspend fun deleteContacts(contactList: List<String>)

Deletes all messages and settings for the given contacts.

Link copied to clipboard
abstract suspend fun deleteMessages(uuidList: List<Long>)

Deletes messages by their database UUIDs.

Link copied to clipboard
abstract suspend fun deleteWaypoint(id: Int)

Deletes a waypoint by its ID.

Link copied to clipboard
abstract suspend fun findPacketsWithId(packetId: Int): List<DataPacket>

Finds all packets matching a specific packet ID.

Link copied to clipboard
abstract suspend fun findReactionsWithId(packetId: Int): List<Reaction>

Finds all reactions associated with a specific packet ID.

Link copied to clipboard
abstract fun getContacts(): Flow<Map<String, DataPacket>>

Reactive flow of all conversation contacts, keyed by their contact identifier.

Link copied to clipboard

Reactive flow of all contact settings (e.g., mute status).

abstract suspend fun getContactSettings(contact: String): ContactSettings

Returns the settings for a specific contact.

Link copied to clipboard

Reactive paged flow of conversation contacts, each paired with its stored contact key.

Link copied to clipboard
abstract suspend fun getDraft(contactKey: String): String
Link copied to clipboard
abstract suspend fun getEnroutePackets(): List<PersistedPacket>

Returns all sent packets still awaiting a routing ACK/NAK, including stable persisted-row identities.

Link copied to clipboard
abstract suspend fun getEnrouteReactions(): List<PersistedReaction>

Returns all sent reactions still awaiting a routing ACK/NAK, including stable persisted-row identities.

Link copied to clipboard
abstract suspend fun getFilteredCount(contactKey: String): Int

Returns the total count of filtered messages for a contact.

Link copied to clipboard
abstract fun getFilteredCountFlow(contactKey: String): Flow<Int>

Reactive flow of the number of filtered messages for a contact.

Link copied to clipboard
abstract fun getFirstUnreadMessageUuid(contact: String): Flow<Long?>

Reactive flow of the UUID of the first unread message in a conversation.

Link copied to clipboard
abstract suspend fun getMessageCount(contact: String): Int

Returns the total number of messages in a conversation.

Link copied to clipboard
abstract suspend fun getMessagesFrom(contact: String, limit: Int? = null, includeFiltered: Boolean = true, getNode: suspend (String?) -> Node): Flow<List<Message>>

Returns a reactive flow of messages for a conversation.

Link copied to clipboard
abstract fun getMessagesFromPaged(contact: String, getNode: suspend (String?) -> Node): Flow<PagingData<Message>>

Returns a paged flow of messages for a conversation.

abstract fun getMessagesFromPaged(contactKey: String, includeFiltered: Boolean, getNode: suspend (String?) -> Node): Flow<PagingData<Message>>

Returns a paged flow of messages for a conversation, with filtering options.

Link copied to clipboard
abstract suspend fun getPacketById(id: Int): DataPacket?

Returns a packet by its internal database ID.

Link copied to clipboard
abstract suspend fun getPacketByPacketId(packetId: Int): DataPacket?

Returns a packet by its mesh-layer packet ID.

Link copied to clipboard
abstract suspend fun getPacketByPacketIdIfUnique(packetId: Int): DataPacket?

Returns a packet by mesh-layer ID only when exactly one row has that ID in the current node database.

Link copied to clipboard

Returns exactly one persisted packet row by its node-scoped database identity.

Link copied to clipboard
abstract suspend fun getQueuedPackets(): List<PersistedPacket>

Returns all packets currently queued for transmission, including their stable persisted-row identities.

Link copied to clipboard
abstract suspend fun getReactionByPacketId(packetId: Int): Reaction?

Returns a reaction associated with a specific packet ID.

Link copied to clipboard
abstract suspend fun getUnreadCount(contact: String): Int

Returns the count of unread messages in a conversation.

Link copied to clipboard
abstract fun getUnreadCountFlow(contact: String): Flow<Int>

Reactive flow of the unread message count in a conversation.

Link copied to clipboard
abstract fun getUnreadCountTotal(): Flow<Int>

Reactive flow of the total unread message count across all conversations.

Link copied to clipboard
abstract fun getWaypoints(): Flow<List<DataPacket>>

Reactive flow of all persisted waypoints (GPS locations).

Link copied to clipboard
abstract fun hasUnreadMessages(contact: String): Flow<Boolean>

Reactive flow indicating whether a conversation has any unread messages.

Link copied to clipboard
abstract suspend fun insert(packet: DataPacket, myNodeNum: Int, contactKey: String, receivedTime: Long, read: Boolean = true, filtered: Boolean = false)

Inserts a packet into the database.

Link copied to clipboard
abstract suspend fun insertReaction(reaction: Reaction, myNodeNum: Int)

Persists a message reaction (emoji).

Link copied to clipboard
abstract suspend fun markContactUnread(contactKey: String)

Returns a conversation to unread: flips its newest message back and rewinds the read watermark past it.

Link copied to clipboard
abstract suspend fun resolveOutgoingPacket(packet: MeshPacket): PersistedPacket?

Resolves the single persisted row matching an outgoing mesh packet without changing its status. Returns null when the row is not present yet or the available packet identity is ambiguous.

Link copied to clipboard

Restores the exact row to QUEUED only if it is still ENROUTE, without overwriting a racing ACK/NAK status.

Link copied to clipboard
abstract suspend fun savePacket(myNodeNum: Int, contactKey: String, packet: DataPacket, receivedTime: Long, read: Boolean = true, filtered: Boolean = false): PersistedPacketId

Persists a packet in the database.

Link copied to clipboard
abstract fun searchMessages(query: String, contactKey: String? = null, getNode: (String?) -> Node): Flow<List<Message>>

Searches message history using full-text search.

Link copied to clipboard
abstract suspend fun setContactFilteringDisabled(contactKey: String, disabled: Boolean)

Disables or enables message filtering for a specific contact.

Link copied to clipboard
abstract suspend fun setDraft(contactKey: String, draft: String)

Persists unsent composer text for contactKey so it survives leaving the screen, and shows in the list.

Link copied to clipboard
abstract suspend fun setMessageTranslation(uuid: Long, translatedText: String)

Persists the on-device translation of a message and switches it to display the translation.

Link copied to clipboard
abstract suspend fun setMuteUntil(contacts: List<String>, until: Long)

Mutes the given contacts until the specified timestamp.

Link copied to clipboard
abstract suspend fun setPinned(contactKeys: List<String>, pinned: Boolean)

Pins or unpins conversations so they sort above their unpinned siblings.

Link copied to clipboard
abstract suspend fun setShowTranslated(uuid: Long, showTranslated: Boolean)

Toggles whether a translated message displays the translation or the original text.

Link copied to clipboard
abstract suspend fun timeOutEnroutePacket(id: PersistedPacketId, routingError: Int): Boolean

Atomically marks a still-MessageStatus.ENROUTE packet as failed with routingError, leaving it untouched if an ACK/NAK already resolved it.

Link copied to clipboard
abstract suspend fun timeOutEnrouteReaction(id: PersistedReactionId, routingError: Int): Boolean

Atomically marks a still-MessageStatus.ENROUTE reaction as failed with routingError, leaving it untouched if an ACK/NAK already resolved it.

Link copied to clipboard
abstract suspend fun update(packet: DataPacket, routingError: Int = -1)

Updates an existing packet in the database, optionally setting a routing error code.

Link copied to clipboard
abstract suspend fun updateFilteredBySender(senderId: String, filtered: Boolean)

Marks all messages from a specific sender as filtered or unfiltered.

Link copied to clipboard
abstract suspend fun updateLastReadMessage(contact: String, messageUuid: Long, lastReadTimestamp: Long)

Updates the identifier of the last read message in a conversation.

Link copied to clipboard
abstract suspend fun updateMessageId(d: DataPacket, id: Int)

Updates the identifier of a persisted packet.

Link copied to clipboard
abstract suspend fun updateMessageStatus(d: DataPacket, m: MessageStatus)

Updates the transmission status of a packet.

abstract suspend fun updateMessageStatus(id: PersistedPacketId, status: MessageStatus)

Updates exactly one persisted packet row without relying on its mesh packet ID.

Link copied to clipboard
abstract suspend fun updateOutgoingMessageStatus(packet: MeshPacket, status: MessageStatus): PersistedPacketId?

Updates the single persisted row matching an outgoing mesh packet and returns its stable identity. Returns null when the row has not been persisted yet or when the mesh identity is ambiguous, so callers can retry without updating the wrong packet.

Link copied to clipboard
abstract suspend fun updateReaction(reaction: Reaction)

Updates an existing reaction.

Link copied to clipboard
abstract suspend fun updateSFPPStatus(packetId: Int, from: Int, to: Int, hash: ByteArray, status: MessageStatus, rxTime: Long, myNodeNum: Int?)

Updates the Store-and-Forward PlusPlus (SFPP) status for packets.

Link copied to clipboard
abstract suspend fun updateSFPPStatusByHash(hash: ByteArray, status: MessageStatus, rxTime: Long)

Updates the SFPP status of packets matching the given commit hash.