mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
fix: Update messaging feature with contact item keys and MQTT limits (#4871)
This commit is contained in:
parent
d61c0c9a67
commit
88d11aafec
3 changed files with 17 additions and 3 deletions
|
|
@ -76,6 +76,7 @@ interface PacketDao {
|
|||
) latest ON p.contact_key = latest.contact_key AND p.received_time = latest.max_time
|
||||
WHERE (p.myNodeNum = 0 OR p.myNodeNum = (SELECT myNodeNum FROM my_node))
|
||||
AND p.port_num = 1 AND p.filtered = 0
|
||||
GROUP BY p.contact_key
|
||||
ORDER BY p.received_time DESC
|
||||
""",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ import kotlinx.coroutines.flow.Flow
|
|||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.sync.Semaphore
|
||||
import kotlinx.coroutines.sync.withPermit
|
||||
import kotlinx.serialization.json.Json
|
||||
import okio.ByteString.Companion.toByteString
|
||||
import org.koin.core.annotation.Single
|
||||
|
|
@ -58,6 +60,7 @@ class MQTTRepositoryImpl(
|
|||
private val json = Json { ignoreUnknownKeys = true }
|
||||
private val scope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
private var clientJob: Job? = null
|
||||
private val publishSemaphore = Semaphore(20)
|
||||
|
||||
override fun disconnect() {
|
||||
Logger.i { "MQTT Disconnecting" }
|
||||
|
|
@ -162,6 +165,15 @@ class MQTTRepositoryImpl(
|
|||
@OptIn(ExperimentalUnsignedTypes::class)
|
||||
override fun publish(topic: String, data: ByteArray, retained: Boolean) {
|
||||
Logger.d { "MQTT publishing message to topic $topic (size: ${data.size} bytes, retained: $retained)" }
|
||||
client?.publish(retain = retained, qos = Qos.AT_LEAST_ONCE, topic = topic, payload = data.toUByteArray())
|
||||
scope.launch {
|
||||
publishSemaphore.withPermit {
|
||||
client?.publish(
|
||||
retain = retained,
|
||||
qos = Qos.AT_LEAST_ONCE,
|
||||
topic = topic,
|
||||
payload = data.toUByteArray(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
|||
import androidx.paging.LoadState
|
||||
import androidx.paging.compose.LazyPagingItems
|
||||
import androidx.paging.compose.collectAsLazyPagingItems
|
||||
import androidx.paging.compose.itemKey
|
||||
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
|
|
@ -566,7 +567,7 @@ private fun LazyListScope.contactListPlaceholdersItems(
|
|||
channels: ChannelSet?,
|
||||
haptic: HapticFeedback,
|
||||
) {
|
||||
items(count = placeholders.size, key = { index -> placeholders[index].contactKey }) { index ->
|
||||
items(count = placeholders.size, key = { index -> "${placeholders[index].contactKey}_placeholder" }) { index ->
|
||||
val contact = placeholders[index]
|
||||
ContactItem(
|
||||
contact = contact,
|
||||
|
|
@ -593,7 +594,7 @@ private fun LazyListScope.contactListPagedItems(
|
|||
channels: ChannelSet?,
|
||||
haptic: HapticFeedback,
|
||||
) {
|
||||
items(count = contacts.itemCount, key = { index -> contacts[index]?.contactKey ?: index }) { index ->
|
||||
items(count = contacts.itemCount, key = contacts.itemKey { it.contactKey }) { index ->
|
||||
contacts[index]?.let { contact ->
|
||||
ContactItem(
|
||||
contact = contact,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue