diff --git a/dist/habitrpg-shared.js b/dist/habitrpg-shared.js index 5513c58db8..bdf0b56afd 100644 --- a/dist/habitrpg-shared.js +++ b/dist/habitrpg-shared.js @@ -13730,6 +13730,13 @@ api.dotGet = function(obj, path) { })(this)), obj); }; + +/* + Reflists are arrays, but stored as objects. Mongoose has a helluvatime working with arrays (the main problem for our + syncing issues) - so the goal is to move away from arrays to objects, since mongoose can reference elements by ID + no problem. To maintain sorting, we use these helper functions: + */ + api.refPush = function(reflist, item, prune) { if (prune == null) { prune = 0; @@ -14694,6 +14701,26 @@ api.wrap = function(user, main) { } return typeof cb === "function" ? cb(null, user.preferences.webhooks) : void 0; }, + deletePM: function(req, cb) { + delete user.inbox.messages[req.params.id]; + if (typeof user.markModified === "function") { + user.markModified('inbox.messages.' + req.params.id); + } + return typeof cb === "function" ? cb(null, user.inbox.messages) : void 0; + }, + blockUser: function(req, cb) { + var i; + i = user.inbox.blocks.indexOf(req.params.uuid); + if (~i) { + user.inbox.blocks.splice(i, 1); + } else { + user.inbox.blocks.push(req.params.uuid); + } + if (typeof user.markModified === "function") { + user.markModified('inbox.blocks'); + } + return typeof cb === "function" ? cb(null, user.inbox.blocks) : void 0; + }, feed: function(req, cb) { var egg, evolve, food, message, pet, potion, userPets, _ref, _ref1, _ref2; _ref = req.params, pet = _ref.pet, food = _ref.food; diff --git a/script/index.coffee b/script/index.coffee index 00f92dc7ab..63ebe06a24 100644 --- a/script/index.coffee +++ b/script/index.coffee @@ -19,6 +19,11 @@ api.dotSet = (obj,path,val)-> api.dotGet = (obj,path)-> _.reduce path.split('.'), ((curr, next) => curr?[next]), obj +### + Reflists are arrays, but stored as objects. Mongoose has a helluvatime working with arrays (the main problem for our + syncing issues) - so the goal is to move away from arrays to objects, since mongoose can reference elements by ID + no problem. To maintain sorting, we use these helper functions: +### 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] @@ -620,6 +625,19 @@ api.wrap = (user, main=true) -> user.markModified? 'preferences.webhooks' cb? null, user.preferences.webhooks + # ------ + # Inbox + # ------ + deletePM: (req, cb) -> + delete user.inbox.messages[req.params.id] + user.markModified? 'inbox.messages.'+req.params.id + cb? null, user.inbox.messages + blockUser: (req, cb) -> + i = user.inbox.blocks.indexOf(req.params.uuid) + if ~i then user.inbox.blocks.splice(i,1) else user.inbox.blocks.push(req.params.uuid) + user.markModified? 'inbox.blocks' + cb? null, user.inbox.blocks + # ------ # Inventory # ------