2019-07-29 22:17:38 +08:00
|
|
|
import _ from 'lodash';
|
|
|
|
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';
|
2019-07-29 22:17:38 +08:00
|
|
|
|
2023-04-01 04:40:41 +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-04-01 04:40:41 +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
|
|
|
|
2021-05-05 20:27:56 +08:00
|
|
|
if (!userLocalSettings || !_.isEqual(userLocalSettings.settings, settings)) {
|
2023-04-01 04:40:41 +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
|
|
|
}
|
|
|
|
}
|