fix: Prefer cached channels before loaded
This commit is contained in:
@@ -117,6 +117,26 @@ function resolveUserDisplayName(user: Pick<User, 'displayName' | 'username'> | n
|
||||
return user?.username?.trim() || 'User';
|
||||
}
|
||||
|
||||
function hasPersistedChannels(channels: Room['channels'] | undefined): channels is NonNullable<Room['channels']> {
|
||||
return Array.isArray(channels) && channels.length > 0;
|
||||
}
|
||||
|
||||
/** Keep cached channels until directory metadata provides a concrete replacement. */
|
||||
function resolveRoomChannels(
|
||||
cachedChannels: Room['channels'] | undefined,
|
||||
incomingChannels: Room['channels'] | undefined
|
||||
): Room['channels'] | undefined {
|
||||
if (hasPersistedChannels(incomingChannels)) {
|
||||
return incomingChannels;
|
||||
}
|
||||
|
||||
if (hasPersistedChannels(cachedChannels)) {
|
||||
return cachedChannels;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
interface RoomPresenceSignalingMessage {
|
||||
type: string;
|
||||
reason?: string;
|
||||
@@ -302,7 +322,7 @@ export class RoomsEffects {
|
||||
const resolvedRoom: Room = {
|
||||
...room,
|
||||
isPrivate: typeof serverInfo?.isPrivate === 'boolean' ? serverInfo.isPrivate : room.isPrivate,
|
||||
channels: Array.isArray(serverInfo?.channels) ? serverInfo.channels : room.channels,
|
||||
channels: resolveRoomChannels(room.channels, serverInfo?.channels),
|
||||
sourceId: serverInfo?.sourceId ?? room.sourceId,
|
||||
sourceName: serverInfo?.sourceName ?? room.sourceName,
|
||||
sourceUrl: serverInfo?.sourceUrl ?? room.sourceUrl,
|
||||
@@ -336,7 +356,7 @@ export class RoomsEffects {
|
||||
createdAt: Date.now(),
|
||||
userCount: 1,
|
||||
maxUsers: 50,
|
||||
channels: Array.isArray(serverInfo.channels) ? serverInfo.channels : undefined,
|
||||
channels: resolveRoomChannels(undefined, serverInfo.channels),
|
||||
sourceId: serverInfo.sourceId,
|
||||
sourceName: serverInfo.sourceName,
|
||||
sourceUrl: serverInfo.sourceUrl
|
||||
@@ -361,7 +381,7 @@ export class RoomsEffects {
|
||||
createdAt: serverData.createdAt || Date.now(),
|
||||
userCount: serverData.userCount,
|
||||
maxUsers: serverData.maxUsers,
|
||||
channels: Array.isArray(serverData.channels) ? serverData.channels : undefined,
|
||||
channels: resolveRoomChannels(undefined, serverData.channels),
|
||||
sourceId: serverData.sourceId,
|
||||
sourceName: serverData.sourceName,
|
||||
sourceUrl: serverData.sourceUrl
|
||||
@@ -428,7 +448,7 @@ export class RoomsEffects {
|
||||
hasPassword: !!serverData.hasPassword,
|
||||
isPrivate: serverData.isPrivate,
|
||||
maxUsers: serverData.maxUsers,
|
||||
channels: Array.isArray(serverData.channels) ? serverData.channels : room.channels,
|
||||
channels: resolveRoomChannels(room.channels, serverData.channels),
|
||||
sourceId: serverData.sourceId ?? room.sourceId,
|
||||
sourceName: serverData.sourceName ?? room.sourceName,
|
||||
sourceUrl: serverData.sourceUrl ?? room.sourceUrl
|
||||
|
||||
Reference in New Issue
Block a user