From 6e28452434b56fecdf56738114b4e9b2368f94a4 Mon Sep 17 00:00:00 2001 From: Ben Cooke Date: Wed, 18 Feb 2026 10:11:45 -0500 Subject: [PATCH] [MM-67563] Change websocket format for translation update events (#35268) --- .../channels/src/actions/websocket_actions.ts | 21 +++++++++++++++---- .../src/reducers/entities/posts.ts | 18 ++++++++++------ .../platform/client/src/websocket_messages.ts | 10 +++++---- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/webapp/channels/src/actions/websocket_actions.ts b/webapp/channels/src/actions/websocket_actions.ts index c89f04f48f8..25614afeb14 100644 --- a/webapp/channels/src/actions/websocket_actions.ts +++ b/webapp/channels/src/actions/websocket_actions.ts @@ -142,6 +142,7 @@ import {openModal, closeModal} from 'actions/views/modals'; import {closeRightHandSide} from 'actions/views/rhs'; import {resetWsErrorCount} from 'actions/views/system'; import {updateThreadLastOpened} from 'actions/views/threads'; +import {getCurrentLocale} from 'selectors/i18n'; import {getSelectedChannelId, getSelectedPost} from 'selectors/rhs'; import {isThreadOpen, isThreadManuallyUnread} from 'selectors/views/threads'; import store from 'stores/redux_store'; @@ -2043,10 +2044,22 @@ export function handleContentFlaggingReportValueChanged(msg: WebSocketMessages.C }; } -export function handlePostTranslationUpdated(msg: WebSocketMessages.PostTranslationUpdated) { - return { - type: PostTypes.POST_TRANSLATION_UPDATED, - data: msg.data, +export function handlePostTranslationUpdated(msg: WebSocketMessages.PostTranslationUpdated): ThunkActionFunc { + return (dispatch, getState) => { + const locale = getCurrentLocale(getState()); + const t = msg.data.translations[locale]; + if (!t) { + return; + } + + dispatch({ + type: PostTypes.POST_TRANSLATION_UPDATED, + data: { + object_id: msg.data.object_id, + language: locale, + ...t, + }, + }); }; } diff --git a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/posts.ts b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/posts.ts index 319d1b7391f..23296c18533 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/posts.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/posts.ts @@ -1,7 +1,6 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import type {WebSocketMessages} from '@mattermost/client'; import type { OpenGraphMetadata, Post, @@ -434,20 +433,27 @@ export function handlePosts(state: IDMappedObjects = {}, action: MMReduxAc } case PostTypes.POST_TRANSLATION_UPDATED: { - const data: WebSocketMessages.PostTranslationUpdated['data'] = action.data; + const data: { + object_id: string; + language: string; + state: 'ready' | 'skipped' | 'processing' | 'unavailable'; + translation?: string; + src_lang?: string; + } = action.data; if (!state[data.object_id]) { return state; } - const translations = state[data.object_id].metadata?.translations || {}; + const existingTranslations = state[data.object_id].metadata?.translations || {}; const newTranslations = { - ...translations, + ...existingTranslations, [data.language]: { - lang: data.language, object: data.translation ? JSON.parse(data.translation) : undefined, state: data.state, source_lang: data.src_lang, - }}; + }, + }; + return { ...state, [data.object_id]: { diff --git a/webapp/platform/client/src/websocket_messages.ts b/webapp/platform/client/src/websocket_messages.ts index f8b178f67d0..e319d9305b3 100644 --- a/webapp/platform/client/src/websocket_messages.ts +++ b/webapp/platform/client/src/websocket_messages.ts @@ -423,11 +423,13 @@ export type RecapUpdated = BaseWebSocketMessage; }>; // Plugin and integration messages