fix(web): normalize channel IDs to lowercase across stores and WS
This commit is contained in:
@@ -49,13 +49,14 @@ export const useChannelStore = create<ChannelState>((set) => ({
|
||||
},
|
||||
|
||||
setActiveChannel: (id) => {
|
||||
set({ activeChannelId: id });
|
||||
if (id) {
|
||||
const chId = id ? id.toLowerCase() : null;
|
||||
set({ activeChannelId: chId });
|
||||
if (chId) {
|
||||
// ponytail: persist last active channel for session restore
|
||||
const state = useChannelStore.getState();
|
||||
for (const [serverId, channels] of Object.entries(state.channelsByServer)) {
|
||||
if (channels.some((c) => c.id === id)) {
|
||||
localStorage.setItem('dumpster:lastChannel', JSON.stringify({ serverId, channelId: id }));
|
||||
if (channels.some((c) => c.id.toLowerCase() === chId)) {
|
||||
localStorage.setItem('dumpster:lastChannel', JSON.stringify({ serverId, channelId: chId }));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,11 +27,12 @@ export const useReadStatesStore = create<ReadStatesState>()((set, get) => ({
|
||||
},
|
||||
|
||||
markRead: async (channelId: string, messageId: string) => {
|
||||
const chId = channelId.toLowerCase();
|
||||
set((state) => ({
|
||||
states: { ...state.states, [channelId]: messageId },
|
||||
states: { ...state.states, [chId]: messageId },
|
||||
}));
|
||||
try {
|
||||
await api.put(`/channels/${channelId}/read`, { last_read_message_id: messageId });
|
||||
await api.put(`/channels/${chId}/read`, { last_read_message_id: messageId });
|
||||
} catch {
|
||||
// optimistic update, ignore failure
|
||||
}
|
||||
@@ -45,8 +46,9 @@ export const useReadStatesStore = create<ReadStatesState>()((set, get) => ({
|
||||
},
|
||||
|
||||
hasUnread: (channelId: string, latestMessageId?: string): boolean => {
|
||||
const chId = channelId.toLowerCase();
|
||||
const state = get().states;
|
||||
const lastRead = state[channelId];
|
||||
const lastRead = state[chId];
|
||||
// never viewed: unread if there are messages
|
||||
if (!lastRead) return !!latestMessageId;
|
||||
// viewed but newer messages exist
|
||||
|
||||
@@ -61,7 +61,7 @@ function extractIds(payload: UnknownPayload | undefined): { channel_id?: string;
|
||||
? payload.id
|
||||
: null;
|
||||
if (!messageId) return null;
|
||||
if (typeof payload.channel_id === 'string') return { channel_id: payload.channel_id, message_id: messageId };
|
||||
if (typeof payload.channel_id === 'string') return { channel_id: payload.channel_id.toLowerCase(), message_id: messageId };
|
||||
if (typeof payload.conversation_id === 'string') return { conversation_id: payload.conversation_id.toLowerCase(), message_id: messageId };
|
||||
return null;
|
||||
}
|
||||
@@ -150,7 +150,8 @@ export const useWebSocketStore = create<WebSocketState>((set, get) => ({
|
||||
}
|
||||
} else {
|
||||
const msg = payload as unknown as Message;
|
||||
addMessage(msg);
|
||||
const normalizedMsg = { ...msg, channel_id: (msg.channel_id || '').toLowerCase() };
|
||||
addMessage(normalizedMsg);
|
||||
|
||||
// Desktop notification
|
||||
const currentUserId = useAuthStore.getState().user?.id;
|
||||
|
||||
Reference in New Issue
Block a user