Skip to content

Commit f5d9c36

Browse files
authored
Mqttflag (#2421)
1 parent 162f9e4 commit f5d9c36

File tree

5 files changed

+133
-1
lines changed

5 files changed

+133
-1
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright (c) 2025 Meshtastic LLC
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.geeksville.mesh.compose
19+
20+
import androidx.compose.ui.test.assertIsDisplayed
21+
import androidx.compose.ui.test.junit4.createComposeRule
22+
import androidx.compose.ui.test.onNodeWithContentDescription
23+
import androidx.test.ext.junit.runners.AndroidJUnit4
24+
import com.geeksville.mesh.MessageStatus
25+
import com.geeksville.mesh.R
26+
import com.geeksville.mesh.model.Message
27+
import com.geeksville.mesh.model.Node
28+
import com.geeksville.mesh.ui.common.preview.NodePreviewParameterProvider
29+
import com.geeksville.mesh.ui.message.components.MessageItem
30+
import org.junit.Rule
31+
import org.junit.Test
32+
import org.junit.runner.RunWith
33+
34+
@RunWith(AndroidJUnit4::class)
35+
class MessageItemTest {
36+
37+
@get:Rule
38+
val composeTestRule = createComposeRule()
39+
40+
@Test
41+
fun mqttIconIsDisplayedWhenViaMqttIsTrue() {
42+
val testNode = NodePreviewParameterProvider().minnieMouse
43+
val messageWithMqtt = Message(
44+
text = "Test message via MQTT",
45+
time = "10:00",
46+
fromLocal = false,
47+
status = MessageStatus.RECEIVED,
48+
snr = 2.5f,
49+
rssi = 90,
50+
hopsAway = 0,
51+
uuid = 1L,
52+
receivedTime = System.currentTimeMillis(),
53+
node = testNode,
54+
read = false,
55+
routingError = 0,
56+
packetId = 1234,
57+
emojis = listOf(),
58+
replyId = null,
59+
viaMqtt = true
60+
)
61+
62+
composeTestRule.setContent {
63+
MessageItem(
64+
message = messageWithMqtt,
65+
node = testNode,
66+
selected = false,
67+
onClick = {},
68+
onLongClick = {},
69+
onStatusClick = {},
70+
isConnected = true,
71+
ourNode = testNode,
72+
)
73+
}
74+
75+
// Check that the MQTT icon is displayed
76+
composeTestRule.onNodeWithContentDescription("via MQTT").assertIsDisplayed()
77+
}
78+
79+
@Test
80+
fun mqttIconIsNotDisplayedWhenViaMqttIsFalse() {
81+
val testNode = NodePreviewParameterProvider().minnieMouse
82+
val messageWithoutMqtt = Message(
83+
text = "Test message not via MQTT",
84+
time = "10:00",
85+
fromLocal = false,
86+
status = MessageStatus.RECEIVED,
87+
snr = 2.5f,
88+
rssi = 90,
89+
hopsAway = 0,
90+
uuid = 1L,
91+
receivedTime = System.currentTimeMillis(),
92+
node = testNode,
93+
read = false,
94+
routingError = 0,
95+
packetId = 1234,
96+
emojis = listOf(),
97+
replyId = null,
98+
viaMqtt = false
99+
)
100+
101+
composeTestRule.setContent {
102+
MessageItem(
103+
message = messageWithoutMqtt,
104+
node = testNode,
105+
selected = false,
106+
onClick = {},
107+
onLongClick = {},
108+
onStatusClick = {},
109+
isConnected = true,
110+
ourNode = testNode,
111+
)
112+
}
113+
114+
// Check that the MQTT icon is not displayed
115+
composeTestRule.onNodeWithContentDescription("via MQTT").assertDoesNotExist()
116+
}
117+
}

app/src/main/java/com/geeksville/mesh/database/entity/Packet.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ data class PacketEntity(
5151
routingError = routingError,
5252
packetId = packetId,
5353
emojis = reactions.toReaction(getNode),
54-
replyId = data.replyId
54+
replyId = data.replyId,
55+
viaMqtt = node.viaMqtt
5556
)
5657
}
5758
}

app/src/main/java/com/geeksville/mesh/model/Message.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ data class Message(
6262
val hopsAway: Int,
6363
val replyId: Int?,
6464
val originalMessage: Message? = null,
65+
val viaMqtt: Boolean = false,
6566
) {
6667
fun getStatusStringRes(): Pair<Int, Int> {
6768
val title = if (routingError > 0) R.string.error else R.string.message_delivery_status

app/src/main/java/com/geeksville/mesh/ui/message/components/MessageItem.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ import androidx.compose.foundation.layout.Row
2727
import androidx.compose.foundation.layout.Spacer
2828
import androidx.compose.foundation.layout.fillMaxWidth
2929
import androidx.compose.foundation.layout.padding
30+
import androidx.compose.foundation.layout.size
3031
import androidx.compose.material.icons.Icons
32+
import androidx.compose.material.icons.filled.Cloud
3133
import androidx.compose.material.icons.filled.FormatQuote
3234
import androidx.compose.material3.Card
3335
import androidx.compose.material3.CardColors
@@ -140,6 +142,13 @@ internal fun MessageItem(
140142
style = MaterialTheme.typography.labelMedium,
141143
modifier = Modifier.weight(1f, fill = true)
142144
)
145+
if (message.viaMqtt) {
146+
Icon(
147+
Icons.Default.Cloud,
148+
contentDescription = stringResource(R.string.via_mqtt),
149+
modifier = Modifier.size(16.dp)
150+
)
151+
}
143152
MessageActions(
144153
isLocal = message.fromLocal,
145154
status = message.status,
@@ -275,6 +284,7 @@ private fun MessageItemPreview() {
275284
packetId = 4545,
276285
emojis = listOf(),
277286
replyId = null,
287+
viaMqtt = false,
278288
)
279289
val received = Message(
280290
text = "This is a received message",
@@ -292,6 +302,7 @@ private fun MessageItemPreview() {
292302
packetId = 4545,
293303
emojis = listOf(),
294304
replyId = null,
305+
viaMqtt = false,
295306
)
296307
val receivedWithOriginalMessage = Message(
297308
text = "This is a received message w/ original, this is a longer message to test next-lining.",
@@ -310,6 +321,7 @@ private fun MessageItemPreview() {
310321
emojis = listOf(),
311322
replyId = null,
312323
originalMessage = received,
324+
viaMqtt = true,
313325
)
314326
AppTheme {
315327
Column(

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<string name="node_sort_hops_away">Hops away</string>
5252
<string name="node_sort_last_heard">Last heard</string>
5353
<string name="node_sort_via_mqtt">via MQTT</string>
54+
<string name="via_mqtt">via MQTT</string>
5455
<string name="node_sort_via_favorite">via Favorite</string>
5556

5657
<string name="unrecognized">Unrecognized</string>

0 commit comments

Comments
 (0)