mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Added cron check
This commit is contained in:
@@ -3,18 +3,26 @@
|
||||
habitrpg.controller('NotificationCtrl',
|
||||
['$scope', '$rootScope', 'Shared', 'Content', 'User', 'Guide', 'Notification', 'Analytics', 'Achievement', 'Social', 'Tasks',
|
||||
function ($scope, $rootScope, Shared, Content, User, Guide, Notification, Analytics, Achievement, Social, Tasks) {
|
||||
$scope.yesterDailiesModalOpen = false;
|
||||
$rootScope.$watch('user.yesterDailies', function (after, before) {
|
||||
if (!after || after.length === 0 || $scope.yesterDailiesModalOpen) return;
|
||||
|
||||
var yesterDailies = [];
|
||||
after.forEach(function (taskId) {
|
||||
var dailyFound = _.find(User.user.dailys, function (task) {
|
||||
return taskId === task._id;
|
||||
$rootScope.$watch('user', function (after, before) {
|
||||
runYesterDailies();
|
||||
});
|
||||
|
||||
if (dailyFound && dailyFound.group.approval && dailyFound.group.approval.requested) return;
|
||||
if (dailyFound) yesterDailies.push(dailyFound);
|
||||
$rootScope.$on('userUpdated', function (after, before) {
|
||||
runYesterDailies();
|
||||
});
|
||||
|
||||
function runYesterDailies() {
|
||||
let userLastCron = moment(User.user.lastCron).local();
|
||||
let userDayStart = moment().startOf('day').add({ hours: User.user.preferences.dayStart });
|
||||
if (!userLastCron.isBefore(userDayStart)) return;
|
||||
let dailys = User.user.dailys;
|
||||
|
||||
if (!Boolean(dailys) || dailys.length === 0) return;
|
||||
|
||||
var yesterDailies = [];
|
||||
dailys.forEach(function (task) {
|
||||
if (task && task.group.approval && task.group.approval.requested) return;
|
||||
if (task) yesterDailies.push(task);
|
||||
});
|
||||
|
||||
if (yesterDailies.length === 0) return;
|
||||
@@ -43,18 +51,11 @@ habitrpg.controller('NotificationCtrl',
|
||||
});
|
||||
|
||||
$scope.ageDailies = function () {
|
||||
Tasks.ageDailies()
|
||||
.then(function () {
|
||||
$scope.yesterDailiesModalOpen = false;
|
||||
User.sync();
|
||||
});
|
||||
User.runCron();
|
||||
};
|
||||
}],
|
||||
})
|
||||
.result.catch(function() {
|
||||
$scope.yesterDailiesModalOpen = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$rootScope.$watch('user.stats.hp', function (after, before) {
|
||||
if (after <= 0){
|
||||
|
||||
@@ -416,6 +416,16 @@ angular.module('habitrpg')
|
||||
});
|
||||
},
|
||||
|
||||
runCron: function () {
|
||||
$http({
|
||||
method: "POST",
|
||||
url: 'api/v3/cron',
|
||||
})
|
||||
.then(function (response) {
|
||||
sync();
|
||||
})
|
||||
},
|
||||
|
||||
setCustomDayStart: function (dayStart) {
|
||||
$http({
|
||||
method: "POST",
|
||||
|
||||
@@ -12,9 +12,11 @@ let api = {};
|
||||
*/
|
||||
api.cron = {
|
||||
method: 'POST',
|
||||
url: '/debug/cron',
|
||||
url: '/cron',
|
||||
middlewares: [authWithHeaders(), cron],
|
||||
async handler (req, res) {
|
||||
res.respond(200, {});
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = api;
|
||||
|
||||
@@ -13,7 +13,7 @@ div(ng-if='(task.type !== "reward") || task.userId || (!obj.auth && obj.purchase
|
||||
|
||||
fieldset.option-group.advanced-option(ng-if='task.type === "daily" && task._edit._advanced')
|
||||
.form-group
|
||||
input(type='checkbox', ng-model='task._edit.yesterDaily')
|
||||
input(type='checkbox', ng-model='task._edit.yesterDaily', ng-disabled='$state.includes("options.social.challenges") || $state.includes("options.social.groups")')
|
||||
legend.option-title
|
||||
a.hint(href='http://habitica.wikia.com/wiki/Task_Alias', target='_blank', popover-trigger='mouseenter', popover="{{::env.t('yesterDailiesDescription')}}")=env.t('yesterDailiesOptionTitle')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user