Skip to content

Mqttflag #2421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
@@ -0,0 +1,117 @@
/*
* Copyright (c) 2025 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.geeksville.mesh.compose

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.geeksville.mesh.MessageStatus
import com.geeksville.mesh.R
import com.geeksville.mesh.model.Message
import com.geeksville.mesh.model.Node
import com.geeksville.mesh.ui.common.preview.NodePreviewParameterProvider
import com.geeksville.mesh.ui.message.components.MessageItem
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class MessageItemTest {

@get:Rule
val composeTestRule = createComposeRule()

@Test
fun mqttIconIsDisplayedWhenViaMqttIsTrue() {
val testNode = NodePreviewParameterProvider().minnieMouse
val messageWithMqtt = Message(
text = "Test message via MQTT",
time = "10:00",
fromLocal = false,
status = MessageStatus.RECEIVED,
snr = 2.5f,
rssi = 90,
hopsAway = 0,
uuid = 1L,
receivedTime = System.currentTimeMillis(),
node = testNode,
read = false,
routingError = 0,
packetId = 1234,
emojis = listOf(),
replyId = null,
viaMqtt = true
)

composeTestRule.setContent {
MessageItem(
message = messageWithMqtt,
node = testNode,
selected = false,
onClick = {},
onLongClick = {},
onStatusClick = {},
isConnected = true,
ourNode = testNode,
)
}

// Check that the MQTT icon is displayed
composeTestRule.onNodeWithContentDescription("via MQTT").assertIsDisplayed()
}

@Test
fun mqttIconIsNotDisplayedWhenViaMqttIsFalse() {
val testNode = NodePreviewParameterProvider().minnieMouse
val messageWithoutMqtt = Message(
text = "Test message not via MQTT",
time = "10:00",
fromLocal = false,
status = MessageStatus.RECEIVED,
snr = 2.5f,
rssi = 90,
hopsAway = 0,
uuid = 1L,
receivedTime = System.currentTimeMillis(),
node = testNode,
read = false,
routingError = 0,
packetId = 1234,
emojis = listOf(),
replyId = null,
viaMqtt = false
)

composeTestRule.setContent {
MessageItem(
message = messageWithoutMqtt,
node = testNode,
selected = false,
onClick = {},
onLongClick = {},
onStatusClick = {},
isConnected = true,
ourNode = testNode,
)
}

// Check that the MQTT icon is not displayed
composeTestRule.onNodeWithContentDescription("via MQTT").assertDoesNotExist()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ data class PacketEntity(
routingError = routingError,
packetId = packetId,
emojis = reactions.toReaction(getNode),
replyId = data.replyId
replyId = data.replyId,
viaMqtt = node.viaMqtt
)
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/geeksville/mesh/model/Message.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ data class Message(
val hopsAway: Int,
val replyId: Int?,
val originalMessage: Message? = null,
val viaMqtt: Boolean = false,
) {
fun getStatusStringRes(): Pair<Int, Int> {
val title = if (routingError > 0) R.string.error else R.string.message_delivery_status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Cloud
import androidx.compose.material.icons.filled.FormatQuote
import androidx.compose.material3.Card
import androidx.compose.material3.CardColors
Expand Down Expand Up @@ -140,6 +142,13 @@ internal fun MessageItem(
style = MaterialTheme.typography.labelMedium,
modifier = Modifier.weight(1f, fill = true)
)
if (message.viaMqtt) {
Icon(
Icons.Default.Cloud,
contentDescription = stringResource(R.string.via_mqtt),
modifier = Modifier.size(16.dp)
)
}
MessageActions(
isLocal = message.fromLocal,
status = message.status,
Expand Down Expand Up @@ -275,6 +284,7 @@ private fun MessageItemPreview() {
packetId = 4545,
emojis = listOf(),
replyId = null,
viaMqtt = false,
)
val received = Message(
text = "This is a received message",
Expand All @@ -292,6 +302,7 @@ private fun MessageItemPreview() {
packetId = 4545,
emojis = listOf(),
replyId = null,
viaMqtt = false,
)
val receivedWithOriginalMessage = Message(
text = "This is a received message w/ original, this is a longer message to test next-lining.",
Expand All @@ -310,6 +321,7 @@ private fun MessageItemPreview() {
emojis = listOf(),
replyId = null,
originalMessage = received,
viaMqtt = true,
)
AppTheme {
Column(
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<string name="node_sort_hops_away">Hops away</string>
<string name="node_sort_last_heard">Last heard</string>
<string name="node_sort_via_mqtt">via MQTT</string>
<string name="via_mqtt">via MQTT</string>
<string name="node_sort_via_favorite">via Favorite</string>

<string name="unrecognized">Unrecognized</string>
Expand Down