2019-07-29 22:17:38 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import LocalSettings from '/imports/api/local-settings';
|
|
|
|
import setChangedLocalSettings from '../modifiers/setChangedLocalSettings';
|
2020-02-07 04:47:28 +08:00
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
2021-05-05 20:27:56 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2023-02-23 21:27:16 +08:00
|
|
|
import { isEqual } from 'radash';
|
2019-07-29 22:17:38 +08:00
|
|
|
|
2023-03-16 22:02:33 +08:00
|
|
|
export default async function userChangedLocalSettings(settings) {
|
2021-05-05 20:27:56 +08:00
|
|
|
try {
|
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
2019-07-29 22:17:38 +08:00
|
|
|
|
2021-05-05 20:27:56 +08:00
|
|
|
if (!meetingId || !requesterUserId) return;
|
2019-07-29 22:17:38 +08:00
|
|
|
|
2021-05-05 20:27:56 +08:00
|
|
|
check(settings, Object);
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
2019-07-29 22:17:38 +08:00
|
|
|
|
2023-03-16 22:02:33 +08:00
|
|
|
const userLocalSettings = await LocalSettings
|
|
|
|
.findOneAsync({ meetingId, userId: requesterUserId },
|
2021-05-05 20:27:56 +08:00
|
|
|
{
|
|
|
|
fields: { settings: 1 },
|
|
|
|
});
|
2019-07-29 22:17:38 +08:00
|
|
|
|
2023-02-23 21:27:16 +08:00
|
|
|
if (!userLocalSettings || !isEqual(userLocalSettings.settings, settings)) {
|
2023-03-16 22:02:33 +08:00
|
|
|
await setChangedLocalSettings(meetingId, requesterUserId, settings);
|
2021-05-05 20:27:56 +08:00
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Exception while invoking method userChangedLocalSettings ${err.stack}`);
|
2019-07-29 22:17:38 +08:00
|
|
|
}
|
|
|
|
}
|