mirror of
https://github.com/mattermost/mattermost.git
synced 2026-02-18 18:18:23 -05:00
[MM-67563] Change websocket format for translation update events (#35268)
This commit is contained in:
parent
cca467ab2f
commit
6e28452434
3 changed files with 35 additions and 14 deletions
|
|
@ -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<void> {
|
||||
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,
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Post> = {}, 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]: {
|
||||
|
|
|
|||
|
|
@ -423,11 +423,13 @@ export type RecapUpdated = BaseWebSocketMessage<WebSocketEvents.RecapUpdated, {
|
|||
// Post translation messages
|
||||
|
||||
export type PostTranslationUpdated = BaseWebSocketMessage<WebSocketEvents.PostTranslationUpdated, {
|
||||
language: string;
|
||||
object_id: string;
|
||||
src_lang: string;
|
||||
state: 'ready' | 'skipped' | 'processing' | 'unavailable';
|
||||
translation: string;
|
||||
translations: Record<string, {
|
||||
state: 'ready' | 'skipped' | 'processing' | 'unavailable';
|
||||
translation?: string;
|
||||
translation_type?: string;
|
||||
src_lang?: string;
|
||||
}>;
|
||||
}>;
|
||||
|
||||
// Plugin and integration messages
|
||||
|
|
|
|||
Loading…
Reference in a new issue