YouBar+: save notifications immediately instead of debounced, live-refresh the inbox screen

This commit is contained in:
Ally Founder 2026-08-12 14:26:31 -04:00
parent 1f6971e7a3
commit 02e0a8ac54
2 changed files with 15 additions and 12 deletions

View file

@ -34,19 +34,21 @@ const lastActivitySignature = new Map<string, string>();
const RELATIONSHIP_PENDING_INCOMING = 3;
let memoryNotifications: NotificationItem[] = [];
let saveTimeout: ReturnType<typeof setTimeout> | undefined;
function syncStorageDebounced() {
if (saveTimeout) clearTimeout(saveTimeout);
saveTimeout = setTimeout(() => {
storage.notifications = memoryNotifications.slice(0, 100);
}, 3000);
// The inbox UI has no Flux store to subscribe to, just this module-level array - listeners let it
// re-render when a new notification lands instead of only refreshing on its own next render.
const listeners = new Set<() => void>();
export function subscribeToNotifications(listener: () => void): () => void {
listeners.add(listener);
return () => listeners.delete(listener);
}
function pushNotification(item: NotificationItem) {
if (memoryNotifications.some((n) => n.id === item.id)) return;
memoryNotifications = [item, ...memoryNotifications];
syncStorageDebounced();
memoryNotifications = [item, ...memoryNotifications].slice(0, 100);
storage.notifications = memoryNotifications;
listeners.forEach((l) => l());
}
export function getNotifications(): NotificationItem[] {
@ -324,8 +326,6 @@ function startTrackingNotifications(): () => void {
const unsubPresence = fluxSubscribe("PRESENCE_UPDATES", handlePresenceUpdates);
return () => {
if (saveTimeout) clearTimeout(saveTimeout);
storage.notifications = memoryNotifications.slice(0, 100);
unsubMessage();
unsubReaction();
unsubRelationship();

View file

@ -2,14 +2,14 @@ import { React, ReactNative, NavigationNative } from "@vendetta/metro/common";
import { findByProps, findByDisplayName } from "@vendetta/metro";
import { storage } from "@vendetta/plugin";
import { TableRow, TableRowGroup } from "@shared/ui/table";
import { getNotifications } from "../lib/notifications";
import { getNotifications, subscribeToNotifications } from "../lib/notifications";
import type { MentionSubCategory, NotificationCategory, NotificationItem } from "../lib/types";
// Ported from fshinz/Revenge-Plugins' BetterInbox (credit: shin), merged in here as an optional
// YouBar+ feature - see lib/notifications.ts for why.
const { View, Text, TouchableOpacity, ScrollView, Image, StyleSheet } = ReactNative;
const { useState, useMemo, useCallback, memo } = React;
const { useState, useMemo, useCallback, useEffect, useReducer, memo } = React;
const Router = findByProps("transitionToGuild", "transitionTo");
const NativeTabs = findByDisplayName("Tabs");
@ -66,6 +66,9 @@ export default function NotificationCenter(): JSX.Element {
})
: null;
const [, forceUpdate] = useReducer((x: number) => x + 1, 0);
useEffect(() => subscribeToNotifications(() => forceUpdate()), []);
const notifications = getNotifications();
const displayedNotifications = useMemo(() => {