Skip to content

Commit

Permalink
[FIX] Migrate autoTranslate.translateMessage to REST API (#4029)
Browse files Browse the repository at this point in the history
Co-authored-by: Diego Mello <[email protected]>
  • Loading branch information
reinaldonetof and diegolmello authored May 27, 2022
1 parent 1ce7d5c commit a527b32
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
8 changes: 1 addition & 7 deletions app/containers/MessageActions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,7 @@ const MessageActions = React.memo(
});
const translatedMessage = getMessageTranslation(message, room.autoTranslateLanguage);
if (!translatedMessage) {
const m = {
_id: message.id,
rid: message.subscription ? message.subscription.id : '',
u: message.u,
msg: message.msg
};
await Services.translateMessage(m, room.autoTranslateLanguage);
await Services.translateMessage(message.id, room.autoTranslateLanguage);
}
} catch (e) {
log(e);
Expand Down
5 changes: 5 additions & 0 deletions app/definitions/rest/v1/autotranslate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type AutoTranslateEndpoints = {
'autotranslate.translateMessage': {
POST: (params: { messageId: string; targetLanguage: string }) => void;
};
};
4 changes: 3 additions & 1 deletion app/definitions/rest/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { VideoConferenceEndpoints } from './videoConference';
import { CommandsEndpoints } from './commands';
import { PushTokenEndpoints } from './pushToken';
import { DirectoryEndpoint } from './directory';
import { AutoTranslateEndpoints } from './autotranslate';

export type Endpoints = ChannelsEndpoints &
ChatEndpoints &
Expand All @@ -40,4 +41,5 @@ export type Endpoints = ChannelsEndpoints &
VideoConferenceEndpoints &
CommandsEndpoints &
PushTokenEndpoints &
DirectoryEndpoint;
DirectoryEndpoint &
AutoTranslateEndpoints;
4 changes: 2 additions & 2 deletions app/lib/services/restApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,8 @@ export const saveAutoTranslate = ({
export const getSupportedLanguagesAutoTranslate = (): Promise<{ language: string; name: string }[]> =>
sdk.methodCallWrapper('autoTranslate.getSupportedLanguages', 'en');

export const translateMessage = (message: any, targetLanguage: string) =>
sdk.methodCallWrapper('autoTranslate.translateMessage', message, targetLanguage);
export const translateMessage = (messageId: string, targetLanguage: string) =>
sdk.post('autotranslate.translateMessage', { messageId, targetLanguage });

export const findOrCreateInvite = ({ rid, days, maxUses }: { rid: string; days: number; maxUses: number }): any =>
// RC 2.4.0
Expand Down

0 comments on commit a527b32

Please sign in to comment.