Remove some unneeded duplication and fix up reconnection management

This commit is contained in:
Jack Kingsman
2026-01-30 21:03:58 -08:00
parent b6c3e13234
commit 1ea809c4e3
16 changed files with 50 additions and 152 deletions
+2 -17
View File
@@ -4,13 +4,12 @@ import {
findContactsByPrefix,
calculateDistance,
sortContactsByDistance,
getHopCount,
resolvePath,
formatDistance,
formatHopCounts,
} from '../utils/pathUtils';
import type { Contact, RadioConfig } from '../types';
import { CONTACT_TYPE_REPEATER, CONTACT_TYPE_CLIENT } from '../types';
import { CONTACT_TYPE_REPEATER } from '../types';
// Helper to create mock contacts
function createContact(overrides: Partial<Contact> = {}): Contact {
@@ -90,7 +89,7 @@ describe('findContactsByPrefix', () => {
createContact({
public_key: '1ACCCC' + 'C'.repeat(52),
name: 'Client1',
type: CONTACT_TYPE_CLIENT,
type: 1, // client
}),
];
@@ -195,20 +194,6 @@ describe('sortContactsByDistance', () => {
});
});
describe('getHopCount', () => {
it('returns 0 for null/empty', () => {
expect(getHopCount(null)).toBe(0);
expect(getHopCount(undefined)).toBe(0);
expect(getHopCount('')).toBe(0);
});
it('counts hops correctly', () => {
expect(getHopCount('1A')).toBe(1);
expect(getHopCount('1A2B')).toBe(2);
expect(getHopCount('1A2B3C')).toBe(3);
});
});
describe('resolvePath', () => {
const repeater1 = createContact({
public_key: '1A' + 'A'.repeat(62),
+2 -2
View File
@@ -10,7 +10,7 @@
import { describe, it, expect } from 'vitest';
import { parseSenderFromText } from '../utils/messageParser';
import { CONTACT_TYPE_REPEATER, CONTACT_TYPE_CLIENT } from '../types';
import { CONTACT_TYPE_REPEATER } from '../types';
describe('Repeater message sender parsing', () => {
/**
@@ -52,7 +52,7 @@ describe('Repeater message sender parsing', () => {
it('non-repeater messages still get sender parsed', () => {
const channelMessage = 'Alice: Hello everyone!';
const contactType: number = CONTACT_TYPE_CLIENT;
const contactType: number = 1; // client
const isRepeater = contactType === CONTACT_TYPE_REPEATER;
const { sender, content } = isRepeater
-1
View File
@@ -164,7 +164,6 @@ export interface MigratePreferencesResponse {
}
/** Contact type constants */
export const CONTACT_TYPE_CLIENT = 1;
export const CONTACT_TYPE_REPEATER = 2;
export interface NeighborInfo {
+1 -1
View File
@@ -148,7 +148,7 @@ export function sortContactsByDistance(
/**
* Get simple hop count from path string
*/
export function getHopCount(path: string | null | undefined): number {
function getHopCount(path: string | null | undefined): number {
if (!path || path.length === 0) {
return 0;
}