Skip to content

Commit

Permalink
if channel name is empty, use the modem preset display name instead
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcottle committed Nov 19, 2024
1 parent 6ba0cb9 commit 0f69a79
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/components/channels/ChannelsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

<!-- channel info -->
<div class="my-auto mr-auto">
<div>
<span v-if="channel.settings.name.length > 0">{{ channel.settings.name }}</span>
<span v-else class="text-gray-500 italic">(No Name)</span>
</div>
<div>{{ getChannelName(channel.index) }}</div>
<div class="text-sm text-gray-500">
<span v-if="channel.role === Protobuf.Channel.Channel_Role.PRIMARY">Primary Channel</span>
<span v-else-if="channel.role === Protobuf.Channel.Channel_Role.SECONDARY">Secondary Channel</span>
Expand All @@ -30,6 +27,7 @@ import {
Protobuf,
} from "@meshtastic/js";
import ChannelPskBadge from "./ChannelPskBadge.vue";
import ChannelUtils from "../../js/ChannelUtils.js";
export default {
name: 'ChannelsList',
components: {ChannelPskBadge},
Expand All @@ -46,6 +44,7 @@ export default {
};
},
methods: {
getChannelName: (channelId) => ChannelUtils.getChannelName(channelId),
onChannelClick(channel) {
this.$emit("channel-click", channel);
},
Expand Down
7 changes: 6 additions & 1 deletion src/components/pages/ChannelMessagesPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Page from "./Page.vue";
import ChannelPskBadge from "../channels/ChannelPskBadge.vue";
import IconButton from "../IconButton.vue";
import Database from "../../js/Database.js";
import ChannelUtils from "../../js/ChannelUtils.js";
export default {
name: 'ChannelMessagesPage',
Expand All @@ -54,6 +55,7 @@ export default {
},
methods: {
getChannelName: (channelId) => ChannelUtils.getChannelName(channelId),
async deleteMessageHistory() {
// confirm user wants to delete message history
Expand All @@ -71,7 +73,10 @@ export default {
return GlobalState.channelsByIndex[this.channelId];
},
subtitle() {
return this.channel?.settings?.name || '(No Name)';
if(this.channel){
return this.getChannelName(this.channel.index);
}
return "Unknown Channel";
},
},
}
Expand Down
55 changes: 54 additions & 1 deletion src/js/ChannelUtils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,63 @@
import GlobalState from "./GlobalState.js";
import {Protobuf} from "@meshtastic/js";

class ChannelUtils {

// https://github.com/meshtastic/firmware/blob/2b0113ae82f2dc5cde82e5c00921d41d10ac141d/src/mesh/Channels.cpp#L294
static getChannelName(channelId) {

// get channel name from channel settings
const channel = GlobalState.channelsByIndex[channelId];
var channelName = channel?.settings?.name;

// if channel name is empty, determine what the name should be based on modem preset
if(channelName === ""){
if(GlobalState.loraConfig?.usePreset === true){
channelName = this.getModemPresetDisplayName(GlobalState.loraConfig.modemPreset);
} else {
channelName = "Custom";
}
}

return channelName;

}

static getModemPresetDisplayName(modemPreset) {
switch(modemPreset){
case Protobuf.Config.Config_LoRaConfig_ModemPreset.SHORT_TURBO: return "ShortTurbo";
case Protobuf.Config.Config_LoRaConfig_ModemPreset.SHORT_SLOW: return "ShortSlow";
case Protobuf.Config.Config_LoRaConfig_ModemPreset.SHORT_FAST: return "ShortFast";
case Protobuf.Config.Config_LoRaConfig_ModemPreset.MEDIUM_SLOW: return "MediumSlow";
case Protobuf.Config.Config_LoRaConfig_ModemPreset.MEDIUM_FAST: return "MediumFast";
case Protobuf.Config.Config_LoRaConfig_ModemPreset.LONG_SLOW: return "LongSlow";
case Protobuf.Config.Config_LoRaConfig_ModemPreset.LONG_FAST: return "LongFast";
case Protobuf.Config.Config_LoRaConfig_ModemPreset.LONG_MODERATE: return "LongMod";
case Protobuf.Config.Config_LoRaConfig_ModemPreset.VERY_LONG_SLOW: return "VLongSlow";
default: return "Invalid";
}
}

// https://github.com/meshtastic/firmware/blob/2b0113ae82f2dc5cde82e5c00921d41d10ac141d/src/mesh/Channels.cpp#L312
static isDefaultChannel(channelId) {

// find channel by id
const channel = GlobalState.channelsByIndex[channelId];
return channel?.settings?.name;
if(!channel){
return false;
}

// check if channel has default key
const hasDefaultPsk = channel.settings.psk.length === 1 && channel.settings.psk[0] === 1;

// check if channel has default display name
const channelName = this.getChannelName(channelId);
const modemPresetDisplayName = this.getModemPresetDisplayName(GlobalState.loraConfig?.modemPreset);
const hasDefaultDisplayName = channelName === modemPresetDisplayName;

// channel is a default channel if it is using the default key and default display name
return hasDefaultPsk && hasDefaultDisplayName;

}

}
Expand Down
7 changes: 7 additions & 0 deletions src/js/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ class Connection {
GlobalState.deviceStatus = deviceStatus;
});

// listen for lora config
connection.events.onConfigPacket.subscribe((configPacket) => {
if(configPacket.payloadVariant.case.toString() === "lora"){
GlobalState.loraConfig = configPacket.payloadVariant.value;
}
});

// listen for packets from radio
// we use this for some packets that don't have their own event listener
connection.events.onFromRadio.subscribe(async (data) => {
Expand Down
1 change: 1 addition & 0 deletions src/js/GlobalState.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const globalState = reactive({
myNodeId: null,
myNodeUser: null,

loraConfig: null,
channelsByIndex: {},
nodesById: {},

Expand Down

0 comments on commit 0f69a79

Please sign in to comment.