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',
|
habitrpg.controller('NotificationCtrl',
|
||||||
['$scope', '$rootScope', 'Shared', 'Content', 'User', 'Guide', 'Notification', 'Analytics', 'Achievement', 'Social', 'Tasks',
|
['$scope', '$rootScope', 'Shared', 'Content', 'User', 'Guide', 'Notification', 'Analytics', 'Achievement', 'Social', 'Tasks',
|
||||||
function ($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', function (after, before) {
|
||||||
$rootScope.$watch('user.yesterDailies', function (after, before) {
|
runYesterDailies();
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (dailyFound && dailyFound.group.approval && dailyFound.group.approval.requested) return;
|
$rootScope.$on('userUpdated', function (after, before) {
|
||||||
if (dailyFound) yesterDailies.push(dailyFound);
|
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;
|
if (yesterDailies.length === 0) return;
|
||||||
@@ -43,18 +51,11 @@ habitrpg.controller('NotificationCtrl',
|
|||||||
});
|
});
|
||||||
|
|
||||||
$scope.ageDailies = function () {
|
$scope.ageDailies = function () {
|
||||||
Tasks.ageDailies()
|
User.runCron();
|
||||||
.then(function () {
|
|
||||||
$scope.yesterDailiesModalOpen = false;
|
|
||||||
User.sync();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
}],
|
}],
|
||||||
})
|
|
||||||
.result.catch(function() {
|
|
||||||
$scope.yesterDailiesModalOpen = false;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$rootScope.$watch('user.stats.hp', function (after, before) {
|
$rootScope.$watch('user.stats.hp', function (after, before) {
|
||||||
if (after <= 0){
|
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) {
|
setCustomDayStart: function (dayStart) {
|
||||||
$http({
|
$http({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
@@ -12,9 +12,11 @@ let api = {};
|
|||||||
*/
|
*/
|
||||||
api.cron = {
|
api.cron = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/debug/cron',
|
url: '/cron',
|
||||||
middlewares: [authWithHeaders(), cron],
|
middlewares: [authWithHeaders(), cron],
|
||||||
async handler (req, res) {
|
async handler (req, res) {
|
||||||
res.respond(200, {});
|
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')
|
fieldset.option-group.advanced-option(ng-if='task.type === "daily" && task._edit._advanced')
|
||||||
.form-group
|
.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
|
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')
|
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