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