kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
add remote node admin
rodzic
213164e95b
commit
d9eb113b12
|
@ -94,6 +94,7 @@ class UIViewModel @Inject constructor(
|
|||
|
||||
private val _channels = MutableStateFlow(ChannelSet())
|
||||
val channels: StateFlow<ChannelSet> = _channels
|
||||
val channelSet get() = channels.value.protobuf
|
||||
|
||||
private val _quickChatActions = MutableStateFlow<List<QuickChatAction>>(emptyList())
|
||||
val quickChatActions: StateFlow<List<QuickChatAction>> = _quickChatActions
|
||||
|
@ -355,6 +356,8 @@ class UIViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
val adminChannelIndex: Int get() = channelSet.settingsList.map { it.name }.indexOf("admin")
|
||||
|
||||
fun requestShutdown(idNum: Int) {
|
||||
try {
|
||||
meshService?.requestShutdown(idNum)
|
||||
|
|
|
@ -463,6 +463,9 @@ class MeshService : Service(), Logging {
|
|||
/// My node ID string
|
||||
private val myNodeID get() = toNodeID(myNodeNum)
|
||||
|
||||
/// Admin channel index
|
||||
private var adminChannelIndex: Int = 0
|
||||
|
||||
/// Convert the channels array into a ChannelSet
|
||||
private var channelSet: AppOnlyProtos.ChannelSet
|
||||
get() {
|
||||
|
@ -543,6 +546,7 @@ class MeshService : Service(), Logging {
|
|||
initFn: AdminProtos.AdminMessage.Builder.() -> Unit
|
||||
): MeshPacket = buildMeshPacket(
|
||||
wantAck = true,
|
||||
channel = adminChannelIndex,
|
||||
priority = MeshPacket.Priority.RELIABLE
|
||||
)
|
||||
{
|
||||
|
@ -958,9 +962,10 @@ class MeshService : Service(), Logging {
|
|||
}
|
||||
}
|
||||
|
||||
private fun addChannelSettings(channel: ChannelProtos.Channel) {
|
||||
private fun addChannelSettings(ch: ChannelProtos.Channel) {
|
||||
if (ch.index == 0 || ch.settings.name == "admin") adminChannelIndex = ch.index
|
||||
serviceScope.handledLaunch {
|
||||
channelSetRepository.addSettings(channel)
|
||||
channelSetRepository.addSettings(ch)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1381,9 +1386,10 @@ class MeshService : Service(), Logging {
|
|||
})
|
||||
}
|
||||
|
||||
private fun setChannel(channel: ChannelProtos.Channel) {
|
||||
private fun setChannel(ch: ChannelProtos.Channel) {
|
||||
if (ch.index == 0 || ch.settings.name == "admin") adminChannelIndex = ch.index
|
||||
sendToRadio(newMeshPacketTo(myNodeNum).buildAdminPacket(wantResponse = true) {
|
||||
setChannel = channel
|
||||
setChannel = ch
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ class ContactsFragment : ScreenFragment("Messages"), Logging {
|
|||
val node = nodes[if (fromLocal) contact.to else contact.from]
|
||||
|
||||
//grab channel names from DeviceConfig
|
||||
val channels = model.channels.value.protobuf
|
||||
val channels = model.channelSet
|
||||
val channelName = if (channels.settingsCount > contact.channel)
|
||||
Channel(channels.settingsList[contact.channel], channels.loraConfig).name else null
|
||||
|
||||
|
@ -173,7 +173,7 @@ class ContactsFragment : ScreenFragment("Messages"), Logging {
|
|||
fun onContactsChanged(contacts: Map<String, Packet>) {
|
||||
// Add empty channel placeholders (always show Broadcast contacts, even when empty)
|
||||
val mutableMap = contacts.toMutableMap()
|
||||
for (ch in 0 until model.channels.value.protobuf.settingsCount) {
|
||||
for (ch in 0 until model.channelSet.settingsCount) {
|
||||
val contactKey = "$ch${DataPacket.ID_BROADCAST}"
|
||||
if (mutableMap[contactKey] == null) mutableMap[contactKey] = Packet(
|
||||
0L, 1, contactKey, 0L,
|
||||
|
|
|
@ -56,7 +56,7 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
|||
private fun popup(view: View, position: Int) {
|
||||
val node = nodes[position]
|
||||
val user = node.user
|
||||
val showAdmin = position == 0 // TODO add admin channel check
|
||||
val showAdmin = position == 0 || model.adminChannelIndex > 0
|
||||
val popup = PopupMenu(requireContext(), view)
|
||||
popup.inflate(R.menu.menu_nodes)
|
||||
popup.menu.findItem(R.id.direct_message).isVisible = position > 0
|
||||
|
|
Ładowanie…
Reference in New Issue