Skip to content

Commit

Permalink
Merging refactored code from p1
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiefeng18 committed Sep 23, 2024
1 parent 5ecb738 commit f740c7e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 49 deletions.
Binary file modified dump.rdb
Binary file not shown.
103 changes: 54 additions & 49 deletions src/upgrades/1.4.4/sound_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,69 @@

const async = require('async');
const db = require('../../database');
const meta = require('../../meta');
const batch = require('../../batch');

const map = {
'notification.mp3': 'Default | Deedle-dum',
'waterdrop-high.mp3': 'Default | Water drop (high)',
'waterdrop-low.mp3': 'Default | Water drop (low)',
};

module.exports = {
name: 'Update global and user sound settings',
timestamp: Date.UTC(2017, 1, 25),
method: function (callback) {
const meta = require('../../meta');
const batch = require('../../batch');
console.log('Sophie Feng');
function soundSettings(cb) {
const keys = ['chat-incoming', 'chat-outgoing', 'notification'];

const map = {
'notification.mp3': 'Default | Deedle-dum',
'waterdrop-high.mp3': 'Default | Water drop (high)',
'waterdrop-low.mp3': 'Default | Water drop (low)',
};
db.getObject('settings:sounds', (err, settings) => {
if (err || !settings) {
return cb(err);
}

async.parallel([
function (cb) {
const keys = ['chat-incoming', 'chat-outgoing', 'notification'];
keys.forEach((key) => {
if (settings[key] && !settings[key].includes(' | ')) {
settings[key] = map[settings[key]] || '';
}
});

db.getObject('settings:sounds', (err, settings) => {
if (err || !settings) {
return cb(err);
}
meta.configs.setMultiple(settings, cb);
});
}

keys.forEach((key) => {
if (settings[key] && !settings[key].includes(' | ')) {
settings[key] = map[settings[key]] || '';
}
});
function UserSoundSettings(cb) {
batch.processSortedSet('users:joindate', (ids, next) => {
async.each(ids, userSettings, next);
}, cb);
}

meta.configs.setMultiple(settings, cb);
});
},
function (cb) {
const keys = ['notificationSound', 'incomingChatSound', 'outgoingChatSound'];
function userSettings(uid, next) {
const keys = ['notificationSound', 'incomingChatSound', 'outgoingChatSound'];
db.getObject(`user:${uid}:settings`, (err, settings) => {
if (err || !settings) {
return next(err);
}

batch.processSortedSet('users:joindate', (ids, next) => {
async.each(ids, (uid, next) => {
db.getObject(`user:${uid}:settings`, (err, settings) => {
if (err || !settings) {
return next(err);
}
const newSettings = {};
keys.forEach((key) => {
if (settings[key] && !settings[key].includes(' | ')) {
newSettings[key] = map[settings[key]] || '';
}
});
const newSettings = {};
keys.forEach((key) => {
if (settings[key] && !settings[key].includes(' | ')) {
newSettings[key] = map[settings[key]] || '';
}
});

if (Object.keys(newSettings).length) {
db.setObject(`user:${uid}:settings`, newSettings, next);
} else {
setImmediate(next);
}
});
}, next);
}, cb);
},
if (Object.keys(newSettings).length) {
db.setObject(`user:${uid}:settings`, newSettings, next);
} else {
setImmediate(next);
}
});
}

module.exports = {
name: 'Update global and user sound settings',
timestamp: Date.UTC(2017, 1, 25),
method: function (callback) {
async.parallel([
soundSettings,
UserSoundSettings,
], callback);
},
};

0 comments on commit f740c7e

Please sign in to comment.