fix: Prefer cached channels before loaded
This commit is contained in:
@@ -139,7 +139,12 @@ export class InviteComponent implements OnInit {
|
|||||||
RoomsActions.joinRoom({
|
RoomsActions.joinRoom({
|
||||||
roomId: joinResponse.server.id,
|
roomId: joinResponse.server.id,
|
||||||
serverInfo: {
|
serverInfo: {
|
||||||
|
...invite.server,
|
||||||
...joinResponse.server,
|
...joinResponse.server,
|
||||||
|
channels:
|
||||||
|
Array.isArray(joinResponse.server.channels) && joinResponse.server.channels.length > 0
|
||||||
|
? joinResponse.server.channels
|
||||||
|
: invite.server.channels,
|
||||||
sourceId: context.endpoint.id,
|
sourceId: context.endpoint.id,
|
||||||
sourceName: context.endpoint.name,
|
sourceName: context.endpoint.name,
|
||||||
sourceUrl: context.sourceUrl
|
sourceUrl: context.sourceUrl
|
||||||
|
|||||||
@@ -241,6 +241,7 @@ export class ServerSearchComponent implements OnInit {
|
|||||||
maxUsers: room.maxUsers ?? 50,
|
maxUsers: room.maxUsers ?? 50,
|
||||||
hasPassword: typeof room.hasPassword === 'boolean' ? room.hasPassword : !!room.password,
|
hasPassword: typeof room.hasPassword === 'boolean' ? room.hasPassword : !!room.password,
|
||||||
isPrivate: room.isPrivate,
|
isPrivate: room.isPrivate,
|
||||||
|
channels: room.channels,
|
||||||
createdAt: room.createdAt,
|
createdAt: room.createdAt,
|
||||||
ownerId: room.hostId,
|
ownerId: room.hostId,
|
||||||
sourceId: room.sourceId,
|
sourceId: room.sourceId,
|
||||||
@@ -272,7 +273,14 @@ export class ServerSearchComponent implements OnInit {
|
|||||||
sourceId: server.sourceId,
|
sourceId: server.sourceId,
|
||||||
sourceUrl: server.sourceUrl
|
sourceUrl: server.sourceUrl
|
||||||
}));
|
}));
|
||||||
const resolvedServer = response.server ?? server;
|
const resolvedServer = {
|
||||||
|
...server,
|
||||||
|
...response.server,
|
||||||
|
channels:
|
||||||
|
Array.isArray(response.server.channels) && response.server.channels.length > 0
|
||||||
|
? response.server.channels
|
||||||
|
: server.channels
|
||||||
|
};
|
||||||
|
|
||||||
this.closePasswordDialog();
|
this.closePasswordDialog();
|
||||||
this.store.dispatch(
|
this.store.dispatch(
|
||||||
|
|||||||
@@ -311,7 +311,11 @@ export class ServersRailComponent {
|
|||||||
roomId: room.id,
|
roomId: room.id,
|
||||||
serverInfo: {
|
serverInfo: {
|
||||||
...this.toServerInfo(room),
|
...this.toServerInfo(room),
|
||||||
...response.server
|
...response.server,
|
||||||
|
channels:
|
||||||
|
Array.isArray(response.server.channels) && response.server.channels.length > 0
|
||||||
|
? response.server.channels
|
||||||
|
: room.channels
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -370,6 +374,7 @@ export class ServersRailComponent {
|
|||||||
isPrivate: room.isPrivate,
|
isPrivate: room.isPrivate,
|
||||||
createdAt: room.createdAt,
|
createdAt: room.createdAt,
|
||||||
ownerId: room.hostId,
|
ownerId: room.hostId,
|
||||||
|
channels: room.channels,
|
||||||
sourceId: room.sourceId,
|
sourceId: room.sourceId,
|
||||||
sourceName: room.sourceName,
|
sourceName: room.sourceName,
|
||||||
sourceUrl: room.sourceUrl
|
sourceUrl: room.sourceUrl
|
||||||
|
|||||||
@@ -117,6 +117,26 @@ function resolveUserDisplayName(user: Pick<User, 'displayName' | 'username'> | n
|
|||||||
return user?.username?.trim() || 'User';
|
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 {
|
interface RoomPresenceSignalingMessage {
|
||||||
type: string;
|
type: string;
|
||||||
reason?: string;
|
reason?: string;
|
||||||
@@ -302,7 +322,7 @@ export class RoomsEffects {
|
|||||||
const resolvedRoom: Room = {
|
const resolvedRoom: Room = {
|
||||||
...room,
|
...room,
|
||||||
isPrivate: typeof serverInfo?.isPrivate === 'boolean' ? serverInfo.isPrivate : room.isPrivate,
|
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,
|
sourceId: serverInfo?.sourceId ?? room.sourceId,
|
||||||
sourceName: serverInfo?.sourceName ?? room.sourceName,
|
sourceName: serverInfo?.sourceName ?? room.sourceName,
|
||||||
sourceUrl: serverInfo?.sourceUrl ?? room.sourceUrl,
|
sourceUrl: serverInfo?.sourceUrl ?? room.sourceUrl,
|
||||||
@@ -336,7 +356,7 @@ export class RoomsEffects {
|
|||||||
createdAt: Date.now(),
|
createdAt: Date.now(),
|
||||||
userCount: 1,
|
userCount: 1,
|
||||||
maxUsers: 50,
|
maxUsers: 50,
|
||||||
channels: Array.isArray(serverInfo.channels) ? serverInfo.channels : undefined,
|
channels: resolveRoomChannels(undefined, serverInfo.channels),
|
||||||
sourceId: serverInfo.sourceId,
|
sourceId: serverInfo.sourceId,
|
||||||
sourceName: serverInfo.sourceName,
|
sourceName: serverInfo.sourceName,
|
||||||
sourceUrl: serverInfo.sourceUrl
|
sourceUrl: serverInfo.sourceUrl
|
||||||
@@ -361,7 +381,7 @@ export class RoomsEffects {
|
|||||||
createdAt: serverData.createdAt || Date.now(),
|
createdAt: serverData.createdAt || Date.now(),
|
||||||
userCount: serverData.userCount,
|
userCount: serverData.userCount,
|
||||||
maxUsers: serverData.maxUsers,
|
maxUsers: serverData.maxUsers,
|
||||||
channels: Array.isArray(serverData.channels) ? serverData.channels : undefined,
|
channels: resolveRoomChannels(undefined, serverData.channels),
|
||||||
sourceId: serverData.sourceId,
|
sourceId: serverData.sourceId,
|
||||||
sourceName: serverData.sourceName,
|
sourceName: serverData.sourceName,
|
||||||
sourceUrl: serverData.sourceUrl
|
sourceUrl: serverData.sourceUrl
|
||||||
@@ -428,7 +448,7 @@ export class RoomsEffects {
|
|||||||
hasPassword: !!serverData.hasPassword,
|
hasPassword: !!serverData.hasPassword,
|
||||||
isPrivate: serverData.isPrivate,
|
isPrivate: serverData.isPrivate,
|
||||||
maxUsers: serverData.maxUsers,
|
maxUsers: serverData.maxUsers,
|
||||||
channels: Array.isArray(serverData.channels) ? serverData.channels : room.channels,
|
channels: resolveRoomChannels(room.channels, serverData.channels),
|
||||||
sourceId: serverData.sourceId ?? room.sourceId,
|
sourceId: serverData.sourceId ?? room.sourceId,
|
||||||
sourceName: serverData.sourceName ?? room.sourceName,
|
sourceName: serverData.sourceName ?? room.sourceName,
|
||||||
sourceUrl: serverData.sourceUrl ?? room.sourceUrl
|
sourceUrl: serverData.sourceUrl ?? room.sourceUrl
|
||||||
|
|||||||
Reference in New Issue
Block a user