dm cache
This commit is contained in:
@ -8,11 +8,12 @@ import { bech32ToHex } from "Util";
|
||||
import useEventPublisher from "Feed/EventPublisher";
|
||||
|
||||
import DM from "Element/DM";
|
||||
import { TaggedRawEvent } from "@snort/nostr";
|
||||
import { RawEvent, TaggedRawEvent } from "@snort/nostr";
|
||||
import { dmsInChat, isToSelf } from "Pages/MessagesPage";
|
||||
import NoteToSelf from "Element/NoteToSelf";
|
||||
import { RootState } from "State/Store";
|
||||
import { FormattedMessage } from "react-intl";
|
||||
import { useDmCache } from "Hooks/useDmsCache";
|
||||
|
||||
type RouterParams = {
|
||||
id: string;
|
||||
@ -23,11 +24,11 @@ export default function ChatPage() {
|
||||
const publisher = useEventPublisher();
|
||||
const id = bech32ToHex(params.id ?? "");
|
||||
const pubKey = useSelector((s: RootState) => s.login.publicKey);
|
||||
const dms = useSelector((s: RootState) => filterDms(s.login.dms));
|
||||
const [content, setContent] = useState<string>();
|
||||
const dmListRef = useRef<HTMLDivElement>(null);
|
||||
const dms = filterDms(useDmCache());
|
||||
|
||||
function filterDms(dms: TaggedRawEvent[]) {
|
||||
function filterDms(dms: readonly RawEvent[]) {
|
||||
return dmsInChat(id === pubKey ? dms.filter(d => isToSelf(d, pubKey)) : dms, id);
|
||||
}
|
||||
|
||||
|
@ -18,11 +18,11 @@ import { totalUnread } from "Pages/MessagesPage";
|
||||
import useModeration from "Hooks/useModeration";
|
||||
import { NoteCreator } from "Element/NoteCreator";
|
||||
import { db } from "Db";
|
||||
import { UserCache } from "State/Users/UserCache";
|
||||
import { FollowsRelays } from "State/Relays";
|
||||
import useEventPublisher from "Feed/EventPublisher";
|
||||
import { SnortPubKey } from "Const";
|
||||
import SubDebug from "Element/SubDebug";
|
||||
import { preload } from "Cache";
|
||||
import { useDmCache } from "Hooks/useDmsCache";
|
||||
|
||||
export default function Layout() {
|
||||
const location = useLocation();
|
||||
@ -101,8 +101,7 @@ export default function Layout() {
|
||||
db.isAvailable().then(async a => {
|
||||
db.ready = a;
|
||||
if (a) {
|
||||
await UserCache.preload();
|
||||
await FollowsRelays.preload();
|
||||
await preload();
|
||||
}
|
||||
console.debug(`Using db: ${a ? "IndexedDB" : "In-Memory"}`);
|
||||
dispatch(init());
|
||||
@ -192,7 +191,8 @@ const AccountHeader = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { isMuted } = useModeration();
|
||||
const { publicKey, latestNotification, readNotifications, dms } = useSelector((s: RootState) => s.login);
|
||||
const { publicKey, latestNotification, readNotifications } = useSelector((s: RootState) => s.login);
|
||||
const dms = useDmCache();
|
||||
|
||||
const hasNotifications = useMemo(
|
||||
() => latestNotification > readNotifications,
|
||||
|
@ -12,6 +12,7 @@ import NoteToSelf from "Element/NoteToSelf";
|
||||
import useModeration from "Hooks/useModeration";
|
||||
|
||||
import messages from "./messages";
|
||||
import { useDmCache } from "Hooks/useDmsCache";
|
||||
|
||||
type DmChat = {
|
||||
pubkey: HexKey;
|
||||
@ -22,9 +23,9 @@ type DmChat = {
|
||||
export default function MessagesPage() {
|
||||
const dispatch = useDispatch();
|
||||
const myPubKey = useSelector<RootState, HexKey | undefined>(s => s.login.publicKey);
|
||||
const dms = useSelector<RootState, RawEvent[]>(s => s.login.dms);
|
||||
const dmInteraction = useSelector<RootState, number>(s => s.login.dmInteraction);
|
||||
const { isMuted } = useModeration();
|
||||
const dms = useDmCache();
|
||||
|
||||
const chats = useMemo(() => {
|
||||
return extractChats(
|
||||
@ -105,11 +106,11 @@ export function dmTo(e: RawEvent) {
|
||||
return firstP ? firstP[1] : "";
|
||||
}
|
||||
|
||||
export function isToSelf(e: RawEvent, pk: HexKey) {
|
||||
export function isToSelf(e: Readonly<RawEvent>, pk: HexKey) {
|
||||
return e.pubkey === pk && dmTo(e) === pk;
|
||||
}
|
||||
|
||||
export function dmsInChat(dms: RawEvent[], pk: HexKey) {
|
||||
export function dmsInChat(dms: readonly RawEvent[], pk: HexKey) {
|
||||
return dms.filter(a => a.pubkey === pk || dmTo(a) === pk);
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,8 @@ import { debounce } from "Util";
|
||||
import { router } from "index";
|
||||
import { SearchRelays } from "Const";
|
||||
import { System } from "System";
|
||||
import { MetadataCache } from "State/Users";
|
||||
import { UserCache } from "State/Users/UserCache";
|
||||
import { MetadataCache } from "Cache";
|
||||
import { UserCache } from "Cache/UserCache";
|
||||
|
||||
import messages from "./messages";
|
||||
|
||||
|
@ -12,8 +12,11 @@ const SettingsIndex = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
function handleLogout() {
|
||||
dispatch(logout());
|
||||
window.location.href = "/";
|
||||
dispatch(
|
||||
logout(() => {
|
||||
navigate("/");
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
|
Reference in New Issue
Block a user