mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-07-06 01:42:11 +02:00
More code cleanup and optimization
This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
||||
type Conversation,
|
||||
type Favorite,
|
||||
} from '../types';
|
||||
import { getStateKey, type ConversationTimes } from '../utils/conversationState';
|
||||
import { getStateKey, type ConversationTimes, type SortOrder } from '../utils/conversationState';
|
||||
import { getContactDisplayName } from '../utils/pubkey';
|
||||
import { ContactAvatar } from './ContactAvatar';
|
||||
import { isFavorite } from '../utils/favorites';
|
||||
@@ -14,8 +14,6 @@ import { Input } from './ui/input';
|
||||
import { Button } from './ui/button';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
type SortOrder = 'alpha' | 'recent';
|
||||
|
||||
type FavoriteItem = { type: 'channel'; channel: Channel } | { type: 'contact'; contact: Contact };
|
||||
|
||||
type ConversationRow = {
|
||||
|
||||
@@ -32,12 +32,6 @@ body,
|
||||
}
|
||||
|
||||
body {
|
||||
font-family:
|
||||
system-ui,
|
||||
-apple-system,
|
||||
BlinkMacSystemFont,
|
||||
'Segoe UI',
|
||||
sans-serif;
|
||||
/* Prevent overscroll/bounce on mobile */
|
||||
overscroll-behavior: none;
|
||||
padding: var(--safe-area-top) var(--safe-area-right) var(--safe-area-bottom-capped)
|
||||
@@ -50,13 +44,6 @@ body {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* Fallback for browsers without dvh support */
|
||||
@supports not (height: 1dvh) {
|
||||
.h-dvh {
|
||||
height: 100vh;
|
||||
}
|
||||
}
|
||||
|
||||
/* Mobile sidebar override - ensures sidebar fills Sheet container */
|
||||
[data-state] .sidebar {
|
||||
width: 100%;
|
||||
|
||||
@@ -15,8 +15,8 @@ const REPEATER_AVATAR = {
|
||||
textColor: '#ffffff',
|
||||
};
|
||||
|
||||
// Simple hash function for strings
|
||||
function hashString(str: string): number {
|
||||
// DJB2 hash function for strings
|
||||
export function hashString(str: string): number {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
const char = str.charCodeAt(i);
|
||||
|
||||
@@ -13,7 +13,7 @@ const LAST_MESSAGE_KEY = 'remoteterm-lastMessageTime';
|
||||
const SORT_ORDER_KEY = 'remoteterm-sortOrder';
|
||||
|
||||
export type ConversationTimes = Record<string, number>;
|
||||
type SortOrder = 'recent' | 'alpha';
|
||||
export type SortOrder = 'recent' | 'alpha';
|
||||
|
||||
// In-memory cache of last message times (loaded from server on init)
|
||||
let lastMessageTimesCache: ConversationTimes = {};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { MeshCoreDecoder, PayloadType } from '@michaelhart/meshcore-decoder';
|
||||
import { CONTACT_TYPE_REPEATER, type Contact, type RawPacket } from '../types';
|
||||
import { hashString } from './contactAvatar';
|
||||
|
||||
// =============================================================================
|
||||
// TYPES
|
||||
@@ -114,15 +115,6 @@ export const PACKET_LEGEND_ITEMS = [
|
||||
// UTILITY FUNCTIONS (Data Layer)
|
||||
// =============================================================================
|
||||
|
||||
function simpleHash(str: string): string {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
hash = (hash << 5) - hash + str.charCodeAt(i);
|
||||
hash = hash & hash;
|
||||
}
|
||||
return Math.abs(hash).toString(16).padStart(8, '0');
|
||||
}
|
||||
|
||||
export function parsePacket(hexData: string): ParsedPacket | null {
|
||||
try {
|
||||
const decoded = MeshCoreDecoder.decode(hexData);
|
||||
@@ -182,7 +174,7 @@ export function getPacketLabel(payloadType: number): PacketLabel {
|
||||
}
|
||||
|
||||
export function generatePacketKey(parsed: ParsedPacket, rawPacket: RawPacket): string {
|
||||
const contentHash = (parsed.messageHash || simpleHash(rawPacket.data)).slice(0, 8);
|
||||
const contentHash = (parsed.messageHash || hashString(rawPacket.data).toString(16).padStart(8, '0')).slice(0, 8);
|
||||
|
||||
if (parsed.payloadType === PayloadType.Advert && parsed.advertPubkey) {
|
||||
return `ad:${parsed.advertPubkey.slice(0, 12)}`;
|
||||
|
||||
Reference in New Issue
Block a user