Skip to content

Commit

Permalink
refactor: udpate conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
filipemarins committed Nov 25, 2022
1 parent b5a71a4 commit d405f19
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
11 changes: 4 additions & 7 deletions apps/meteor/app/autotranslate/client/lib/actionButton.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import { isTranslatedMessage } from '@rocket.chat/core-typings';

import { AutoTranslate } from './autotranslate';
import { settings } from '../../../settings/client';
Expand Down Expand Up @@ -41,12 +40,11 @@ Meteor.startup(() => {
}

return Boolean(
message?.u &&
(message?.u &&
message.u._id !== user._id &&
subscription?.autoTranslate &&
((isTranslatedMessage(message) && message.autoTranslateShowInverse) ||
(!hasTranslationLanguageInMessage(message, language) &&
!hasTranslationLanguageInAttachments(message.attachments, language))),
(message as { autoTranslateShowInverse?: boolean }).autoTranslateShowInverse) ||
(!hasTranslationLanguageInMessage(message, language) && !hasTranslationLanguageInAttachments(message.attachments, language)),
);
},
order: 90,
Expand Down Expand Up @@ -76,9 +74,8 @@ Meteor.startup(() => {
return Boolean(
message?.u &&
message.u._id !== user._id &&
isTranslatedMessage(message) &&
subscription?.autoTranslate &&
!message.autoTranslateShowInverse &&
!(message as { autoTranslateShowInverse?: boolean }).autoTranslateShowInverse &&
(hasTranslationLanguageInMessage(message, language) || hasTranslationLanguageInAttachments(message.attachments, language)),
);
},
Expand Down
5 changes: 4 additions & 1 deletion apps/meteor/app/ui-message/client/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { renderMessageBody } from '../../../client/lib/utils/renderMessageBody';
import { settings } from '../../settings/client';
import { formatTime } from '../../../client/lib/utils/formatTime';
import { formatDate } from '../../../client/lib/utils/formatDate';
import { hasTranslationLanguageInAttachments } from '../../../client/views/room/MessageList/lib/autoTranslate';
import './messageThread';
import './message.html';
import { roomCoordinator } from '../../../client/lib/rooms/roomCoordinator';
Expand Down Expand Up @@ -257,7 +258,9 @@ Template.message.helpers({
const autoTranslate = subscription && subscription.autoTranslate;
return (
msg.autoTranslateFetching ||
(!!autoTranslate !== !!msg.autoTranslateShowInverse && msg.translations && msg.translations[settings.translateLanguage])
(!!autoTranslate !== !!msg.autoTranslateShowInverse && msg.translations && msg.translations[settings.translateLanguage]) ||
(!!autoTranslate !== !!msg.autoTranslateShowInverse &&
hasTranslationLanguageInAttachments(msg.attachments, settings.translateLanguage))
);
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IMessage, isTranslatedMessage, ISubscription } from '@rocket.chat/core-typings';
import { IMessage, ISubscription } from '@rocket.chat/core-typings';
import { useSetting } from '@rocket.chat/ui-contexts';

import { hasTranslationLanguageInAttachments, hasTranslationLanguageInMessage } from '../lib/autoTranslate';
Expand All @@ -21,13 +21,10 @@ export const useAutoTranslate = (subscription?: ISubscription): AutoTranslateOpt
showAutoTranslate: autoTranslateEnabled
? (message: IMessage): boolean =>
!isOwnUserMessage(message, subscription) &&
isTranslatedMessage(message) &&
!message.autoTranslateShowInverse &&
Boolean(
autoTranslateLanguage &&
(hasTranslationLanguageInMessage(message, autoTranslateLanguage) ||
hasTranslationLanguageInAttachments(message.attachments, autoTranslateLanguage)),
)
!!autoTranslateLanguage &&
!(message as { autoTranslateShowInverse?: boolean }).autoTranslateShowInverse &&
(hasTranslationLanguageInMessage(message, autoTranslateLanguage) ||
hasTranslationLanguageInAttachments(message.attachments, autoTranslateLanguage))
: (): boolean => false,
};
};

0 comments on commit d405f19

Please sign in to comment.