Persistent message store (#814)
* Fix default filter behaviour * Persist message store * messageStore tests, node PKI validation Implement node validation and improve merging logic - Added `validateIncomingNode` function to validate new nodes against existing nodes, checking for public key conflicts and ensuring proper handling of node updates. - Updated `nodeDBFactory` to utilize the new validation function when adding nodes. - Enhanced `getNodes` method to optionally include the current node in the results. - Removed the `mergeNodeInfo` utility as its functionality is now integrated into the validation and merging process. - Updated tests to cover new validation logic and ensure correct behavior during node addition and merging. - Cleaned up unused utility functions related to key comparison. * refactor: reuse eviction logic for message and node stores * Update format, move hooks * Improve test performance * Update imports --------- Co-authored-by: philon- <philon-@users.noreply.github.com> Co-authored-by: Dan Ditomaso <dan.ditomaso@gmail.com>
This commit is contained in:
co-authored by
philon-
Dan Ditomaso
parent
799283fd46
commit
dcb44d27fe
@@ -0,0 +1,19 @@
|
||||
import { createContext, useContext } from "react";
|
||||
|
||||
export type DeviceContext = {
|
||||
deviceId: number; // Unique identifier for the device, not nodeNum
|
||||
};
|
||||
|
||||
export const CurrentDeviceContext = createContext<DeviceContext | undefined>(
|
||||
undefined,
|
||||
);
|
||||
|
||||
export function useDeviceContext(): DeviceContext {
|
||||
const ctx = useContext(CurrentDeviceContext);
|
||||
if (!ctx) {
|
||||
throw new Error(
|
||||
"useDeviceContext must be used within CurrentDeviceContext provider",
|
||||
);
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { useDeviceStore, useMessageStore, useNodeDBStore } from "@core/stores";
|
||||
import type { Protobuf } from "@meshtastic/core";
|
||||
|
||||
export function useNewNodeNum(
|
||||
id: number,
|
||||
nodeInfo: Protobuf.Mesh.MyNodeInfo,
|
||||
): void {
|
||||
useDeviceStore.getState().getDevice(id)?.setHardware(nodeInfo);
|
||||
useNodeDBStore.getState().getNodeDB(id)?.setNodeNum(nodeInfo.myNodeNum);
|
||||
useMessageStore
|
||||
.getState()
|
||||
.getMessageStore(id)
|
||||
?.setNodeNum(nodeInfo.myNodeNum);
|
||||
}
|
||||
Reference in New Issue
Block a user