diff --git a/app/lib/methods/getSettings.js b/app/lib/methods/getSettings.js index 6935631ef..0d558e625 100644 --- a/app/lib/methods/getSettings.js +++ b/app/lib/methods/getSettings.js @@ -41,6 +41,11 @@ const loginSettings = [ 'Accounts_Iframe_api_method' ]; +export function subscribeSettings() { + this.sdk.subscribe('stream-notify-all', 'public-settings-changed'); + this.sdk.subscribe('stream-notify-logged', 'private-settings-changed'); +} + const serverInfoUpdate = async(serverInfo, iconSetting) => { const serversDB = database.servers; const serverId = reduxStore.getState().server.server; @@ -192,6 +197,7 @@ export default async function() { } return allRecords.length; }); + subscribeSettings(); } catch (e) { log(e); } diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 693c5eb78..c957fac39 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -29,7 +29,7 @@ import getUsersPresence, { getUserPresence, subscribeUsersPresence } from './met import protectedFunction from './methods/helpers/protectedFunction'; import readMessages from './methods/readMessages'; -import getSettings, { getLoginSettings, setSettings } from './methods/getSettings'; +import getSettings, { getLoginSettings, setSettings, subscribeSettings } from './methods/getSettings'; import getRooms from './methods/getRooms'; import { setPermissions, getPermissions } from './methods/getPermissions'; @@ -292,6 +292,21 @@ const RocketChat = { } catch { // We can't create a new record since we don't receive the user._id } + } else if (/private-settings-changed/.test(eventName)) { + const { _id, value } = ddpMessage.fields.args[1]; + const db = database.active; + const settingsCollection = db.get('settings'); + try { + const settingsRecord = await settingsCollection.find(_id); + await db.action(async() => { + await settingsRecord.update((u) => { + u._raw.value_as_boolean = value; + }); + }); + setSettings(); + } catch (err) { + console.log(err); + } } else if (/Users:NameChanged/.test(eventName)) { const userNameChanged = ddpMessage.fields.args[0]; const db = database.active; @@ -1420,6 +1435,7 @@ const RocketChat = { getUsersPresence, getUserPresence, subscribeUsersPresence, + subscribeSettings, getDirectory({ query, count, offset, sort }) { diff --git a/app/sagas/login.js b/app/sagas/login.js index b5c267263..b95a73c3f 100644 --- a/app/sagas/login.js +++ b/app/sagas/login.js @@ -111,6 +111,10 @@ const fetchUsersPresence = function* fetchUserPresence() { RocketChat.subscribeUsersPresence(); }; +const subscribeSettings = function* subscribeSetting() { + yield RocketChat.subscribeSettings(); +}; + const fetchEnterpriseModules = function* fetchEnterpriseModules({ user }) { yield RocketChat.getEnterpriseModules(); @@ -138,6 +142,7 @@ const handleLoginSuccess = function* handleLoginSuccess({ user }) { yield fork(fetchSlashCommands); yield fork(registerPushToken); yield fork(fetchUsersPresence); + yield fork(subscribeSettings); yield fork(fetchEnterpriseModules, { user }); yield put(encryptionInit());