fix: Error when non-support setting change is received via stream (#5487)

This commit is contained in:
Gopal Verma 2024-01-23 04:10:03 +05:30 committed by GitHub
parent 0639d22e30
commit f7e443a670
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 17 deletions

View File

@ -138,25 +138,31 @@ function connect({ server, logoutOnError = false }: { server: string; logoutOnEr
const { _id, value } = ddpMessage.fields.args[1];
const db = database.active;
const settingsCollection = db.get('settings');
try {
const settingsRecord = await settingsCollection.find(_id);
// @ts-ignore
const { type } = defaultSettings[_id];
if (type) {
await db.write(async () => {
await settingsRecord.update(u => {
// @ts-ignore
u[type] = value;
});
});
}
store.dispatch(updateSettings(_id, value));
if (_id === 'Presence_broadcast_disabled') {
setPresenceCap(value);
// Check if the _id exists in defaultSettings
if (defaultSettings.hasOwnProperty(_id)) {
try {
const settingsRecord = await settingsCollection.find(_id);
// @ts-ignore
const { type } = defaultSettings[_id];
if (type) {
await db.write(async () => {
await settingsRecord.update(u => {
// @ts-ignore
u[type] = value;
});
});
}
store.dispatch(updateSettings(_id, value));
if (_id === 'Presence_broadcast_disabled') {
setPresenceCap(value);
}
} catch (e) {
log(e);
}
} catch (e) {
log(e);
} else {
console.warn(`Setting with _id '${_id}' is not present in defaultSettings.`);
}
}
})