[CHORE] Subscribe settings

This commit is contained in:
kresnaputra 2021-03-18 16:20:55 +08:00
parent a56dade12b
commit 2f3b5666d6
3 changed files with 28 additions and 1 deletions

View File

@ -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);
}

View File

@ -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
}) {

View File

@ -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());