refactor(reflist): helper fn for reflist.push (not used now, but might

need soon)
This commit is contained in:
Tyler Renelle
2014-11-20 16:22:42 -07:00
parent b88a48ebd3
commit f68f884525
2 changed files with 22 additions and 10 deletions
+16 -5
View File
@@ -13730,6 +13730,17 @@ api.dotGet = function(obj, path) {
})(this)), obj);
};
api.refPush = function(reflist, item, prune) {
if (prune == null) {
prune = 0;
}
item.sort = _.isEmpty(reflist) ? 0 : _.max(reflist, 'sort').sort + 1;
if (!(item.id && !reflist[item.id])) {
item.id = api.uuid();
}
return reflist[item.id] = item;
};
api.planGemLimits = {
convRate: 20,
convCap: 25
@@ -14659,11 +14670,11 @@ api.wrap = function(user, main) {
addWebhook: function(req, cb) {
var wh;
wh = user.preferences.webhooks;
wh[req.body.id || api.uuid()] = {
api.refPush(wh, {
url: req.body.url,
enabled: req.body.enabled || true,
sort: _.isEmpty(wh) ? 0 : _.max(wh, 'sort').sort + 1
};
id: req.body.id
});
if (typeof user.markModified === "function") {
user.markModified('preferences.webhooks');
}
@@ -15914,5 +15925,5 @@ api.wrap = function(user, main) {
};
}).call(this,require("/Users/lefnire/Dropbox/Sites/habitrpg/modules/habitrpg-shared/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
},{"./content.coffee":5,"./i18n.coffee":6,"/Users/lefnire/Dropbox/Sites/habitrpg/modules/habitrpg-shared/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":2,"lodash":3,"moment":4}]},{},[1])
}).call(this,require("/Users/lefnire/Google Drive/Sync/Sites/habitrpg/modules/habitrpg-shared/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
},{"./content.coffee":5,"./i18n.coffee":6,"/Users/lefnire/Google Drive/Sync/Sites/habitrpg/modules/habitrpg-shared/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":2,"lodash":3,"moment":4}]},{},[1])
+6 -5
View File
@@ -19,6 +19,11 @@ api.dotSet = (obj,path,val)->
api.dotGet = (obj,path)->
_.reduce path.split('.'), ((curr, next) => curr?[next]), obj
api.refPush = (reflist, item, prune=0) ->
item.sort = if _.isEmpty(reflist) then 0 else _.max(reflist,'sort').sort+1
item.id = api.uuid() unless item.id and !reflist[item.id]
reflist[item.id] = item
api.planGemLimits =
convRate: 20 #how much does a gem cost?
convCap: 25 #how many gems can be converted / month?
@@ -72,7 +77,6 @@ api.shouldDo = (day, repeat, options={}) ->
yesterday = moment(o.now).subtract({days:1}).day() # have to wrap o.now so as not to modify original
return repeat[api.dayMapping[yesterday]] # FIXME is this correct?? Do I need to do any timezone calcaulation here?
###
------------------------------------------------------
Scoring
@@ -604,10 +608,7 @@ api.wrap = (user, main=true) ->
# ------
addWebhook: (req, cb) ->
wh = user.preferences.webhooks
wh[req.body.id or api.uuid()] =
url: req.body.url
enabled: req.body.enabled or true
sort: if _.isEmpty(wh) then 0 else _.max(wh,'sort').sort+1
api.refPush(wh, {url:req.body.url, enabled: req.body.enabled or true, id:req.body.id})
user.markModified? 'preferences.webhooks'
cb? null, user.preferences.webhooks
updateWebhook: (req, cb) ->