Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
fix(console): reopen a Mattermost room once its server's Mattermost is back (#927)
Louis Amaudruze03ab6b9d74d
diff --git a/console/apps/switch-console-desktop/src/main/core/switch-rooms/mattermost-embed.ts b/console/apps/switch-console-desktop/src/main/core/switch-rooms/mattermost-embed.tsindex 99f539e66..0929b97e4 100644--- a/console/apps/switch-console-desktop/src/main/core/switch-rooms/mattermost-embed.ts+++ b/console/apps/switch-console-desktop/src/main/core/switch-rooms/mattermost-embed.ts@@ -166,9 +166,13 @@ export async function resolveChannelEmbed(params: {if (externalChannelUrl) {return { kind: 'external', url: externalChannelUrl, platform: bridgeType };}+ // The server sends no link both for a room with no channel and while its+ // Mattermost bridge is not running, which on a local server is the minutes+ // Mattermost takes to come up after the server does.return {kind: 'unavailable',- reason: 'No Mattermost channel is linked to this room yet.',+ reason:+ 'This room’s Mattermost channel can’t be reached right now. If the server has just started, Mattermost can take a few minutes to come up.',};}diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-embed-layer.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-embed-layer.tsxindex 4bbf48cf0..94ae8c970 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-embed-layer.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-embed-layer.tsx@@ -9,7 +9,7 @@ import { rpc } from '@renderer/lib/ipc';import { appState } from '@renderer/lib/stores/app-state';import { Button } from '@renderer/lib/ui/button';import { cn } from '@renderer/utils/utils';-import type { RoomEmbed } from '@shared/core/switch-rooms/room-embed';+import { embedIsStale, type RoomEmbed } from '@shared/core/switch-rooms/room-embed';import { openRoomChannel } from './room-links';import { roomTabStore } from './room-tab-store';import { currentMattermostTheme } from './theme-tokens';@@ -24,7 +24,8 @@ const MAX_LIVE_EMBEDS = 4;type EmbedState =| { phase: 'resolving' }- | { phase: 'ready'; embed: RoomEmbed }+ /** `channelUrl`: the room's channel link the embed was decided with. */+ | { phase: 'ready'; embed: RoomEmbed; channelUrl: string | null }| { phase: 'error'; message: string };function RoomNotice({@@ -90,14 +91,15 @@ export const RoomEmbedLayer = observer(function RoomEmbedLayer() {return;}+ const channelUrl = switchRoomsStore.roomChannelUrl(roomId);try {const embed = await rpc.switchRooms.resolveRoomEmbed({serverId,bridgeType: switchRoomsStore.roomBridgeTypeById(roomId),- externalChannelUrl: switchRoomsStore.roomChannelUrl(roomId),+ externalChannelUrl: channelUrl,theme: currentMattermostTheme(effectiveTheme),});- setStates((prev) => new Map(prev).set(roomId, { phase: 'ready', embed }));+ setStates((prev) => new Map(prev).set(roomId, { phase: 'ready', embed, channelUrl }));} catch (cause) {setStates((prev) =>new Map(prev).set(roomId, {@@ -134,6 +136,16 @@ export const RoomEmbedLayer = observer(function RoomEmbedLayer() {if (!startedRef.current.has(activeRoomId)) void resolve(activeRoomId);}, [activeRoomId, resolve]);+ // The room list is read again every little while; a room whose channel link+ // has come back since it was opened is opened again.+ const activeState = activeRoomId ? states.get(activeRoomId) : undefined;+ const activeChannelUrl = activeRoomId ? switchRoomsStore.roomChannelUrl(activeRoomId) : null;+ useEffect(() => {+ if (!activeRoomId || activeState?.phase !== 'ready') return;+ if (embedIsStale(activeState.embed, activeState.channelUrl, activeChannelUrl))+ void resolve(activeRoomId);+ }, [activeRoomId, activeState, activeChannelUrl, resolve]);+/** A theme switch needs the guest reloaded, not just re-pushed.*@@ -170,7 +182,7 @@ export const RoomEmbedLayer = observer(function RoomEmbedLayer() {// just not on screen.const visible =isRoomView && activeRoomId !== null && roomTabStore.tabFor(activeRoomId) === 'chat';- const active = activeRoomId ? states.get(activeRoomId) : undefined;+ const active = activeState;return (<div@@ -205,7 +217,24 @@ export const RoomEmbedLayer = observer(function RoomEmbedLayer() {) : null}{visible && active?.phase === 'ready' && active.embed.kind === 'unavailable' ? (- <RoomNotice icon={<MessagesSquare className="size-6" />} title={active.embed.reason} />+ <RoomNotice+ icon={<MessagesSquare className="size-6" />}+ title={active.embed.reason}+ action={+ <Button+ variant="outline"+ size="sm"+ // The link comes from the room list, so it is read again first.+ onClick={() => {+ if (!activeRoomId) return;+ void switchRoomsStore.loadRoomNames().then(() => resolve(activeRoomId));+ }}+ >+ <RefreshCw className="size-3" />+ Retry+ </Button>+ }+ />) : null}{visible && active?.phase === 'ready' && active.embed.kind === 'unlinked' ? (diff --git a/console/apps/switch-console-desktop/src/shared/core/switch-rooms/room-embed.test.ts b/console/apps/switch-console-desktop/src/shared/core/switch-rooms/room-embed.test.tsindex e1cb9f9b8..9dee523b9 100644--- a/console/apps/switch-console-desktop/src/shared/core/switch-rooms/room-embed.test.ts+++ b/console/apps/switch-console-desktop/src/shared/core/switch-rooms/room-embed.test.ts@@ -1,5 +1,10 @@import { describe, expect, it } from 'vitest';-import { channelUrlFromDeeplink, mattermostPartition } from './room-embed';+import {+ channelUrlFromDeeplink,+ embedIsStale,+ mattermostPartition,+ type RoomEmbed,+} from './room-embed';describe('channelUrlFromDeeplink', () => {it('rewrites a Mattermost deeplink onto the origin we serve it from', () => {@@ -46,3 +51,30 @@ describe('mattermostPartition', () => {expect(mattermostPartition('a').startsWith('persist:')).toBe(true);});});++describe('embedIsStale', () => {+ const unavailable: RoomEmbed = { kind: 'unavailable', reason: 'down' };+ const inline: RoomEmbed = {+ kind: 'inline',+ url: 'http://localhost:8065/switch/channels/town-square',+ partition: 'persist:mm',+ chromeless: true,+ };++ it('decides again once the link a room was missing comes back', () => {+ expect(embedIsStale(unavailable, null, 'mattermost://town-square')).toBe(true);+ });++ it('leaves a room whose link has not changed', () => {+ expect(embedIsStale(unavailable, null, null)).toBe(false);+ expect(embedIsStale(inline, 'mattermost://a', 'mattermost://a')).toBe(false);+ });++ it('keeps a live conversation when its link merely goes missing', () => {+ expect(embedIsStale(inline, 'mattermost://a', null)).toBe(false);+ });++ it('decides again when the link points somewhere else', () => {+ expect(embedIsStale(inline, 'mattermost://a', 'mattermost://b')).toBe(true);+ });+});diff --git a/console/apps/switch-console-desktop/src/shared/core/switch-rooms/room-embed.ts b/console/apps/switch-console-desktop/src/shared/core/switch-rooms/room-embed.tsindex 0719197a8..bf27e73ff 100644--- a/console/apps/switch-console-desktop/src/shared/core/switch-rooms/room-embed.ts+++ b/console/apps/switch-console-desktop/src/shared/core/switch-rooms/room-embed.ts@@ -64,3 +64,22 @@ export function channelUrlFromDeeplink(deeplink: string, mattermostOrigin: strinexport function mattermostPartition(serverId: string): string {return `persist:switch-mattermost:${serverId}`;}++/**+ * Whether a room's conversation, decided while its channel link was+ * `resolvedUrl`, has to be decided again now the room list says `currentUrl`.+ *+ * The link is missing while the server's bridge is not running — a local+ * server's Mattermost comes up minutes after the server does — so a room+ * opened in that window would otherwise stay "unavailable" once it is back.+ * A live conversation is not torn down for a link that has merely gone+ * missing: its own page reconnects when the platform does.+ */+export function embedIsStale(+ embed: RoomEmbed,+ resolvedUrl: string | null,+ currentUrl: string | null+): boolean {+ if (resolvedUrl === currentUrl) return false;+ return currentUrl !== null || embed.kind !== 'inline';+}