Polish off all our gross edges around frontend/backend Public name management

This commit is contained in:
Jack Kingsman
2026-03-15 18:20:43 -07:00
parent c76f230c9f
commit c809dad05d
46 changed files with 311 additions and 140 deletions
+5 -10
View File
@@ -4,10 +4,9 @@ import { takePrefetchOrFetch } from '../prefetch';
import { toast } from '../components/ui/sonner';
import * as messageCache from '../messageCache';
import { getContactDisplayName } from '../utils/pubkey';
import { findPublicChannel, PUBLIC_CHANNEL_KEY, PUBLIC_CHANNEL_NAME } from '../utils/publicChannel';
import type { Channel, Contact, Conversation } from '../types';
const PUBLIC_CHANNEL_KEY = '8B3387E9C5CDEA6AC9E5EDBAA115CD72';
interface UseContactsAndChannelsArgs {
setActiveConversation: (conv: Conversation | null) => void;
pendingDeleteFallbackRef: MutableRefObject<boolean>;
@@ -121,14 +120,12 @@ export function useContactsAndChannels({
messageCache.remove(key);
const refreshedChannels = await api.getChannels();
setChannels(refreshedChannels);
const publicChannel =
refreshedChannels.find((c) => c.key === PUBLIC_CHANNEL_KEY) ||
refreshedChannels.find((c) => c.name === 'Public');
const publicChannel = findPublicChannel(refreshedChannels);
hasSetDefaultConversation.current = true;
setActiveConversation({
type: 'channel',
id: publicChannel?.key || PUBLIC_CHANNEL_KEY,
name: publicChannel?.name || 'Public',
name: publicChannel?.name || PUBLIC_CHANNEL_NAME,
});
toast.success('Channel deleted');
} catch (err) {
@@ -151,14 +148,12 @@ export function useContactsAndChannels({
setContacts((prev) => prev.filter((c) => c.public_key !== publicKey));
const refreshedChannels = await api.getChannels();
setChannels(refreshedChannels);
const publicChannel =
refreshedChannels.find((c) => c.key === PUBLIC_CHANNEL_KEY) ||
refreshedChannels.find((c) => c.name === 'Public');
const publicChannel = findPublicChannel(refreshedChannels);
hasSetDefaultConversation.current = true;
setActiveConversation({
type: 'channel',
id: publicChannel?.key || PUBLIC_CHANNEL_KEY,
name: publicChannel?.name || 'Public',
name: publicChannel?.name || PUBLIC_CHANNEL_NAME,
});
toast.success('Contact deleted');
} catch (err) {
+3 -6
View File
@@ -10,11 +10,10 @@ import {
getReopenLastConversationEnabled,
saveLastViewedConversation,
} from '../utils/lastViewedConversation';
import { findPublicChannel } from '../utils/publicChannel';
import { getContactDisplayName } from '../utils/pubkey';
import type { Channel, Contact, Conversation } from '../types';
const PUBLIC_CHANNEL_KEY = '8B3387E9C5CDEA6AC9E5EDBAA115CD72';
interface UseConversationRouterArgs {
channels: Channel[];
contacts: Contact[];
@@ -44,7 +43,7 @@ export function useConversationRouter({
}, []);
const getPublicChannelConversation = useCallback((): Conversation | null => {
const publicChannel = channels.find((c) => c.name === 'Public');
const publicChannel = findPublicChannel(channels);
if (!publicChannel) return null;
return {
type: 'channel',
@@ -221,9 +220,7 @@ export function useConversationRouter({
return;
}
const publicChannel =
channels.find((c) => c.key === PUBLIC_CHANNEL_KEY) ||
channels.find((c) => c.name === 'Public');
const publicChannel = findPublicChannel(channels);
if (!publicChannel) return;
hasSetDefaultConversation.current = true;