wip
This commit is contained in:
@@ -151,7 +151,7 @@ export const useDeviceStore = createStore<DeviceState>((set, get) => ({
|
|||||||
},
|
},
|
||||||
pendingSettingsChanges: false,
|
pendingSettingsChanges: false,
|
||||||
messageDraft: "",
|
messageDraft: "",
|
||||||
unreadCounts: new Map([[0, 100],[2718471552, 1]]),
|
unreadCounts: new Map([[0, 100],[3663106604, 1]]),
|
||||||
|
|
||||||
setStatus: (status: Types.DeviceStatusEnum) => {
|
setStatus: (status: Types.DeviceStatusEnum) => {
|
||||||
set(
|
set(
|
||||||
@@ -634,13 +634,16 @@ export const useDeviceStore = createStore<DeviceState>((set, get) => ({
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
setUnread: (id: number, count: number) => {
|
setUnread: (unread_id: number, count?: number) => {
|
||||||
set(
|
set(
|
||||||
produce<DeviceState>((draft) => {
|
produce<DeviceState>((draft) => {
|
||||||
console.log(id, count);
|
|
||||||
const device = draft.devices.get(id);
|
const device = draft.devices.get(id);
|
||||||
if (device) {
|
if (device) {
|
||||||
device.unreadCounts.set(id, count);
|
if (count == null) {
|
||||||
|
let currentCount = device.unreadCounts.get(unread_id) ?? 0;
|
||||||
|
count = currentCount + 1;
|
||||||
|
}
|
||||||
|
device.unreadCounts.set(unread_id, count);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ export const subscribeAll = (
|
|||||||
...messagePacket,
|
...messagePacket,
|
||||||
state: messagePacket.from !== myNodeNum ? "ack" : "waiting",
|
state: messagePacket.from !== myNodeNum ? "ack" : "waiting",
|
||||||
});
|
});
|
||||||
device.unreadCounts.set(messagePacket.from, 1);
|
device.setUnread(messagePacket.from);
|
||||||
});
|
});
|
||||||
|
|
||||||
connection.events.onTraceRoutePacket.subscribe((traceRoutePacket) => {
|
connection.events.onTraceRoutePacket.subscribe((traceRoutePacket) => {
|
||||||
|
|||||||
@@ -14,14 +14,15 @@ import { HashIcon, LockIcon, LockOpenIcon } from "lucide-react";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
export const MessagesPage = () => {
|
export const MessagesPage = () => {
|
||||||
const { channels, nodes, hardware, messages, unreadCounts } = useDevice();
|
const { channels, nodes, hardware, messages, unreadCounts, setUnread } = useDevice();
|
||||||
const { activeChat, chatType, setActiveChat, setChatType } = useAppStore();
|
const { activeChat, chatType, setActiveChat, setChatType } = useAppStore();
|
||||||
const [searchTerm, setSearchTerm] = useState<string>("");
|
const [searchTerm, setSearchTerm] = useState<string>("");
|
||||||
const filteredNodes = Array.from(nodes.values()).filter((node) => {
|
const filteredNodes = Array.from(nodes.values()).filter((node) => {
|
||||||
if (node.num === hardware.myNodeNum) return false;
|
if (node.num === hardware.myNodeNum) return false;
|
||||||
const nodeName = node.user?.longName ?? `!${numberToHexUnpadded(node.num)}`;
|
const nodeName = node.user?.longName ?? `!${numberToHexUnpadded(node.num)}`;
|
||||||
return nodeName.toLowerCase().includes(searchTerm.toLowerCase());
|
return nodeName.toLowerCase().includes(searchTerm.toLowerCase());
|
||||||
});
|
}).map((node) => { node.unreadCount = unreadCounts.get(node.num) ?? 0; return node;})
|
||||||
|
.sort((a, b) => b.unreadCount - a.unreadCount);
|
||||||
const allChannels = Array.from(channels.values());
|
const allChannels = Array.from(channels.values());
|
||||||
const filteredChannels = allChannels.filter(
|
const filteredChannels = allChannels.filter(
|
||||||
(ch) => ch.role !== Protobuf.Channel.Channel_Role.DISABLED,
|
(ch) => ch.role !== Protobuf.Channel.Channel_Role.DISABLED,
|
||||||
@@ -48,7 +49,7 @@ export const MessagesPage = () => {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
setChatType("broadcast");
|
setChatType("broadcast");
|
||||||
setActiveChat(channel.index);
|
setActiveChat(channel.index);
|
||||||
unreadCounts.set(channel.index, 0);
|
setUnread(channel.index, 0);
|
||||||
}}
|
}}
|
||||||
element={<HashIcon size={16} className="mr-2" />}
|
element={<HashIcon size={16} className="mr-2" />}
|
||||||
/>
|
/>
|
||||||
@@ -75,7 +76,7 @@ export const MessagesPage = () => {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
setChatType("direct");
|
setChatType("direct");
|
||||||
setActiveChat(node.num);
|
setActiveChat(node.num);
|
||||||
unreadCounts.set(node.num, 1)
|
setUnread(node.num, 0)
|
||||||
}}
|
}}
|
||||||
element={
|
element={
|
||||||
<Avatar
|
<Avatar
|
||||||
|
|||||||
Reference in New Issue
Block a user