mirror of
https://github.com/RocketChat/Rocket.Chat.git
synced 2025-12-28 14:58:55 +00:00
feat: Update autotranslate on language preference change (#31417)
This commit is contained in:
parent
baf5694465
commit
e7d3cdeef0
6
.changeset/sixty-bananas-sit.md
Normal file
6
.changeset/sixty-bananas-sit.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"@rocket.chat/meteor": minor
|
||||
"@rocket.chat/model-typings": minor
|
||||
---
|
||||
|
||||
Added feature to sync the user's language preference with the autotranslate setting.
|
||||
@ -5,6 +5,8 @@ import type { ThemePreference } from '@rocket.chat/ui-theming/src/types/themes';
|
||||
import { Match, check } from 'meteor/check';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
import { settings as rcSettings } from '../../app/settings/server';
|
||||
|
||||
type UserPreferences = {
|
||||
language: string;
|
||||
newRoomNotification: string;
|
||||
@ -102,6 +104,7 @@ export const saveUserPreferences = async (settings: Partial<UserPreferences>, us
|
||||
desktopNotifications: oldDesktopNotifications,
|
||||
pushNotifications: oldMobileNotifications,
|
||||
emailNotificationMode: oldEmailNotifications,
|
||||
language: oldLanguage,
|
||||
} = user.settings?.preferences || {};
|
||||
|
||||
if (user.settings == null) {
|
||||
@ -169,6 +172,10 @@ export const saveUserPreferences = async (settings: Partial<UserPreferences>, us
|
||||
if (Array.isArray(settings.highlights)) {
|
||||
await Subscriptions.updateUserHighlights(user._id, settings.highlights);
|
||||
}
|
||||
|
||||
if (settings.language && oldLanguage !== settings.language && rcSettings.get('AutoTranslate_AutoEnableOnJoinRoom')) {
|
||||
await Subscriptions.updateAllAutoTranslateLanguagesByUserId(user._id, settings.language);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -61,6 +61,7 @@ export class SubscriptionsRaw extends BaseRaw<ISubscription> implements ISubscri
|
||||
{ key: { prid: 1 } },
|
||||
{ key: { 'u._id': 1, 'open': 1, 'department': 1 } },
|
||||
{ key: { rid: 1, ls: 1 } },
|
||||
{ key: { 'u._id': 1, 'autotranslate': 1 } },
|
||||
];
|
||||
}
|
||||
|
||||
@ -603,6 +604,21 @@ export class SubscriptionsRaw extends BaseRaw<ISubscription> implements ISubscri
|
||||
return this.updateOne(query, update);
|
||||
}
|
||||
|
||||
updateAllAutoTranslateLanguagesByUserId(userId: IUser['_id'], language: string): Promise<UpdateResult | Document> {
|
||||
const query = {
|
||||
'u._id': userId,
|
||||
'autoTranslate': true,
|
||||
};
|
||||
|
||||
const update: UpdateFilter<ISubscription> = {
|
||||
$set: {
|
||||
autoTranslateLanguage: language,
|
||||
},
|
||||
};
|
||||
|
||||
return this.updateMany(query, update);
|
||||
}
|
||||
|
||||
disableAutoTranslateByRoomId(roomId: IRoom['_id']): Promise<UpdateResult | Document> {
|
||||
const query = {
|
||||
rid: roomId,
|
||||
|
||||
@ -470,6 +470,14 @@ describe('AutoTranslate', function () {
|
||||
expect(sub).to.have.property('autoTranslate');
|
||||
expect(sub).to.have.property('autoTranslateLanguage').and.to.be.equal('en');
|
||||
});
|
||||
|
||||
it('should change the auto translate language when the user changes his language preference', async () => {
|
||||
await setLanguagePref('es', credA);
|
||||
const subscription = await getSub(channel._id, credA);
|
||||
|
||||
expect(subscription).to.have.property('autoTranslate', true);
|
||||
expect(subscription).to.have.property('autoTranslateLanguage', 'es');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -131,6 +131,7 @@ export interface ISubscriptionsModel extends IBaseModel<ISubscription> {
|
||||
findByUserId(userId: string, options?: FindOptions<ISubscription>): FindCursor<ISubscription>;
|
||||
cachedFindByUserId(userId: string, options?: FindOptions<ISubscription>): FindCursor<ISubscription>;
|
||||
updateAutoTranslateById(_id: string, autoTranslate: boolean): Promise<UpdateResult>;
|
||||
updateAllAutoTranslateLanguagesByUserId(userId: IUser['_id'], language: string): Promise<UpdateResult | Document>;
|
||||
disableAutoTranslateByRoomId(roomId: IRoom['_id']): Promise<UpdateResult | Document>;
|
||||
findAlwaysNotifyDesktopUsersByRoomId(roomId: string): FindCursor<ISubscription>;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user