Skip to content

Commit

Permalink
fix: set user.id in NodeDb getUser
Browse files Browse the repository at this point in the history
This commit updates the `getUser` function in `NodeDB` to set the ID of the user when creating a new `User` object, ensuring that the user ID is always populated.

Additionally, it refactors the `Message` class to use the proto `User` object instead of the `MeshUser` class. This change simplifies the code and improves consistency by utilizing the proto definition for user information.
  • Loading branch information
jamesarich authored and andrekir committed Oct 26, 2024
1 parent 6190683 commit 6447485
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/geeksville/mesh/model/Message.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.geeksville.mesh.model

import com.geeksville.mesh.MeshProtos
import com.geeksville.mesh.MeshProtos.Routing
import com.geeksville.mesh.MeshUser
import com.geeksville.mesh.MessageStatus
import com.geeksville.mesh.R

Expand Down Expand Up @@ -29,7 +29,7 @@ val Routing.Error.stringRes: Int
data class Message(
val uuid: Long,
val receivedTime: Long,
val user: MeshUser,
val user: MeshProtos.User,
val text: String,
val time: Long,
val read: Boolean,
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/geeksville/mesh/model/NodeDB.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class NodeDB @Inject constructor(
fun getUser(userId: String): MeshProtos.User =
nodeDBbyNum.value.values.find { it.user.id == userId }?.user
?: MeshProtos.User.newBuilder()
.setId(userId)
.setLongName("Meshtastic ${userId.takeLast(n = 4)}")
.setShortName(userId.takeLast(n = 4))
.setHwModel(MeshProtos.HardwareModel.UNSET)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/geeksville/mesh/model/UIState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class UIViewModel @Inject constructor(
Message(
uuid = it.uuid,
receivedTime = it.received_time,
user = MeshUser(getUser(it.data.from)), // FIXME convert to proto User
user = getUser(it.data.from),
text = it.data.text.orEmpty(),
time = it.data.time,
read = it.read,
Expand Down

0 comments on commit 6447485

Please sign in to comment.